Skip to content

Commit

Permalink
EverestRunModel: sanitize realization var names
Browse files Browse the repository at this point in the history
  • Loading branch information
verveerpj committed Dec 19, 2024
1 parent ce39215 commit 8e48f08
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/ert/run_models/everest_run_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,9 +522,9 @@ def _get_run_args(
self.active_realizations = [True] * len(batch_data)
assert evaluator_context.config.realizations.names is not None
for sim_id, control_idx in enumerate(batch_data.keys()):
realization = evaluator_context.realizations[control_idx]
realization_idx = evaluator_context.realizations[control_idx]
substitutions[f"<GEO_ID_{sim_id}_0>"] = str(
evaluator_context.config.realizations.names[realization]
evaluator_context.config.realizations.names[realization_idx]
)
run_paths = Runpaths(
jobname_format=self.ert_config.model_config.jobname_format_string,
Expand Down Expand Up @@ -654,9 +654,9 @@ def _add_results_to_cache(
if self._simulator_cache is not None:
assert evaluator_context.config.realizations.names is not None
for control_idx in batch_data:
realization = evaluator_context.realizations[control_idx]
realization_idx = evaluator_context.realizations[control_idx]
self._simulator_cache.add(
evaluator_context.config.realizations.names[realization],
evaluator_context.config.realizations.names[realization_idx],
control_values[control_idx, ...],
objectives[control_idx, ...],
None if constraints is None else constraints[control_idx, ...],
Expand Down Expand Up @@ -748,7 +748,7 @@ class SimulatorCache:

def __init__(self) -> None:
self._data: defaultdict[
int,
str,
list[
tuple[
NDArray[np.float64], NDArray[np.float64], NDArray[np.float64] | None
Expand All @@ -758,12 +758,12 @@ def __init__(self) -> None:

def add(
self,
realization_id: int,
realization: str,
control_values: NDArray[np.float64],
objectives: NDArray[np.float64],
constraints: NDArray[np.float64] | None,
) -> None:
self._data[realization_id].append(
self._data[realization].append(
(
control_values.copy(),
objectives.copy(),
Expand All @@ -772,11 +772,9 @@ def add(
)

def get(
self, realization_id: int, controls: NDArray[np.float64]
self, realization: str, controls: NDArray[np.float64]
) -> tuple[NDArray[np.float64], NDArray[np.float64] | None] | None:
for control_values, objectives, constraints in self._data.get(
realization_id, []
):
for control_values, objectives, constraints in self._data.get(realization, []):
if np.allclose(controls, control_values, rtol=0.0, atol=self.EPS):
return objectives, constraints
return None

0 comments on commit 8e48f08

Please sign in to comment.