From 5e2531d65c708e2e5dc32e42de5a897d8dc76e58 Mon Sep 17 00:00:00 2001 From: Steve Bachmeier <23350991+stevebachmeier@users.noreply.github.com> Date: Fri, 26 Jul 2024 14:21:15 -0600 Subject: [PATCH] call get_results just once at end of sim instead of twice (#454) --- src/vivarium/framework/engine.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/vivarium/framework/engine.py b/src/vivarium/framework/engine.py index 433c1c1c7..96934835b 100644 --- a/src/vivarium/framework/engine.py +++ b/src/vivarium/framework/engine.py @@ -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() @@ -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.")