Skip to content

Commit

Permalink
Move .add_observer logic to _create_optimizer
Browse files Browse the repository at this point in the history
  • Loading branch information
yngve-sk committed Nov 6, 2024
1 parent 322ff05 commit 613735e
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/ert/run_models/everest_run_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,14 +401,6 @@ def run_experiment(
# Initialize the ropt optimizer:
optimizer = self._create_optimizer(simulator)

# Before each batch evaluation we check if we should abort:
optimizer.add_observer(
EventType.START_EVALUATION,
functools.partial(
self._ropt_callback, optimizer=optimizer, simulator=simulator
),
)

# The SqliteStorage object is used to store optimization results from
# Seba in an sqlite database. It reacts directly to events emitted by
# Seba and is not called by Everest directly. The stored results are
Expand Down Expand Up @@ -515,7 +507,7 @@ def _create_optimizer(self, simulator: Simulator) -> BasicOptimizer:
# simplifying code that reads them as fixed width tables. `maximize` is
# set because ropt reports minimization results, while everest wants
# maximization results, necessitating a conversion step.
return (
optimizer = (
BasicOptimizer(enopt_config=self.ropt_config, evaluator=simulator)
.add_table(
columns=RESULT_COLUMNS,
Expand Down Expand Up @@ -545,6 +537,16 @@ def _create_optimizer(self, simulator: Simulator) -> BasicOptimizer:
)
)

# Before each batch evaluation we check if we should abort:
optimizer.add_observer(
EventType.START_EVALUATION,
functools.partial(
self._ropt_callback, optimizer=optimizer, simulator=simulator
),
)

return optimizer

@classmethod
def name(cls) -> str:
return "Batch simulator"
Expand Down

0 comments on commit 613735e

Please sign in to comment.