Skip to content

Commit

Permalink
Initialize experiment along with simulator
Browse files Browse the repository at this point in the history
  • Loading branch information
yngve-sk committed Oct 10, 2024
1 parent b9cfd46 commit 628b96b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
8 changes: 8 additions & 0 deletions src/ert/storage/local_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ def refresh(self) -> None:
self._ensembles = self._load_ensembles()
self._experiments = self._load_experiments()

def load_experiment(self, uuid: UUID) -> LocalExperiment:
if uuid not in self._experiments:
self._experiments[uuid] = LocalExperiment(
self, self._experiment_path(uuid), self.mode
)

return self._experiments[uuid]

def get_experiment(self, uuid: UUID) -> LocalExperiment:
"""
Retrieves an experiment by UUID.
Expand Down
20 changes: 10 additions & 10 deletions src/everest/simulator/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ def __init__(self, ever_config: EverestConfig, callback=None) -> None:
if ever_config.simulator is not None and ever_config.simulator.enable_cache:
self._cache = _SimulatorCache()

with open_storage(ert_config.ens_path, "w") as storage:
experiment = storage.create_experiment(
name=f"EnOpt@{datetime.now().strftime('%Y-%m-%d@%H:%M:%S')}",
parameters=ert_config.ensemble_config.parameter_configuration,
responses=ert_config.ensemble_config.response_configuration,
)

self._experiment_id = experiment.id

def _get_controls(self, ever_config: EverestConfig) -> List[str]:
controls = ever_config.controls or []
return [control.name for control in controls]
Expand Down Expand Up @@ -119,16 +128,7 @@ def __call__(
case_data.append((real_id, controls))

with open_storage(self.ert_config.ens_path, "w") as storage:
if self._experiment_id is None:
experiment = storage.create_experiment(
name=f"EnOpt@{datetime.now().strftime('%Y-%m-%d@%H:%M:%S')}",
parameters=self.ert_config.ensemble_config.parameter_configuration,
responses=self.ert_config.ensemble_config.response_configuration,
)

self._experiment_id = experiment.id
else:
experiment = storage.get_experiment(self._experiment_id)
experiment = storage.load_experiment(self._experiment_id)

sim_context = self.start(f"batch_{self._batch}", case_data, experiment)

Expand Down

0 comments on commit 628b96b

Please sign in to comment.