Skip to content

Commit

Permalink
Inline addNode function
Browse files Browse the repository at this point in the history
  • Loading branch information
oyvindeide committed Nov 13, 2024
1 parent c1e1c80 commit 9eb5ce4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 28 deletions.
15 changes: 0 additions & 15 deletions src/ert/config/ensemble_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,21 +152,6 @@ def hasNodeGenData(self, key: str) -> bool:
config = self.response_configs["gen_data"]
return key in config.keys

def addNode(self, config_node: Union[ParameterConfig, ResponseConfig]) -> None:
assert config_node is not None
if config_node.name in self:
raise ConfigValidationError(
f"Config node with key {config_node.name!r} already present in ensemble config"
)

if isinstance(config_node, ParameterConfig):
logger.info(
f"Adding {type(config_node).__name__} config (of size {len(config_node)}) to parameter_configs"
)
self.parameter_configs[config_node.name] = config_node
else:
self.response_configs[config_node.name] = config_node

def get_keylist_gen_kw(self) -> List[str]:
return [
val.name
Expand Down
2 changes: 1 addition & 1 deletion src/everest/simulator/everest_to_ert.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ def _get_variables(
# configuration key. When initializing an ERT config object, it is ignored.
# It is used by the Simulator object to inject ExtParamConfig nodes.
for control in ever_config.controls or []:
ens_config.addNode(
ens_config.parameter_configs[control.name] = (
ExtParamConfig(
name=control.name,
input_keys=_get_variables(control.variables),
Expand Down
20 changes: 8 additions & 12 deletions tests/ert/unit_tests/simulator/test_batch_sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,17 @@ def __init__(self, ert_config, storage, controls, results, callback=None):
try:
ens_config = ert_config.ensemble_config
for control_name, variables in controls.items():
ens_config.addNode(
ExtParamConfig(
name=control_name,
input_keys=variables,
output_file=control_name + ".json",
)
ens_config.parameter_configs[control_name] = ExtParamConfig(
name=control_name,
input_keys=variables,
output_file=control_name + ".json",
)

if "gen_data" not in ens_config:
ens_config.addNode(
GenDataConfig(
keys=results,
input_files=[f"{k}" for k in results],
report_steps_list=[None for _ in results],
)
ens_config.response_configs["gen_data"] = GenDataConfig(
keys=results,
input_files=[f"{k}" for k in results],
report_steps_list=[None for _ in results],
)
else:
existing_gendata = ens_config.response_configs["gen_data"]
Expand Down

0 comments on commit 9eb5ce4

Please sign in to comment.