Skip to content

Commit

Permalink
Warn in case of empty SummaryConfig.keys
Browse files Browse the repository at this point in the history
  • Loading branch information
eivindjahren committed Feb 19, 2024
1 parent 84dbd67 commit 58cf54f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/ert/config/ert_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ def __post_init__(self) -> None:
else os.getcwd()
)
self.enkf_obs: EnkfObs = self._create_observations()
if (
"summary" in self.ensemble_config
and len(self.ensemble_config["summary"].keys) == 0
):
# There is a bug with storing empty responses so we have
# to warn that the forward model fails in this case
# https://github.com/equinor/ert/issues/6974
ConfigWarning.ert_context_warn(
"Setting ECLBASE without using SUMMARY, SUMMARY_OBSERVATION, "
"or HISTORY_OBSERVATION most likely causes the forward model to fail."
"to silence this warning just add 'SUMMARY *' to your config file.",
)
self.observations: Dict[str, xr.Dataset] = self.enkf_obs.datasets

@classmethod
Expand Down
14 changes: 13 additions & 1 deletion src/ert/config/observations.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,21 @@ def _handle_history_observation(
history_type: Optional[HistorySource],
time_len: int,
) -> Dict[str, ObsVector]:
if "summary" not in ensemble_config:
raise ObservationConfigError.with_context(
"In order to use history observation, ECLBASE has to be set",
summary_key,
)
response_config = ensemble_config["summary"]
assert isinstance(response_config, SummaryConfig)

refcase = ensemble_config.refcase
if refcase is None:
raise ObservationConfigError("REFCASE is required for HISTORY_OBSERVATION")
if history_type is None:
raise ValueError("Need a history type in order to use history observations")
raise ObservationConfigError(
"Need a history type in order to use history observations"
)

if summary_key not in response_config.keys:
response_config.keys.append(summary_key)
Expand Down Expand Up @@ -274,6 +281,11 @@ def _handle_summary_observation(
time_map: List[datetime],
) -> Dict[str, ObsVector]:
summary_key = summary_dict["KEY"]
if "summary" not in ensemble_config:
raise ObservationConfigError.with_context(
"In order to use summary observation, ECLBASE has to be set",
obs_key,
)
summary_config = ensemble_config["summary"]
assert isinstance(summary_config, SummaryConfig)
if summary_key not in summary_config.keys:
Expand Down
1 change: 1 addition & 0 deletions src/ert/config/summary_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def read_from_file(self, run_path: str, iens: int) -> xr.Dataset:
filename = self.input_file.replace("<IENS>", str(iens))
_, keys, time_map, data = read_summary(f"{run_path}/{filename}", self.keys)
if len(data) == 0 or len(keys) == 0:
# https://github.com/equinor/ert/issues/6974
# There is a bug with storing empty responses so we have
# to raise an error in that case
raise ValueError(
Expand Down
17 changes: 17 additions & 0 deletions tests/unit_tests/config/test_observations.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,23 @@ def test_date_parsing_in_observations(datestring, errors):
ErtConfig.from_file("config.ert")


def test_that_using_summary_observations_without_eclbase_shows_user_error():
config_text = dedent(
"""
NUM_REALIZATIONS 1
OBS_CONFIG observations_config
"""
)
Path("observations_config").write_text(
"SUMMARY_OBSERVATION FOPR_1 "
"{ KEY=FOPR; VALUE=1; ERROR=1; DATE=2023-03-15; };",
encoding="utf-8",
)
Path("config.ert").write_text(config_text, encoding="utf-8")
with pytest.raises(ObservationConfigError, match="ECLBASE has to be set"):
ErtConfig.from_file("config.ert")


def test_observations(minimum_case):
observations = minimum_case.enkf_obs
count = 10
Expand Down

0 comments on commit 58cf54f

Please sign in to comment.