From e18edbf97b0c7eadea2bb1aa6b822bf9c0475abd Mon Sep 17 00:00:00 2001 From: Peter Verveer Date: Wed, 18 Dec 2024 15:02:12 +0000 Subject: [PATCH] EverestRunModel: allow callbacks to be None --- src/ert/run_models/everest_run_model.py | 23 +++++++---------------- tests/everest/test_everest_output.py | 8 +------- 2 files changed, 8 insertions(+), 23 deletions(-) diff --git a/src/ert/run_models/everest_run_model.py b/src/ert/run_models/everest_run_model.py index 5f4299a7831..84aa13a1f38 100644 --- a/src/ert/run_models/everest_run_model.py +++ b/src/ert/run_models/everest_run_model.py @@ -152,8 +152,8 @@ def __init__( self, config: ErtConfig, everest_config: EverestConfig, - simulation_callback: SimulationCallback, - optimization_callback: OptimizerCallback, + simulation_callback: SimulationCallback | None, + optimization_callback: OptimizerCallback | None, ): everest_config = self._add_defaults(everest_config) @@ -227,21 +227,11 @@ def create( simulation_callback: SimulationCallback | None = None, optimization_callback: OptimizerCallback | None = None, ) -> EverestRunModel: - def default_simulation_callback( - simulation_status: SimulationStatus | None, - ) -> str | None: - return None - - def default_optimization_callback() -> str | None: - return None - - ert_config = everest_to_ert_config(cls._add_defaults(ever_config)) return cls( - config=ert_config, + config=everest_to_ert_config(cls._add_defaults(ever_config)), everest_config=ever_config, - simulation_callback=simulation_callback or default_simulation_callback, - optimization_callback=optimization_callback - or default_optimization_callback, + simulation_callback=simulation_callback, + optimization_callback=optimization_callback, ) def run_experiment( @@ -698,7 +688,8 @@ def send_snapshot_event(self, event: Event, iteration: int) -> None: if type(event) in (EESnapshot, EESnapshotUpdate): newstatus = self._simulation_status(self.get_current_snapshot()) if self._status != newstatus: # No change in status - self._sim_callback(newstatus) + if self._sim_callback is not None: + self._sim_callback(newstatus) self._status = newstatus def _simulation_status(self, snapshot: EnsembleSnapshot) -> SimulationStatus: diff --git a/tests/everest/test_everest_output.py b/tests/everest/test_everest_output.py index 5287251aca4..78ee7e439b8 100644 --- a/tests/everest/test_everest_output.py +++ b/tests/everest/test_everest_output.py @@ -52,13 +52,7 @@ async def test_everest_output(copy_mocked_test_data_to_tmp): initial_folders = set(folders) initial_files = set(files) - # Tests in this class used to fail when a callback was passed in - # Use a callback just to see that everything works fine, even though - # the callback does nothing - def useless_cb(*args, **kwargs): - pass - - EverestRunModel.create(config, optimization_callback=useless_cb) + EverestRunModel.create(config) # Check the output folder is created when stating the optimization # in everest workflow