Skip to content

Commit

Permalink
fix: 🐛 fix how file stats are updated (#265)
Browse files Browse the repository at this point in the history
Prepend existing stats for file stats store to prevent overwriting.
  • Loading branch information
mzouink committed Jul 22, 2024
2 parents e806bf4 + b649843 commit fb1bd5d
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions dacapo/store/file_stats_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,15 @@ def store_training_stats(self, run_name, stats):
)
else:
# current stats are behind DB--drop DB
existing_stats = None
logger.warning(
f"Overwriting previous training stats for run {run_name}"
)
self.__delete_training_stats(run_name)

# store all new stats
self.__store_training_stats(
stats, store_from_iteration, stats.trained_until(), run_name
existing_stats, stats, store_from_iteration, stats.trained_until(), run_name
)

def retrieve_training_stats(self, run_name):
Expand Down Expand Up @@ -174,11 +175,12 @@ def delete_training_stats(self, run_name: str) -> None:
"""
self.__delete_training_stats(run_name)

def __store_training_stats(self, stats, begin, end, run_name):
def __store_training_stats(self, existing_stats, stats, begin, end, run_name):
"""
Store the training statistics for a specific run.
Args:
existing_stats (Stats): The statistics object containing the training stats that are already stored.
stats (Stats): The statistics object containing the training stats.
begin (int): The starting index of the iteration stats to store.
end (int): The ending index of the iteration stats to store.
Expand All @@ -190,10 +192,15 @@ def __store_training_stats(self, stats, begin, end, run_name):
"""
docs = converter.unstructure(stats.iteration_stats[begin:end])
for doc in docs:
doc.update({"run_name": run_name})

if docs:
if existing_stats:
# prepend existing stats to new stats
docs = converter.unstructure(existing_stats.iteration_stats) + docs

for doc in docs:
doc.update({"run_name": run_name})

file_store = self.training_stats / run_name
with file_store.open("wb") as fd:
pickle.dump(docs, fd)
Expand Down

0 comments on commit fb1bd5d

Please sign in to comment.