Skip to content

Commit

Permalink
call get_results just once at end of sim instead of twice (#454)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevebachmeier committed Aug 13, 2024
1 parent 2dc4870 commit 5e2531d
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/vivarium/framework/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,8 @@ def finalize(self) -> None:
def report(self, print_results: bool = True) -> None:
self._lifecycle.set_state("report")
self.report_emitter(self.get_population().index)

results = self.get_results()
if print_results:
results = self.get_results()
for measure, df in results.items():
self._logger.info(f"\n{measure}:\n{pformat(df)}")
performance_metrics = self.get_performance_metrics()
Expand All @@ -285,15 +284,15 @@ def report(self, print_results: bool = True) -> None:
float_format=lambda x: f"{x:.2f}",
)
self._logger.info("\n" + performance_metrics)
self._write_results()
self._write_results(results)

def _write_results(self) -> None:
def _write_results(self, results: dict[str, pd.DataFrame]) -> None:
"""Iterate through the measures and write out the formatted results"""
try:
results_dir = self.configuration.output_data.results_directory
for measure, results in self.get_results().items():
for measure, df in results.items():
output_file = Path(results_dir) / f"{measure}.parquet"
results.to_parquet(output_file, index=False)
df.to_parquet(output_file, index=False)
except ConfigurationKeyError:
self._logger.info("No results directory set; results are not written to disk.")

Expand Down

0 comments on commit 5e2531d

Please # to comment.