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

Backports to version 8.0 branch #6874

Merged
merged 3 commits into from
Jan 3, 2024
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
4 changes: 2 additions & 2 deletions docs/reference/configuration/keywords.rst
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,8 @@ Commonly used keywords
will be replaced by the realization number and iteration number when ERT creates the folders.
By default, RUNPATH is set to "simulations/realization-<IENS>/iter-<ITER>".

Deprecated syntax still allow use of two %d specifers. Use of less than two %d is prohibited.
The behaviour is identical to the default substitution.
Deprecated syntax still allow use of two `%d` specifers. Use of more than two `%d` specifiers,
using multiple `<IENS>` or `<ITER>` keywords or mixing styles is prohibited.

*Example:*

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ dependencies=[
"ert-storage >= 0.3.16",
"fastapi < 0.100.0",
"filelock",
"iterative_ensemble_smoother>=0.1.1",
"iterative_ensemble_smoother==0.1.1",
"typing_extensions",
"jinja2",
"lark",
Expand Down
26 changes: 23 additions & 3 deletions src/ert/config/model_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,31 @@ def __init__(
self.history_source = history_source
self.jobname_format_string = _replace_runpath_format(jobname_format_string)
self.eclbase_format_string = _replace_runpath_format(eclbase_format_string)
self.runpath_format_string = _replace_runpath_format(runpath_format_string)

if self.runpath_format_string is not None and not any(
x in self.runpath_format_string for x in ["<ITER>", "<IENS>"]
# do not combine styles
if "%d" in runpath_format_string and any(
x in runpath_format_string for x in ["<ITER>", "<IENS>"]
):
raise ConfigValidationError(
f"RUNPATH cannot combine deprecated and new style placeholders: `{runpath_format_string}`. Valid example `{DEFAULT_RUNPATH}`"
)

# do not allow multiple occurrences
for kw in ["<ITER>", "<IENS>"]:
if runpath_format_string.count(kw) > 1:
raise ConfigValidationError(
f"RUNPATH cannot contain multiple {kw} placeholders: `{runpath_format_string}`. Valid example `{DEFAULT_RUNPATH}`"
)

# do not allow too many placeholders
if runpath_format_string.count("%d") > 2:
raise ConfigValidationError(
f"RUNPATH cannot contain more than two value placeholders: `{runpath_format_string}`. Valid example `{DEFAULT_RUNPATH}`"
)

self.runpath_format_string = _replace_runpath_format(runpath_format_string)

if not any(x in self.runpath_format_string for x in ["<ITER>", "<IENS>"]):
logger.warning(
"RUNPATH keyword contains no value placeholders: "
f"`{runpath_format_string}`. Valid example: "
Expand Down
100 changes: 47 additions & 53 deletions src/ert/gui/tools/plot/plot_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,59 +115,53 @@ def currentPlotChanged(self):
return
key = key_def["key"]

for plot_widget in self._plot_widgets:
index = self._central_tab.indexOf(plot_widget)
if (
index == self._central_tab.currentIndex()
and plot_widget._plotter.dimensionality == key_def["dimensionality"]
):
self._updateCustomizer(plot_widget)
cases = self._case_selection_widget.getPlotCaseNames()
case_to_data_map = {}
for case in cases:
try:
case_to_data_map[case] = self._api.data_for_key(case, key)
except (RequestError, TimeoutError) as e:
logger.exception(e)
msg = f"{e}"

QMessageBox.critical(self, "Request Failed", msg)

observations = None
if key_def["observations"] and cases:
try:
observations = self._api.observations_for_key(cases[0], key)
except (RequestError, TimeoutError) as e:
logger.exception(e)
msg = f"{e}"

QMessageBox.critical(self, "Request Failed", msg)

plot_config = PlotConfig.createCopy(
self._plot_customizer.getPlotConfig()
)
plot_config.setTitle(key)
plot_context = PlotContext(plot_config, cases, key)

case = plot_context.cases()[0] if plot_context.cases() else None

# Check if key is a history key.
# If it is it already has the data it needs
if str(key).endswith("H") or "H:" in str(key):
plot_context.history_data = DataFrame()
else:
try:
plot_context.history_data = self._api.history_data(key, case)
except (RequestError, TimeoutError) as e:
logger.exception(e)
msg = f"{e}"

QMessageBox.critical(self, "Request Failed", msg)
plot_context.history_data = None

plot_context.log_scale = key_def["log_scale"]

plot_widget.updatePlot(plot_context, case_to_data_map, observations)
plot_widget = self._central_tab.currentWidget()

if plot_widget._plotter.dimensionality == key_def["dimensionality"]:
self._updateCustomizer(plot_widget)
cases = self._case_selection_widget.getPlotCaseNames()
case_to_data_map = {}
for case in cases:
try:
case_to_data_map[case] = self._api.data_for_key(case, key)
except (RequestError, TimeoutError) as e:
logger.exception(e)
msg = f"{e}"

QMessageBox.critical(self, "Request Failed", msg)

observations = None
if key_def["observations"] and cases:
try:
observations = self._api.observations_for_key(cases[0], key)
except (RequestError, TimeoutError) as e:
logger.exception(e)
msg = f"{e}"

QMessageBox.critical(self, "Request Failed", msg)

plot_config = PlotConfig.createCopy(self._plot_customizer.getPlotConfig())
plot_context = PlotContext(plot_config, cases, key)

case = plot_context.cases()[0] if plot_context.cases() else None

# Check if key is a history key.
# If it is it already has the data it needs
if str(key).endswith("H") or "H:" in str(key):
plot_context.history_data = DataFrame()
else:
try:
plot_context.history_data = self._api.history_data(key, case)
except (RequestError, TimeoutError) as e:
logger.exception(e)
msg = f"{e}"

QMessageBox.critical(self, "Request Failed", msg)
plot_context.history_data = None

plot_context.log_scale = key_def["log_scale"]

plot_widget.updatePlot(plot_context, case_to_data_map, observations)

def _updateCustomizer(self, plot_widget: PlotWidget):
key_def = self.getSelectedKey()
Expand Down
52 changes: 51 additions & 1 deletion tests/unit_tests/test_run_path_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import pytest

from ert.config import ErtConfig
from ert.config import ConfigValidationError, ErtConfig
from ert.enkf_main import create_run_path, ensemble_context, sample_prior
from ert.run_context import RunContext
from ert.runpaths import Runpaths
Expand Down Expand Up @@ -469,3 +469,53 @@ def test_num_cpu_subst(monkeypatch, tmp_path, append, numcpu, storage):

with open("simulations/realization-0/iter-0/jobs.json", encoding="utf-8") as f:
assert f'"argList": ["{numcpu}"]' in f.read()


@pytest.mark.parametrize(
"run_path, expected_raise, msg",
[
("simulations/realization-<IENS>/iter-<ITER>", False, ""),
("simulations/realization-%d/iter-%d", False, ""),
("simulations/realization-%d", False, ""),
(
"simulations/realization-<IENS>/iter-%d",
True,
"RUNPATH cannot combine deprecated ",
),
(
"simulations/realization-<IENS>/iter-<IENS>",
True,
"RUNPATH cannot contain multiple <IENS>",
),
(
"simulations/realization-<ITER>/iter-<ITER>",
True,
"RUNPATH cannot contain multiple <ITER>",
),
(
"simulations/realization-%d/iter-%d/more-%d",
True,
"RUNPATH cannot contain more than two",
),
],
)
@pytest.mark.usefixtures("use_tmpdir")
def test_that_runpaths_are_raised_when_invalid(run_path, expected_raise, msg):
"""
This checks that RUNPATH does not include too many or few substitution placeholders
"""
config_text = dedent(
"""
NUM_REALIZATIONS 2
"""
)
Path("config.ert").write_text(config_text + f"RUNPATH {run_path}", encoding="utf-8")

if expected_raise:
with pytest.raises(
ConfigValidationError,
match=f"{msg}.*{run_path}`.",
):
_ = ErtConfig.from_file("config.ert")
else:
_ = ErtConfig.from_file("config.ert")
Loading