Skip to content

Commit

Permalink
refactor: batch_data -> sim_controls
Browse files Browse the repository at this point in the history
  • Loading branch information
yngve-sk committed Feb 7, 2025
1 parent 6bf7de4 commit ddb8c70
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/ert/run_models/everest_run_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,15 +419,17 @@ def _run_forward_model(
]

# Create the batch to run:
batch_data = self._init_batch_data(control_values, evaluated_control_indices)
sim_controls = self._create_simulation_controls(
control_values, evaluated_control_indices
)

# Initialize a new ensemble in storage:
assert self._experiment is not None
ensemble = self._experiment.create_ensemble(
name=f"batch_{self._batch_id}",
ensemble_size=len(evaluated_control_indices),
)
for sim_id, controls in enumerate(batch_data.values()):
for sim_id, controls in enumerate(sim_controls.values()):
self._setup_sim(sim_id, controls, ensemble)

# Evaluate the batch:
Expand Down Expand Up @@ -521,18 +523,18 @@ def _get_cached_results(
cached_results[sim_id] = cached_data
return cached_results

def _init_batch_data(
def _create_simulation_controls(
self,
control_values: NDArray[np.float64],
controls_to_evaluate: list[int],
) -> dict[int, dict[str, Any]]:
def _add_controls(
def _create_control_dict(
controls_config: list[ControlConfig], values: NDArray[np.float64]
) -> dict[str, Any]:
batch_data_item: dict[str, Any] = {}
control_dicts: dict[str, Any] = {}
value_list = values.tolist()
for control in controls_config:
control_dict: dict[str, Any] = batch_data_item.get(control.name, {})
control_dict: dict[str, Any] = control_dicts.get(control.name, {})
for variable in control.variables:
variable_value = control_dict.get(variable.name, {})
if isinstance(variable, ControlVariableGuessListConfig):
Expand All @@ -543,11 +545,13 @@ def _add_controls(
else:
variable_value = value_list.pop(0)
control_dict[variable.name] = variable_value
batch_data_item[control.name] = control_dict
return batch_data_item
control_dicts[control.name] = control_dict
return control_dicts

return {
idx: _add_controls(self._everest_config.controls, control_values[idx, :])
idx: _create_control_dict(
self._everest_config.controls, control_values[idx, :]
)
for idx in controls_to_evaluate
}

Expand Down

0 comments on commit ddb8c70

Please sign in to comment.