Skip to content

Commit

Permalink
Disable modes that do parameter updates if there are no params to update
Browse files Browse the repository at this point in the history
If all parameters have UPDATE:FALSE set, then we should not let the user
select any mode that does parameter updates.
  • Loading branch information
JHolba committed Nov 11, 2024
1 parent a7559fd commit 3fec61f
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 9 deletions.
17 changes: 12 additions & 5 deletions src/ert/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,22 @@ def run_cli(args: Namespace, plugin_manager: Optional[ErtPluginManager] = None)
f"'OBS_CONFIG observation_file.txt'."
)

if not ert_config.ensemble_config.parameter_configs and args.mode in [
if args.mode in [
ENSEMBLE_SMOOTHER_MODE,
ES_MDA_MODE,
ITERATIVE_ENSEMBLE_SMOOTHER_MODE,
]:
raise ErtCliError(
f"To run {args.mode}, GEN_KW, FIELD or SURFACE parameters are needed. \n"
f"Please add to file {args.config}"
)
if not ert_config.ensemble_config.parameter_configs:
raise ErtCliError(
f"To run {args.mode}, GEN_KW, FIELD or SURFACE parameters are needed. \n"
f"Please add to file {args.config}"
)
if not any(
p.update for p in ert_config.ensemble_config.parameter_configs.values()
):
raise ErtCliError(
f"All parameters are set to UPDATE:FALSE in {args.config}"
)

storage = open_storage(ert_config.ens_path, "w")

Expand Down
10 changes: 6 additions & 4 deletions src/ert/gui/simulation/experiment_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ def __init__(
True,
)

experiment_type_valid = bool(
config.ensemble_config.parameter_configs and config.observations
)
experiment_type_valid = any(
p.update for p in config.ensemble_config.parameter_configs.values()
) and bool(config.observations)

self.addExperimentConfigPanel(
MultipleDataAssimilationPanel(
Expand Down Expand Up @@ -202,7 +202,9 @@ def addExperimentConfigPanel(
sim_item = model.item(item_count)
assert sim_item is not None
sim_item.setEnabled(False)
sim_item.setToolTip("Both observations and parameters must be defined")
sim_item.setToolTip(
"Both observations and parameters must be defined.\nThere must be parameters to update."
)
style = self.style()
assert style is not None
sim_item.setIcon(
Expand Down
32 changes: 32 additions & 0 deletions tests/ert/ui_tests/cli/test_parameter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import fileinput
from argparse import ArgumentParser

import pytest

from ert.__main__ import ert_parser
from ert.cli.main import ErtCliError, run_cli
from ert.mode_definitions import ENSEMBLE_SMOOTHER_MODE


@pytest.mark.usefixtures("copy_poly_case")
def test_running_smoother_raises_without_updateable_parameters():
with fileinput.input("poly.ert", inplace=True) as fin:
for line in fin:
if "GEN_KW COEFFS coeff_priors" in line:
print(f"{line[:-1]} UPDATE:FALSE")
else:
print(line, end="")

parser = ArgumentParser(prog="test_main")
parsed = ert_parser(
parser,
[
ENSEMBLE_SMOOTHER_MODE,
"--disable-monitor",
"poly.ert",
],
)

with pytest.raises(ErtCliError) as e:
run_cli(parsed)
assert "All parameters are set to UPDATE:FALSE in" in str(e)
38 changes: 38 additions & 0 deletions tests/ert/ui_tests/gui/test_missing_parameters_to_update.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import fileinput

import pytest
from qtpy.QtCore import Qt
from qtpy.QtWidgets import QComboBox

from ert.gui.simulation.experiment_panel import ExperimentPanel
from tests.ert.ui_tests.gui.conftest import get_child, open_gui_with_config


@pytest.mark.usefixtures("copy_poly_case")
def test_no_updateable_parameters(qtbot):
with fileinput.input("poly.ert", inplace=True) as fin:
for line in fin:
if "GEN_KW COEFFS coeff_priors" in line:
print(f"{line[:-1]} UPDATE:FALSE")
else:
print(line, end="")

for gui in open_gui_with_config("poly.ert"):
experiment_panel = get_child(gui, ExperimentPanel)
simulation_mode_combo = get_child(experiment_panel, QComboBox)
idx = simulation_mode_combo.findText("Ensemble smoother")
assert not (
simulation_mode_combo.model().item(idx).flags() & Qt.ItemFlag.ItemIsEnabled
)
idx = simulation_mode_combo.findText("Multiple data assimilation")
assert not (
simulation_mode_combo.model().item(idx).flags() & Qt.ItemFlag.ItemIsEnabled
)
idx = simulation_mode_combo.findText("Iterated ensemble smoother")
assert not (
simulation_mode_combo.model().item(idx).flags() & Qt.ItemFlag.ItemIsEnabled
)
idx = simulation_mode_combo.findText("Ensemble experiment")
assert (
simulation_mode_combo.model().item(idx).flags() & Qt.ItemFlag.ItemIsEnabled
)

0 comments on commit 3fec61f

Please sign in to comment.