Skip to content

Commit

Permalink
Raise warning when summary key and no simulator job present in ert co…
Browse files Browse the repository at this point in the history
…nfig
  • Loading branch information
DanSava authored Oct 2, 2024
1 parent 21bbca8 commit 0774438
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 7 deletions.
20 changes: 15 additions & 5 deletions src/ert/config/summary_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import logging
from dataclasses import dataclass
from datetime import datetime
from typing import TYPE_CHECKING, Optional, Set, Union
from typing import TYPE_CHECKING, Optional, Set, Union, no_type_check

import xarray as xr

from ._read_summary import read_summary
from .ensemble_config import Refcase
from .parsing import ConfigDict, ConfigKeys
from .parsing.config_errors import ConfigValidationError
from .parsing.config_errors import ConfigValidationError, ConfigWarning
from .response_config import ResponseConfig
from .responses_index import responses_index

Expand Down Expand Up @@ -57,17 +57,27 @@ def read_from_file(self, run_path: str, iens: int) -> xr.Dataset:
def response_type(self) -> str:
return "summary"

@no_type_check
@classmethod
def from_config_dict(cls, config_dict: ConfigDict) -> Optional[SummaryConfig]:
refcase = Refcase.from_config_dict(config_dict)
if summary_keys := config_dict.get(ConfigKeys.SUMMARY, []): # type: ignore
eclbase: Optional[str] = config_dict.get("ECLBASE") # type: ignore
if summary_keys := config_dict.get(ConfigKeys.SUMMARY, []):
eclbase: Optional[str] = config_dict.get("ECLBASE")
if eclbase is None:
raise ConfigValidationError(
"In order to use summary responses, ECLBASE has to be set."
)
time_map = set(refcase.dates) if refcase is not None else None

forward_model = config_dict.get(ConfigKeys.FORWARD_MODEL, [])
names = [fm_step[0] for fm_step in forward_model]
simulation_step_exists = any(
any(sim in _name.lower() for sim in ["eclipse", "flow"])
for _name in names
)
if not simulation_step_exists:
ConfigWarning.warn(
"Config contains a SUMMARY key but no forward model steps known to generate a summary file"
)
return cls(
name="summary",
input_files=[eclbase.replace("%d", "<IENS>")],
Expand Down
4 changes: 2 additions & 2 deletions test-data/ert/snake_oil_field/snake_oil_surface.ert
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ REFCASE refcase/SNAKE_OIL_FIELD
TIME_MAP refcase/time_map.txt
OBS_CONFIG observations/observations.txt

INSTALL_JOB SNAKE_OIL_SIMULATOR jobs/SNAKE_OIL_SIMULATOR
INSTALL_JOB SNAKE_OIL_ECLIPSE_SIMULATOR jobs/SNAKE_OIL_SIMULATOR
INSTALL_JOB SNAKE_OIL_NPV jobs/SNAKE_OIL_NPV
INSTALL_JOB SNAKE_OIL_DIFF jobs/SNAKE_OIL_DIFF

FORWARD_MODEL SNAKE_OIL_SIMULATOR
FORWARD_MODEL SNAKE_OIL_ECLIPSE_SIMULATOR
FORWARD_MODEL SNAKE_OIL_NPV
FORWARD_MODEL SNAKE_OIL_DIFF

Expand Down
62 changes: 62 additions & 0 deletions tests/ert/unit_tests/config/test_ert_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1609,3 +1609,65 @@ def test_general_option_in_local_config_has_priority_over_site_config():
assert config.queue_config.max_running == 13
assert config.queue_config.submit_sleep == 14
assert config.queue_config.queue_system == QueueSystem.TORQUE


@pytest.mark.usefixtures("use_tmpdir")
def test_warning_raised_when_summary_key_and_no_simulation_job_present(caplog, recwarn):
caplog.set_level(logging.WARNING)

with open("job_file", "w", encoding="utf-8") as fout:
fout.write("EXECUTABLE echo\nARGLIST <ECLBASE> <RUNPATH>\n")

with open("config_file.ert", "w", encoding="utf-8") as fout:
# Write a minimal config file
fout.write("NUM_REALIZATIONS 1\n")
fout.write("SUMMARY *\n")
fout.write("ECLBASE RESULT_SUMMARY\n")

fout.write("INSTALL_JOB job_name job_file\n")
fout.write(
"FORWARD_MODEL job_name(<ECLBASE>=A/<ECLBASE>, <RUNPATH>=<RUNPATH>/x)\n"
)

ErtConfig.from_file("config_file.ert")

# Check no warning is logged when config contains
# forward model step with <ECLBASE> and <RUNPATH> as arguments
assert not caplog.text
assert len(recwarn) == 1
assert issubclass(recwarn[0].category, ConfigWarning)
assert (
recwarn[0].message.info.message
== "Config contains a SUMMARY key but no forward model steps known to generate a summary file"
)


@pytest.mark.parametrize(
"job_name", ["eclipse", "eclipse100", "flow", "FLOW", "ECLIPSE100"]
)
@pytest.mark.usefixtures("use_tmpdir")
def test_no_warning_when_summary_key_and_simulation_job_present(
caplog, recwarn, job_name
):
caplog.set_level(logging.WARNING)

with open("job_file", "w", encoding="utf-8") as fout:
fout.write("EXECUTABLE echo\nARGLIST <ECLBASE> <RUNPATH>\n")

with open("config_file.ert", "w", encoding="utf-8") as fout:
# Write a minimal config file
fout.write("NUM_REALIZATIONS 1\n")
fout.write("SUMMARY *\n")
fout.write("ECLBASE RESULT_SUMMARY\n")

fout.write(f"INSTALL_JOB {job_name} job_file\n")
fout.write(
f"FORWARD_MODEL {job_name}(<ECLBASE>=A/<ECLBASE>, <RUNPATH>=<RUNPATH>/x)\n"
)

ErtConfig.from_file("config_file.ert")

# Check no warning is logged when config contains
# forward model step with <ECLBASE> and <RUNPATH> as arguments
assert not caplog.text
assert len(recwarn) == 0

0 comments on commit 0774438

Please sign in to comment.