Skip to content

Commit

Permalink
Have ModelConfig output more noticable warning when malformatted runpath
Browse files Browse the repository at this point in the history
This commit makes ModelConfig emit a ConfigWarning if the input runpath does not contain `<ITER>` or `<IENS>`. This was previously only a warning in the logs, but it should be more noticable.
  • Loading branch information
jonathan-eq committed Dec 2, 2024
1 parent c9fc8d3 commit de45683
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/ert/config/model_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@
from pydantic import field_validator
from pydantic.dataclasses import dataclass

from .parsing import ConfigDict, ConfigKeys, ConfigValidationError, HistorySource
from .parsing import (
ConfigDict,
ConfigKeys,
ConfigValidationError,
ConfigWarning,
HistorySource,
)

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -70,11 +76,13 @@ def validate_runpath(cls, runpath_format_string: str) -> str:
)
result = _replace_runpath_format(runpath_format_string)
if not any(x in result for x in ["<ITER>", "<IENS>"]):
logger.warning(
msg = (
"RUNPATH keyword contains no value placeholders: "
f"`{runpath_format_string}`. Valid example: "
f"`{DEFAULT_RUNPATH}` "
)
ConfigWarning.warn(msg)
logger.warning(msg)
return result

@field_validator("jobname_format_string", mode="before")
Expand Down
17 changes: 17 additions & 0 deletions tests/ert/unit_tests/config/test_ert_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1852,3 +1852,20 @@ def test_no_warning_when_summary_key_and_simulation_job_present(job_name, key):
with warnings.catch_warnings():
warnings.simplefilter("error", category=ConfigWarning)
ErtConfig.from_file("config_file.ert")


def test_warning_is_emitted_when_malformatted_runpath(tmp_path):
config_path = tmp_path / "config_file.ert"
with open(config_path, "w", encoding="utf-8") as fout:
# Write a minimal config file
fout.write(
"RUNPATH <STORAGE>/runpath/constant-realization-num/contant-iter-num\n"
)
fout.write("NUM_REALIZATIONS 1\n")
with warnings.catch_warnings(record=True) as all_warnings:
ErtConfig.from_file(config_path)
assert any(
("RUNPATH keyword contains no value placeholders" in str(w.message))
for w in all_warnings
if isinstance(w.message, ConfigWarning)
)

0 comments on commit de45683

Please sign in to comment.