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

[Backport] Fix faulty validation for maintained forward model objectives. #9225

Merged
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
2 changes: 1 addition & 1 deletion src/everest/config/everest_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ def validate_maintained_forward_models(self) -> Self:

@model_validator(mode="after")
def validate_maintained_forward_model_write_objectives(self) -> Self:
if not self.objective_functions:
if not self.objective_functions or not self.forward_model:
return self
objectives = {objective.name for objective in self.objective_functions}
check_forward_model_objective(self.forward_model, objectives)
Expand Down
28 changes: 16 additions & 12 deletions tests/everest/test_config_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -952,37 +952,41 @@ def test_that_non_existing_workflow_jobs_cause_error():
@skipif_no_everest_models
@pytest.mark.everest_models_test
@pytest.mark.parametrize(
["objective", "warning_msg"],
["objective", "forward_model", "warning_msg"],
[
(
["npv", "rf"],
["rf -s TEST -o rf"],
"Warning: Forward model might not write the required output file for \\['npv'\\]",
),
(
["npv", "npv2"],
["rf -s TEST -o rf"],
"Warning: Forward model might not write the required output files for \\['npv', 'npv2'\\]",
),
(["rf"], None),
(
["rf"],
["rf -s TEST -o rf"],
None,
),
(
["rf"],
None,
None,
),
],
)
def test_warning_forward_model_write_objectives(objective, warning_msg):
fm_steps = [
"well_constraints -i files/well_readydate.json -c files/wc_config.yml -rc well_rate.json -o wc_wells.json",
"add_templates -i wc_wells.json -c files/at_config.yml -o at_wells.json",
"schmerge -s eclipse/include/schedule/schedule.tmpl -i at_wells.json -o eclipse/include/schedule/schedule.sch",
"eclipse100 TEST.DATA --version 2020.2",
"rf -s TEST -o rf",
]
def test_warning_forward_model_write_objectives(objective, forward_model, warning_msg):
if warning_msg is not None:
with pytest.warns(ConfigWarning, match=warning_msg):
EverestConfig.with_defaults(
objective_functions=[{"name": o} for o in objective],
forward_model=fm_steps,
forward_model=forward_model,
)
else:
with warnings.catch_warnings():
warnings.simplefilter("error", category=ConfigWarning)
EverestConfig.with_defaults(
objective_functions=[{"name": o} for o in objective],
forward_model=fm_steps,
forward_model=forward_model,
)