Skip to content

Commit

Permalink
Add logging of duplicate gen_kw parameter names
Browse files Browse the repository at this point in the history
  • Loading branch information
larsevj committed Feb 4, 2025
1 parent 0dc2a57 commit a522de5
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/ert/config/ensemble_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ def __post_init__(self) -> None:
[p.name for p in self.parameter_configs.values()],
[key for config in self.response_configs.values() for key in config.keys],
)
self._check_for_duplicate_gen_kw_param_names(
[p for p in self.parameter_configs.values() if isinstance(p, GenKwConfig)]
)

self.grid_file = _get_abs_path(self.grid_file)

Expand All @@ -73,6 +76,23 @@ def _check_for_duplicate_names(
duplicate_names[0],
)

@staticmethod
def _check_for_duplicate_gen_kw_param_names(gen_kw_list: list[GenKwConfig]) -> None:
gen_kw_param_count = Counter(
keyword.name for p in gen_kw_list for keyword in p.transform_functions
)
duplicate_gen_kw_names = [
(n, c) for n, c in gen_kw_param_count.items() if c > 1
]

if duplicate_gen_kw_names:
duplicates_formatted = ", ".join(
f"{name}({count})" for name, count in duplicate_gen_kw_names
)
logger.info(
f"Found duplicate GEN_KW parameter names: {duplicates_formatted}"
)

@no_type_check
@classmethod
def from_dict(cls, config_dict: ConfigDict) -> EnsembleConfig:
Expand Down
29 changes: 29 additions & 0 deletions tests/ert/unit_tests/config/test_ensemble_config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import os
from datetime import datetime
from pathlib import Path
Expand Down Expand Up @@ -162,3 +163,31 @@ def test_that_empty_grid_file_raises(tmpdir):
match="did not contain dimensions",
):
_ = ErtConfig.from_file("config.ert")


@pytest.mark.usefixtures("use_tmpdir")
def test_logging_of_duplicate_gen_kw_parameter_names(caplog):
Path("MULTFLT1.TXT").write_text("a UNIFORM 0 1\nc UNIFORM 2 5", encoding="utf-8")
Path("MULTFLT2.TXT").write_text("a UNIFORM 0 1\nc UNIFORM 4 7", encoding="utf-8")
Path("FAULT_TEMPLATE").write_text("", encoding="utf-8")
config_dict = {
ConfigKeys.GEN_KW: [
[
"test_group1",
"FAULT_TEMPLATE",
"MULTFLT.INC",
"MULTFLT1.TXT",
"FORWARD_INIT:FALSE",
],
[
"test_group2",
"FAULT_TEMPLATE",
"MULTFLT.INC",
"MULTFLT2.TXT",
"FORWARD_INIT:FALSE",
],
],
}
with caplog.at_level(logging.INFO):
EnsembleConfig.from_dict(config_dict=config_dict)
assert "Found duplicate GEN_KW parameter names: a(2), c(2)" in caplog.text

0 comments on commit a522de5

Please sign in to comment.