Skip to content

Commit

Permalink
EverestRunModel: allow callbacks to be None
Browse files Browse the repository at this point in the history
  • Loading branch information
verveerpj committed Dec 18, 2024
1 parent 2f00579 commit e18edbf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 23 deletions.
23 changes: 7 additions & 16 deletions src/ert/run_models/everest_run_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 1 addition & 7 deletions tests/everest/test_everest_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e18edbf

Please sign in to comment.