Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 🐛 fix how file stats are updated #265

Merged
merged 3 commits into from
Jul 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading