Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logging of duplicate gen_kw parameter names #9086

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading