Skip to content

Commit

Permalink
Remove report_steps
Browse files Browse the repository at this point in the history
This was a remnant from when we could not load different summary
files with different report_steps. This is no longer the case, so
this is just a complication.
  • Loading branch information
oyvindeide committed Nov 25, 2024
1 parent 6a4bcd2 commit c0cb788
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 155 deletions.
6 changes: 0 additions & 6 deletions docs/everest/config_generated.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ Configuration of the Everest model
If specified, it must be a list of numeric values, one per realization.


**report_steps (optional)**
Type: *Optional[List[str]]*

List of dates allowed in the summary file.



controls (required)
-------------------
Expand Down
41 changes: 12 additions & 29 deletions src/everest/config/model_config.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from datetime import datetime
from typing import List, Optional

from pydantic import BaseModel, Field, NonNegativeInt, field_validator, model_validator
from pydantic import BaseModel, Field, NonNegativeInt, model_validator

from everest.strings import DATE_FORMAT
from ert.config import ConfigWarning


class ModelConfig(BaseModel, extra="forbid"): # type: ignore
Expand All @@ -26,10 +25,16 @@ class ModelConfig(BaseModel, extra="forbid"): # type: ignore
If specified, it must be a list of numeric values, one per realization.""",
)
report_steps: Optional[List[str]] = Field(
default=None,
description="List of dates allowed in the summary file.",
)

@model_validator(mode="before")
@classmethod
def remove_deprecated(cls, values):
if values.get("report_steps") is not None:
ConfigWarning.warn(
"report_steps no longer has any effect and can be removed."
)
values.pop("report_steps")
return values

@model_validator(mode="before")
@classmethod
Expand All @@ -47,25 +52,3 @@ def validate_realizations_weights_same_cardinaltiy(cls, values): # pylint: disa
)

return values

@field_validator("report_steps")
@classmethod
def validate_report_steps_are_dates(cls, report_steps): # pylint: disable=E0213
invalid_steps = []
for step in report_steps:
try:
if not isinstance(step, str):
invalid_steps.append(str(step))
continue

datetime.strptime(step, DATE_FORMAT)
except ValueError:
invalid_steps.append(step)

if len(invalid_steps) > 0:
raise ValueError(
f"malformed dates: {', '.join(invalid_steps)},"
f"expected format: {DATE_FORMAT}"
)

return report_steps
1 change: 0 additions & 1 deletion src/everest/config_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ class ConfigKeys:
REALIZATIONS = "realizations"
REALIZATIONS_WEIGHTS = "realizations_weights"
RELATIVE = "relative"
REPORT_STEPS = "report_steps"
RESUBMIT_LIMIT = "resubmit_limit"
SKIP_EXPORT = "skip_export"
RUN_TEMPLATE = "run_template"
Expand Down
23 changes: 0 additions & 23 deletions src/everest/simulator/everest_to_ert.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,33 +408,10 @@ def _extract_templating(ever_config: EverestConfig):
return forward_model


def _insert_strip_dates_job(everest_config: EverestConfig, forward_model):
report_steps = everest_config.model.report_steps

if report_steps:
simulation_idx = [
idx
for idx, model in enumerate(forward_model)
if "eclipse" in model.split()[0] or "flow" in model.split()[0]
]

strip_dates_job_str = "{job_name} {args}".format(
job_name="strip_dates",
args="--summary {file} --dates {dates}".format(
file="<ECLBASE>.UNSMRY", dates=" ".join(report_steps)
),
)

for idx in simulation_idx:
forward_model.insert(idx + 1, strip_dates_job_str)
return forward_model


def _extract_forward_model(ever_config: EverestConfig, ert_config):
forward_model = _extract_data_operations(ever_config)
forward_model += _extract_templating(ever_config)
forward_model += ever_config.forward_model or []
forward_model = _insert_strip_dates_job(ever_config, forward_model)

sim_job = ert_config.get(ErtConfigKeys.SIMULATION_JOB, [])
for job in forward_model:
Expand Down
1 change: 0 additions & 1 deletion test-data/everest/egg/everest/model/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ optimization:
model:
realizations: [0, 1, 2]
data_file: r{{data_file}}
report_steps: ['2014-05-30', '2014-08-28', '2014-11-26', '2015-02-24', '2015-05-25', '2015-08-23', '2015-11-21', '2016-02-19', '2016-05-19']

environment:
simulation_folder: egg_simulations
Expand Down
1 change: 0 additions & 1 deletion test-data/everest/egg/everest/model/config_flow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ optimization:
model:
realizations: [0, 1, 2]
data_file: ../../eclipse/include/realizations/realization-r{{realization}}/eclipse/model/EGG_FLOW.DATA
report_steps: ['2014-05-30', '2014-08-28', '2014-11-26', '2015-02-24', '2015-05-25', '2015-08-23', '2015-11-21', '2016-02-19', '2016-05-19']

environment:
simulation_folder: egg_simulations
Expand Down
32 changes: 5 additions & 27 deletions tests/everest/test_config_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,33 +644,6 @@ def test_that_model_data_file_exists(change_to_tmpdir):
)


def test_that_model_report_steps_invalid_dates_errors(change_to_tmpdir):
os.makedirs("config_dir/relative/path")
with open("config_dir/test.yml", "w", encoding="utf-8") as f:
f.write(" ")

with pytest.raises(ValueError) as e:
EverestConfig.with_defaults(
model={
"realizations": [1, 2, 3],
"report_steps": ["2022-02-02", "hey", "yo", "sup", "ma", "dawg"],
"data_file": "relative/path",
},
config_path=Path("config_dir/test.yml"),
)

assert has_error(e.value, "malformed dates: hey, yo, sup, ma, dawg")

EverestConfig.with_defaults(
model={
"realizations": [1, 2, 3],
"report_steps": ["2022-01-01", "2022-01-03", "2022-01-05"],
"data_file": "relative/path",
},
config_path=Path("config_dir/test.yml"),
)


@pytest.mark.parametrize(
["install_keyword"],
[
Expand Down Expand Up @@ -990,3 +963,8 @@ def test_warning_forward_model_write_objectives(objective, forward_model, warnin
objective_functions=[{"name": o} for o in objective],
forward_model=forward_model,
)


def test_deprecated_keyword():
with pytest.warns(ConfigWarning, match="report_steps .* can be removed"):
ModelConfig(**{"report_steps": []})
15 changes: 0 additions & 15 deletions tests/everest/test_egg_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,21 +537,6 @@ def _generate_exp_ert_config(config_path, output_dir):
"--version",
"2020.2",
),
(
"strip_dates",
"--summary",
"<ECLBASE>.UNSMRY",
"--dates",
"2014-05-30",
"2014-08-28",
"2014-11-26",
"2015-02-24",
"2015-05-25",
"2015-08-23",
"2015-11-21",
"2016-02-19",
"2016-05-19",
),
("rf", "-s", "eclipse/model/EGG", "-o", "rf"),
],
ErtConfigKeys.ENSPATH: os.path.join(
Expand Down
19 changes: 0 additions & 19 deletions tests/everest/test_everlint.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,25 +550,6 @@ def test_date_type():
has_error(err, match=f"malformed date: {date}(.*)")


def test_lint_report_steps():
config_file = relpath("test_data/mocked_test_case/mocked_test_case.yml")
config = EverestConfig.load_file(config_file).to_dict()
# Check initial config file is valid
assert len(EverestConfig.lint_config_dict(config)) == 0
config[ConfigKeys.MODEL][ConfigKeys.REPORT_STEPS] = [
"2000-1-1",
"2001-1-1",
"2002-1-1",
"2003-1-1",
]
# Check config file is valid after report steps have been added
assert len(EverestConfig.lint_config_dict(config)) == 0
config[ConfigKeys.MODEL][ConfigKeys.REPORT_STEPS].append("invalid_date")
# Check config no longer valid when invalid date is added
errors = EverestConfig.lint_config_dict(config)
has_error(errors, match="malformed date: invalid_date(.*)")


@pytest.mark.fails_on_macos_github_workflow
def test_lint_everest_models_jobs():
pytest.importorskip("everest_models")
Expand Down
34 changes: 1 addition & 33 deletions tests/everest/test_res_initialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
TUTORIAL_CONFIG_DIR = "mocked_test_case"


def build_snake_dict(output_dir, queue_system, report_steps=False):
def build_snake_dict(output_dir, queue_system):
# This is a tested config from ert corresponding to the
# snake_oil

Expand All @@ -50,20 +50,6 @@ def simulation_jobs():
("snake_oil_npv",),
("snake_oil_diff",),
]
if report_steps:
sim_jobs.insert(2, ("eclipse100",))
sim_jobs.insert(
3,
(
"strip_dates",
"--summary",
"<ECLBASE>.UNSMRY",
"--dates",
"2000-1-1",
"2001-1-2",
"2002-1-1",
),
)
return sim_jobs

def install_jobs():
Expand Down Expand Up @@ -610,24 +596,6 @@ def test_install_data_with_invalid_templates(
assert expected_error_msg in str(exc_info.value)


def test_strip_date_job_insertion(copy_snake_oil_to_tmp):
# Load config file
ever_config = EverestConfig.load_file(SNAKE_CONFIG_PATH)
ever_config.model.report_steps = [
"2000-1-1",
"2001-1-2",
"2002-1-1",
]
ever_config.forward_model.insert(1, "eclipse100")

output_dir = ever_config.output_dir
snake_dict = build_snake_dict(output_dir, ConfigKeys.LOCAL, report_steps=True)

# Transform to res dict and verify equality
ert_config_dict = _everest_to_ert_config_dict(ever_config)
assert snake_dict == ert_config_dict


def test_workflow_job(copy_snake_oil_to_tmp):
workflow_jobs = [{"name": "test", "source": "jobs/TEST"}]
ever_config = EverestConfig.load_file(SNAKE_CONFIG_PATH)
Expand Down

0 comments on commit c0cb788

Please sign in to comment.