Skip to content

Commit

Permalink
Split out optimizer observer logic
Browse files Browse the repository at this point in the history
  • Loading branch information
yngve-sk committed Nov 18, 2024
1 parent 613fc4d commit fb1ba4a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
3 changes: 1 addition & 2 deletions src/ert/run_models/everest_run_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 4 additions & 10 deletions src/everest/everest_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit fb1ba4a

Please sign in to comment.