From fb1ba4a5c65ab4e0cb400f0e311366e68bb87f44 Mon Sep 17 00:00:00 2001 From: "Yngve S. Kristiansen" Date: Mon, 18 Nov 2024 09:28:22 +0100 Subject: [PATCH] Split out optimizer observer logic --- src/ert/run_models/everest_run_model.py | 3 +-- src/everest/everest_storage.py | 14 ++++---------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/ert/run_models/everest_run_model.py b/src/ert/run_models/everest_run_model.py index f3882fc9d55..5ea2dec98f4 100644 --- a/src/ert/run_models/everest_run_model.py +++ b/src/ert/run_models/everest_run_model.py @@ -402,13 +402,12 @@ def run_experiment( optimizer = self._create_optimizer(simulator) self.ever_storage = EverestStorage( - simulator, - optimizer, Path(self.everest_config.optimization_output_dir) / "dakota" / "OPT_DEFAULT.out", output_dir=Path(self.everest_config.optimization_output_dir), ) + self.ever_storage.observe_optimizer(optimizer) # The SqliteStorage object is used to store optimization results from # Seba in an sqlite database. It reacts directly to events emitted by diff --git a/src/everest/everest_storage.py b/src/everest/everest_storage.py index 04d94c1a28e..32f1ec61c8a 100644 --- a/src/everest/everest_storage.py +++ b/src/everest/everest_storage.py @@ -23,8 +23,6 @@ from ropt.results import FunctionResults, GradientResults, convert_to_maximize from seba_sqlite import sqlite_storage -from everest.simulator import Simulator - logger = logging.getLogger(__name__) if TYPE_CHECKING: @@ -243,20 +241,19 @@ def get_ensemble_by_name(self, name: str) -> _OptimizerOnlyEnsemble: class EverestStorage: def __init__( self, - simulator: Simulator, - optimizer: BasicOptimizer, merit_file: Path, output_dir: Path, ) -> None: - self._simulator = simulator - self._optimizer = optimizer self._initialized = False self._control_ensemble_id = 0 self._gradient_ensemble_id = 0 - self._simulator_results = None self._merit_file = merit_file + self._dataframes = EverestStorageDataFrames() + self._experiment = _OptimizerOnlyExperiment(output_dir) + + def observe_optimizer(self, optimizer: BasicOptimizer) -> None: optimizer.add_observer(EventType.START_OPTIMIZER_STEP, self._initialize) optimizer.add_observer( EventType.FINISHED_EVALUATION, self._handle_finished_batch_event @@ -266,9 +263,6 @@ def __init__( self._handle_finished_event, ) - self._dataframes = EverestStorageDataFrames() - self._experiment = _OptimizerOnlyExperiment(output_dir) - @property def experiment(self) -> _OptimizerOnlyExperiment: # Should be replaced with ERT experiment