Skip to content

Commit

Permalink
review: Hardcode merit file property
Browse files Browse the repository at this point in the history
  • Loading branch information
yngve-sk committed Jan 21, 2025
1 parent ab585e9 commit cb34d6f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
7 changes: 1 addition & 6 deletions src/ert/run_models/everest_run_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,7 @@ def run_experiment(
self.ever_storage = EverestStorage(
output_dir=Path(self._everest_config.optimization_output_dir),
)
self.ever_storage.observe_optimizer(
optimizer,
Path(self._everest_config.optimization_output_dir)
/ "dakota"
/ "OPT_DEFAULT.out",
)
self.ever_storage.observe_optimizer(optimizer)

# Run the optimization:
optimizer_exit_code = optimizer.run().exit_code
Expand Down
13 changes: 4 additions & 9 deletions src/everest/everest_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ def __init__(
self._gradient_ensemble_id = 0

self._output_dir = output_dir
self._merit_file: Path | None = None
self.data = OptimizationStorageData()

@staticmethod
Expand Down Expand Up @@ -338,12 +337,7 @@ def read_from_output_dir(self) -> None:
def observe_optimizer(
self,
optimizer: BasicOptimizer,
merit_file: Path,
) -> None:
# We only need this file if we are observing a running ROPT instance
# (using dakota backend)
self._merit_file = merit_file

optimizer.add_observer(
EventType.START_OPTIMIZER_STEP, self._on_start_optimization
)
Expand Down Expand Up @@ -860,7 +854,7 @@ def _get_merit_values(self) -> list[_MeritValue]:
# Iter F(x) mu alpha Merit feval btracks Penalty
# :return: merit values indexed by the function evaluation number

def _get_merit_fn_lines(merit_path: str) -> list[str]:
def _get_merit_fn_lines(merit_path: Path) -> list[str]:
if os.path.isfile(merit_path):
with open(merit_path, errors="replace", encoding="utf-8") as reader:
lines = reader.readlines()
Expand All @@ -887,9 +881,10 @@ def _parse_merit_line(merit_values_string: str) -> tuple[int, float] | None:
return int(values[5]) - 1, values[4]
return None

merit_file = Path(self._output_dir) / "dakota" / "OPT_DEFAULT.out"
merit_values = []
if self._merit_file.exists():
for line in _get_merit_fn_lines(self._merit_file):
if merit_file.exists():
for line in _get_merit_fn_lines(merit_file):
value = _parse_merit_line(line)
if value is not None:
merit_values.append(_MeritValue(iter=value[0], value=value[1]))
Expand Down

0 comments on commit cb34d6f

Please sign in to comment.