Skip to content

Commit

Permalink
fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
yngve-sk committed Oct 24, 2024
1 parent 69de78c commit a877bc4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
35 changes: 17 additions & 18 deletions src/ert/run_models/everest_run_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import copy
import datetime
import functools
import json
import logging
import os
import queue
Expand Down Expand Up @@ -300,7 +301,7 @@ def __init__(
optimization_callback: OptimizerCallback,
display_all_jobs: bool = True,
):
self._add_defaults(everest_config)
everest_config = self._add_defaults(everest_config)

Path(everest_config.log_dir).mkdir(parents=True)
Path(everest_config.optimization_output_dir).mkdir(parents=True)
Expand Down Expand Up @@ -341,7 +342,7 @@ def __init__(
self.num_retries_per_iter = 0 # OK?

@staticmethod
def _add_defaults(config: EverestConfig):
def _add_defaults(config: EverestConfig) -> EverestConfig:
"""This function exists as a temporary mechanism to default configurations that
needs to be global in the sense that they should carry over both to ropt and ERT.
When the proper mechanism for this is implemented this code
Expand Down Expand Up @@ -372,24 +373,23 @@ def create(
simulation_callback: Optional[SimulationCallback] = None,
optimization_callback: Optional[OptimizerCallback] = None,
random_seed: Optional[int] = None,
):
if simulation_callback is None:

def simulation_callback():
return None
) -> EverestRunModel:
def default_simulation_callback(
simulation_status: SimulationStatus | None, event: str
) -> str | None:
return None

if optimization_callback is None:

def optimization_callback():
return None
def default_optimization_callback() -> str | None:
return None

ert_config = everest_to_ert_config(ever_config)
return cls(
random_seed=random_seed,
config=ert_config,
everest_config=ever_config,
simulation_callback=simulation_callback,
optimization_callback=optimization_callback,
simulation_callback=simulation_callback or default_simulation_callback,
optimization_callback=optimization_callback
or default_optimization_callback,
)

def run_experiment(
Expand Down Expand Up @@ -561,10 +561,9 @@ def description(cls) -> str:
return "Run batches "

@property
def result(self):
def result(self) -> Optional[seba_sqlite.sqlite_storage.OptimalResult]:
return self._result

def __repr__(self):
return "EverestRunModel(config={})" % json.dumps(
self.everest_config, sort_keys=True, indent=2
)
def __repr__(self) -> str:
config_json = json.dumps(self.everest_config, sort_keys=True, indent=2)
return f"EverestRunModel(config={config_json})"
2 changes: 1 addition & 1 deletion tests/everest/test_objective_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ def test_mathfunc_stddev(
assert x1 == pytest.approx(0.5, abs=0.025)
assert x2 == pytest.approx(0.5, abs=0.025)

assert workflow.result.total_objective < 0.0
assert run_model.result.total_objective < 0.0

0 comments on commit a877bc4

Please sign in to comment.