Skip to content

Commit

Permalink
Allow non zero iteration number when creating experiment-ensemble pai…
Browse files Browse the repository at this point in the history
…r using CreateExperimentDialog
  • Loading branch information
DanSava committed Oct 8, 2024
1 parent 5776d0e commit 65689fb
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 7 deletions.
33 changes: 27 additions & 6 deletions src/ert/gui/ertwidgets/create_experiment_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@
)

from ert.gui.ertnotifier import ErtNotifier
from ert.gui.ertwidgets import StringBox, TextModel
from ert.validation.proper_name_argument import (
from ert.gui.ertwidgets import StringBox, TextModel, ValueModel
from ert.validation import (
ExperimentValidation,
IntegerArgument,
ProperNameArgument,
)


class CreateExperimentDialog(QDialog):
onDone = Signal(str, str)
onDone = Signal(str, str, int)

def __init__(
self,
Expand Down Expand Up @@ -54,6 +55,15 @@ def __init__(
)
self._ensemble_edit.setValidator(ProperNameArgument())

iteration_label = QLabel("Ensemble iteration:")
self._iterations_model = ValueModel(0) # type: ignore
self._iterations_field = StringBox(
self._iterations_model, # type: ignore
"0",
minimum_width=200,
)
self._iterations_field.setValidator(IntegerArgument(from_value=0))
self._iterations_field.setObjectName("iterations_field_ced")
buttons = QDialogButtonBox(
QDialogButtonBox.Ok | QDialogButtonBox.Cancel,
Qt.Orientation.Horizontal,
Expand All @@ -67,7 +77,7 @@ def __init__(

self._ok_button.clicked.connect(
lambda: self.onDone.emit(
self._experiment_edit.get_text, self._ensemble_edit.get_text
self.experiment_name, self.ensemble_name, self.iteration
)
)

Expand All @@ -76,12 +86,15 @@ def enableOkButton() -> None:

self._experiment_edit.textChanged.connect(enableOkButton)
self._ensemble_edit.textChanged.connect(enableOkButton)
self._iterations_field.textChanged.connect(enableOkButton)

layout.addWidget(experiment_label, 0, 0)
layout.addWidget(self._experiment_edit, 0, 1)
layout.addWidget(ensemble_label, 1, 0)
layout.addWidget(self._ensemble_edit, 1, 1)
layout.addWidget(buttons, 2, 1)
layout.addWidget(iteration_label, 2, 0)
layout.addWidget(self._iterations_field, 2, 1)
layout.addWidget(buttons, 3, 1)

self.setLayout(layout)

Expand All @@ -103,5 +116,13 @@ def experiment_name(self) -> str:
def ensemble_name(self) -> str:
return self._ensemble_edit.get_text

@property
def iteration(self) -> int:
return int(self._iterations_field.get_text)

def isConfigurationValid(self) -> bool:
return self._experiment_edit.isValid() and self._ensemble_edit.isValid()
return (
self._experiment_edit.isValid()
and self._ensemble_edit.isValid()
and self._iterations_field.isValid()
)
1 change: 1 addition & 0 deletions src/ert/gui/tools/manage_experiments/storage_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ def _addItem(self) -> None:
).create_ensemble(
name=create_experiment_dialog.ensemble_name,
ensemble_size=self._ensemble_size,
iteration=create_experiment_dialog.iteration,
)
self._notifier.set_current_ensemble(ensemble)
self._notifier.ertChanged.emit()
3 changes: 2 additions & 1 deletion src/ert/validation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from .argument_definition import ArgumentDefinition
from .integer_argument import IntegerArgument
from .number_list_string_argument import NumberListStringArgument
from .proper_name_argument import ProperNameArgument
from .proper_name_argument import ExperimentValidation, ProperNameArgument
from .proper_name_format_argument import ProperNameFormatArgument
from .range_string_argument import RangeStringArgument
from .rangestring import mask_to_rangestring, rangestring_to_list, rangestring_to_mask
Expand All @@ -11,6 +11,7 @@
__all__ = [
"ActiveRange",
"ArgumentDefinition",
"ExperimentValidation",
"IntegerArgument",
"NumberListStringArgument",
"ProperNameArgument",
Expand Down
7 changes: 7 additions & 0 deletions tests/ert/ui_tests/gui/test_main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,12 +548,19 @@ def handle_add_dialog():
dialog._ensemble_edit.setText("_new_ensemble_")
assert dialog._ok_button.isEnabled()

dialog._iterations_field.setText("a")
assert not dialog._ok_button.isEnabled()
dialog._iterations_field.setText("42")
assert dialog._ok_button.isEnabled()

qtbot.mouseClick(dialog._ok_button, Qt.MouseButton.LeftButton)

QTimer.singleShot(1000, handle_add_dialog)
create_widget = get_child(storage_widget, AddWidget)
qtbot.mouseClick(create_widget.addButton, Qt.LeftButton)

assert experiments_panel.notifier.current_ensemble.iteration == 42

# Go to the "initialize from scratch" panel
experiments_panel.setCurrentIndex(1)
current_tab = experiments_panel.currentWidget()
Expand Down

0 comments on commit 65689fb

Please sign in to comment.