Skip to content

Commit

Permalink
Raise if params not registered are saved
Browse files Browse the repository at this point in the history
  • Loading branch information
dafeda committed Dec 13, 2023
1 parent 374c4b7 commit 78c9649
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/ert/storage/local_ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,9 @@ def save_parameters(
f"must contain a 'values' variable"
)

if group not in self.experiment.parameter_configuration:
raise ValueError(f"{group} is not registered to the experiment.")

path = self.mount_point / f"realization-{realization}" / f"{group}.nc"
path.parent.mkdir(exist_ok=True)

Expand Down
26 changes: 26 additions & 0 deletions tests/unit_tests/storage/test_local_ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,29 @@ def test_that_load_parameters_throws_exception(tmp_path):

with pytest.raises(expected_exception=KeyError):
ensemble.load_parameters("I_DONT_EXIST", 1)


def test_that_only_registered_parameters_can_be_saved(tmp_path):
with open_storage(tmp_path, mode="w") as storage:
experiment = storage.create_experiment()
prior = storage.create_ensemble(
experiment,
ensemble_size=1,
iteration=0,
name="prior",
)

with pytest.raises(
ValueError, match="PARAMETER is not registered to the experiment."
):
prior.save_parameters(
"PARAMETER",
0,
xr.Dataset(
{
"values": ("names", [1.0]),
"transformed_values": ("names", [1.0]),
"names": ["KEY_1"],
}
),
)

0 comments on commit 78c9649

Please sign in to comment.