Skip to content

Commit

Permalink
Replace done_button with simulation flag
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas-el committed Oct 17, 2024
1 parent e5d3227 commit 21203bb
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 51 deletions.
14 changes: 6 additions & 8 deletions src/ert/gui/simulation/run_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,6 @@ def __init__(
self.memory_usage = QLabel("")

self.kill_button = QPushButton("Terminate experiment")
self.done_button = QPushButton("Done")
self.done_button.setHidden(True)
self.restart_button = QPushButton("Rerun failed")
self.restart_button.setHidden(True)
self.copy_debug_info_button = QPushButton("Debug Info")
Expand All @@ -256,7 +254,6 @@ def __init__(
button_layout.addStretch()
button_layout.addWidget(self.copy_debug_info_button)
button_layout.addWidget(self.kill_button)
button_layout.addWidget(self.done_button)
button_layout.addWidget(self.restart_button)

button_widget_container = QWidget()
Expand Down Expand Up @@ -294,14 +291,17 @@ def __init__(
self.setLayout(layout)

self.kill_button.clicked.connect(self.killJobs) # type: ignore
self.done_button.clicked.connect(self.hide)
self.restart_button.clicked.connect(self.restart_failed_realizations)
self.simulation_done.connect(self._on_simulation_done)

self.setMinimumSize(self._minimum_width, self._minimum_height)
self.finished.connect(self._on_finished)

self._restart = False
self.flag_simulation_done = False

def is_simulation_done(self) -> bool:
return self.flag_simulation_done

def _current_tab_changed(self, index: int) -> None:
widget = self._tab_widget.widget(index)
Expand Down Expand Up @@ -351,12 +351,12 @@ def _select_real(self, index: QModelIndex) -> None:
def closeEvent(self, a0: Optional[QCloseEvent]) -> None:
if not self._notifier.is_simulation_running:
self.finished.emit()
# self.accept()
elif self.killJobs() != QMessageBox.Yes and a0 is not None:
a0.ignore()

def run_experiment(self, restart: bool = False) -> None:
self._restart = restart
self.flag_simulation_done = False
if restart is False:
self._snapshot_model.reset()
self._tab_widget.clear()
Expand Down Expand Up @@ -403,7 +403,6 @@ def killJobs(self) -> QMessageBox.StandardButton:
# Normally this slot would be invoked by the signal/slot system,
# but the worker is busy tracking the evaluation.
self._run_model.cancel()
self._on_finished()
self.finished.emit()
return kill_job

Expand Down Expand Up @@ -440,7 +439,6 @@ def _on_event(self, event: object) -> None:
self.simulation_done.emit(event.failed, event.msg)
self.finished.emit()
self._ticker.stop()
self.done_button.setHidden(False)
elif isinstance(event, FullSnapshotEvent):
if event.snapshot is not None:
if self._restart:
Expand Down Expand Up @@ -541,13 +539,13 @@ def restart_failed_realizations(self) -> None:
if result == QMessageBox.Ok:
self.restart_button.setVisible(False)
self.kill_button.setVisible(True)
self.done_button.setVisible(False)
self.run_experiment(restart=True)

def get_runtime(self) -> int:
return self._run_model.get_runtime()

def _on_finished(self) -> None:
self.flag_simulation_done = True
for file_dialog in self.findChildren(FileDialog):
file_dialog.close()

Expand Down
3 changes: 1 addition & 2 deletions tests/ert/ui_tests/gui/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def handle_dialog():
# then click it
run_dialog = wait_for_child(gui, qtbot, RunDialog, timeout=10000)
qtbot.waitUntil(
lambda: not run_dialog.done_button.isHidden(), timeout=200000
lambda: run_dialog.is_simulation_done() == True, timeout=200000
)
qtbot.waitUntil(lambda: run_dialog._tab_widget.currentWidget() is not None)

Expand All @@ -268,7 +268,6 @@ def handle_dialog():
list_model.rowCount()
== experiment_panel.config.model_config.num_realizations
)
qtbot.mouseClick(run_dialog.done_button, Qt.LeftButton)

return func

Expand Down
3 changes: 1 addition & 2 deletions tests/ert/ui_tests/gui/test_csv_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,8 @@ def run_experiment_via_gui(gui, qtbot):
qtbot.mouseClick(run_experiment, Qt.LeftButton)

run_dialog = wait_for_child(gui, qtbot, RunDialog)
qtbot.waitUntil(lambda: not run_dialog.done_button.isHidden(), timeout=10000)
qtbot.waitUntil(lambda: run_dialog.is_simulation_done() == True, timeout=10000)
qtbot.waitUntil(lambda: run_dialog._tab_widget.currentWidget() is not None)
qtbot.mouseClick(run_dialog.done_button, Qt.LeftButton)


from ert.storage import open_storage
Expand Down
3 changes: 1 addition & 2 deletions tests/ert/ui_tests/gui/test_full_manual_update_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ def test_manual_analysis_workflow(ensemble_experiment_has_run, qtbot):
qtbot.mouseClick(run_experiment, Qt.LeftButton)
# The Run dialog opens, wait until done appears, then click done
run_dialog = wait_for_child(gui, qtbot, RunDialog)
qtbot.waitUntil(lambda: not run_dialog.done_button.isHidden(), timeout=10000)
qtbot.waitUntil(lambda: run_dialog.is_simulation_done() == True, timeout=10000)
qtbot.waitUntil(lambda: run_dialog._tab_widget.currentWidget() is not None)
qtbot.mouseClick(run_dialog.done_button, Qt.LeftButton)

button_manage_experiments = gui.findChild(QToolButton, "button_Manage_experiments")
assert button_manage_experiments
Expand Down
3 changes: 1 addition & 2 deletions tests/ert/ui_tests/gui/test_main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,8 +554,7 @@ def handle_error_dialog(run_dialog):
run_dialog = wait_for_child(gui, qtbot, RunDialog)

QTimer.singleShot(200, lambda: handle_error_dialog(run_dialog))
qtbot.waitUntil(lambda: not run_dialog.done_button.isHidden(), timeout=100000)
qtbot.mouseClick(run_dialog.done_button, Qt.LeftButton)
qtbot.waitUntil(lambda: run_dialog.is_simulation_done() == True, timeout=100000)


@pytest.mark.usefixtures("use_tmpdir", "set_site_config")
Expand Down
5 changes: 2 additions & 3 deletions tests/ert/ui_tests/gui/test_missing_runpath.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import stat
from contextlib import suppress

from qtpy.QtCore import Qt, QTimer
from qtpy.QtCore import QTimer
from qtpy.QtWidgets import (
QLabel,
)
Expand Down Expand Up @@ -77,7 +77,7 @@ def inner():

QTimer.singleShot(100, handle_message_box(run_dialog))
qtbot.waitUntil(
lambda dialog=run_dialog: not dialog.done_button.isHidden(),
lambda dialog=run_dialog: dialog.is_simulation_done() == True,
timeout=200000,
)
assert (
Expand All @@ -92,7 +92,6 @@ def inner():
QLabel, name="progress_label_text_Failed"
).text()
)
qtbot.mouseClick(run_dialog.done_button, Qt.LeftButton)
finally:
with suppress(FileNotFoundError):
(tmp_path / "simulations/realization-0/iter-0").chmod(0x777)
8 changes: 3 additions & 5 deletions tests/ert/ui_tests/gui/test_restart_ensemble_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def _evaluate(coeffs, x):

# The Run dialog opens, wait until restart appears and the tab is ready
run_dialog = wait_for_child(gui, qtbot, RunDialog)
qtbot.waitUntil(lambda: not run_dialog.restart_button.isHidden(), timeout=60000)
qtbot.waitUntil(lambda: run_dialog.is_simulation_done() == True, timeout=60000)
qtbot.waitUntil(lambda: run_dialog._tab_widget.currentWidget() is not None)

# Assert that the number of boxes in the detailed view is
Expand Down Expand Up @@ -108,7 +108,7 @@ def handle_dialog():
write_poly_eval(failing_reals=failing_reals_second_try)
qtbot.mouseClick(run_dialog.restart_button, Qt.MouseButton.LeftButton)

qtbot.waitUntil(lambda: not run_dialog.restart_button.isHidden(), timeout=60000)
qtbot.waitUntil(lambda: run_dialog.is_simulation_done() == True, timeout=60000)
qtbot.waitUntil(lambda: run_dialog._tab_widget.currentWidget() is not None)

# We expect to have the same amount of realizations in list_model
Expand Down Expand Up @@ -139,7 +139,7 @@ def handle_dialog():
write_poly_eval(failing_reals=failing_reals_third_try)
qtbot.mouseClick(run_dialog.restart_button, Qt.MouseButton.LeftButton)

qtbot.waitUntil(lambda: not run_dialog.done_button.isHidden(), timeout=60000)
qtbot.waitUntil(lambda: run_dialog.is_simulation_done() == True, timeout=60000)
qtbot.waitUntil(lambda: run_dialog._tab_widget.currentWidget() is not None)

# We expect to have the same amount of realizations in list_model
Expand All @@ -151,5 +151,3 @@ def handle_dialog():
assert (
list_model.rowCount() == experiment_panel.config.model_config.num_realizations
)

qtbot.mouseClick(run_dialog.done_button, Qt.MouseButton.LeftButton)
8 changes: 2 additions & 6 deletions tests/ert/ui_tests/gui/test_restart_esmda.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,12 @@ def test_restart_esmda(ensemble_experiment_has_run_no_failure, qtbot):
qtbot.mouseClick(run_experiment, Qt.MouseButton.LeftButton)
qtbot.waitUntil(lambda: gui.findChild(RunDialog) is not None)
run_dialog = gui.findChild(RunDialog)
qtbot.waitUntil(lambda: not run_dialog.done_button.isHidden(), timeout=60000)
qtbot.waitUntil(lambda: run_dialog.is_simulation_done() == True, timeout=60000)
assert (
run_dialog._total_progress_label.text()
== "Total progress 100% — Experiment completed."
)

qtbot.mouseClick(run_dialog.done_button, Qt.MouseButton.LeftButton)


def test_custom_weights_stored_and_retrieved_from_metadata_esmda(
opened_main_window_minimal_realizations, qtbot
Expand Down Expand Up @@ -71,14 +69,12 @@ def test_custom_weights_stored_and_retrieved_from_metadata_esmda(
qtbot.mouseClick(run_experiment, Qt.MouseButton.LeftButton)
qtbot.waitUntil(lambda: gui.findChild(RunDialog) is not None, timeout=5000)
run_dialog = gui.findChild(RunDialog)
qtbot.waitUntil(lambda: not run_dialog.done_button.isHidden(), timeout=20000)
qtbot.waitUntil(lambda: run_dialog.is_simulation_done() == True, timeout=20000)
assert (
run_dialog._total_progress_label.text()
== "Total progress 100% — Experiment completed."
)
qtbot.mouseClick(run_dialog.done_button, Qt.MouseButton.LeftButton)
assert wsb.text() == default_weights

restart_checkbox = es_mda_panel.findChild(QCheckBox, name="restart_checkbox_esmda")
assert restart_checkbox
assert not restart_checkbox.isChecked()
Expand Down
4 changes: 1 addition & 3 deletions tests/ert/ui_tests/gui/test_single_test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@ def test_single_test_run_after_ensemble_experiment(

run_experiment = get_child(experiment_panel, QWidget, name="run_experiment")
qtbot.mouseClick(run_experiment, Qt.LeftButton)
# The Run dialog opens, wait until done appears, then click done
run_dialog = wait_for_child(gui, qtbot, RunDialog)
qtbot.waitUntil(lambda: not run_dialog.done_button.isHidden(), timeout=100000)
qtbot.waitUntil(lambda: run_dialog.is_simulation_done() == True, timeout=100000)
qtbot.waitUntil(lambda: run_dialog._tab_widget.currentWidget() is not None)
qtbot.mouseClick(run_dialog.done_button, Qt.LeftButton)

storage = gui.notifier.storage
assert "single_test_run" in [exp.name for exp in storage.experiments]
Expand Down
17 changes: 8 additions & 9 deletions tests/ert/unit_tests/gui/simulation/test_run_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def test_run_dialog_polls_run_model_for_runtime(
lambda: run_model.get_runtime.called, timeout=run_dialog._RUN_TIME_POLL_RATE * 2
)
event_queue.put(EndEvent(failed=False, msg=""))
qtbot.waitUntil(lambda: not run_dialog.done_button.isHidden())
qtbot.waitUntil(lambda: run_dialog.is_simulation_done() == True)
run_dialog.close()


Expand Down Expand Up @@ -148,7 +148,7 @@ def test_large_snapshot(
lambda: run_dialog._tab_widget.count() == 2, timeout=timeout_per_iter
)
qtbot.waitUntil(
lambda: not run_dialog.done_button.isHidden(), timeout=timeout_per_iter
lambda: run_dialog.is_simulation_done() == True, timeout=timeout_per_iter
)


Expand Down Expand Up @@ -354,7 +354,7 @@ def test_run_dialog(events, tab_widget_count, qtbot: QtBot, run_dialog, event_qu
qtbot.waitUntil(
lambda: run_dialog._tab_widget.count() == tab_widget_count, timeout=5000
)
qtbot.waitUntil(lambda: not run_dialog.done_button.isHidden(), timeout=5000)
qtbot.waitUntil(lambda: run_dialog.is_simulation_done() == True, timeout=5000)


@pytest.mark.parametrize(
Expand Down Expand Up @@ -436,7 +436,7 @@ def test_run_dialog_memory_usage_showing(
qtbot.waitUntil(
lambda: run_dialog._tab_widget.count() == tab_widget_count, timeout=5000
)
qtbot.waitUntil(lambda: not run_dialog.done_button.isHidden(), timeout=5000)
qtbot.waitUntil(lambda: run_dialog.is_simulation_done() == True, timeout=5000)

# This is the container of realization boxes
realization_box = run_dialog._tab_widget.widget(0)
Expand Down Expand Up @@ -529,7 +529,7 @@ def test_run_dialog_fm_label_show_correct_info(
qtbot.waitUntil(
lambda: run_dialog._tab_widget.count() == tab_widget_count, timeout=5000
)
qtbot.waitUntil(lambda: not run_dialog.done_button.isHidden(), timeout=5000)
qtbot.waitUntil(lambda: run_dialog.is_simulation_done() == True, timeout=5000)

# This is the container of realization boxes
realization_box = run_dialog._tab_widget.widget(0)
Expand Down Expand Up @@ -586,7 +586,7 @@ def handle_error_dialog(run_dialog):
run_dialog = wait_for_child(gui, qtbot, RunDialog)

QTimer.singleShot(100, lambda: handle_error_dialog(run_dialog))
qtbot.waitUntil(lambda: not run_dialog.done_button.isHidden(), timeout=100000)
qtbot.waitUntil(lambda: run_dialog.is_simulation_done() == True, timeout=100000)
run_dialog.close()


Expand Down Expand Up @@ -614,7 +614,7 @@ def test_that_debug_info_button_provides_data_in_clipboard(qtbot: QtBot, storage
qtbot.mouseClick(run_experiment, Qt.LeftButton)
qtbot.waitUntil(lambda: gui.findChild(RunDialog) is not None, timeout=5000)
run_dialog = gui.findChild(RunDialog)
qtbot.waitUntil(lambda: not run_dialog.done_button.isHidden(), timeout=10000)
qtbot.waitUntil(lambda: run_dialog.is_simulation_done() == True, timeout=10000)

copy_debug_info_button = gui.findChild(QPushButton, "copy_debug_info_button")
assert copy_debug_info_button
Expand All @@ -625,7 +625,6 @@ def test_that_debug_info_button_provides_data_in_clipboard(qtbot: QtBot, storage

for keyword in ["Single realization test-run", "Local", r"minimal\_config.ert"]:
assert keyword in clipboard_text
qtbot.mouseClick(run_dialog.done_button, Qt.LeftButton)


@pytest.mark.integration_test
Expand Down Expand Up @@ -660,7 +659,7 @@ def test_that_stdout_and_stderr_buttons_react_to_file_content(
qtbot.waitUntil(lambda: gui.findChild(RunDialog) is not None, timeout=5000)
run_dialog = gui.findChild(RunDialog)

qtbot.waitUntil(lambda: not run_dialog.done_button.isHidden(), timeout=100000)
qtbot.waitUntil(lambda: run_dialog.is_simulation_done() == True, timeout=100000)

fm_step_overview = run_dialog._fm_step_overview
qtbot.waitUntil(lambda: not fm_step_overview.isHidden(), timeout=20000)
Expand Down
12 changes: 3 additions & 9 deletions tests/ert/unit_tests/gui/simulation/test_run_path_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,8 @@ def test_run_path_deleted_error(

qtbot.waitUntil(lambda: gui.findChild(RunDialog) is not None)
run_dialog = gui.findChild(RunDialog)
qtbot.waitUntil(lambda: not run_dialog.done_button.isHidden(), timeout=100000)
qtbot.waitUntil(lambda: run_dialog.is_simulation_done() == True, timeout=100000)
qtbot.waitUntil(lambda: run_dialog._tab_widget.currentWidget() is not None)
qtbot.mouseClick(run_dialog.done_button, Qt.LeftButton)

assert os.path.exists(run_path / dummy_file.name)


Expand Down Expand Up @@ -138,10 +136,8 @@ def test_run_path_is_deleted(snake_oil_case_storage: ErtConfig, qtbot: QtBot):

qtbot.waitUntil(lambda: gui.findChild(RunDialog) is not None)
run_dialog = gui.findChild(RunDialog)
qtbot.waitUntil(lambda: not run_dialog.done_button.isHidden(), timeout=100000)
qtbot.waitUntil(lambda: run_dialog.is_simulation_done() == True, timeout=100000)
qtbot.waitUntil(lambda: run_dialog._tab_widget.currentWidget() is not None)
qtbot.mouseClick(run_dialog.done_button, Qt.LeftButton)

assert not os.path.exists(run_path / dummy_file.name)


Expand Down Expand Up @@ -182,8 +178,6 @@ def test_run_path_is_not_deleted(snake_oil_case_storage: ErtConfig, qtbot: QtBot

qtbot.waitUntil(lambda: gui.findChild(RunDialog) is not None, timeout=10000)
run_dialog = gui.findChild(RunDialog)
qtbot.waitUntil(lambda: not run_dialog.done_button.isHidden(), timeout=100000)
qtbot.waitUntil(lambda: run_dialog.is_simulation_done() == True, timeout=100000)
qtbot.waitUntil(lambda: run_dialog._tab_widget.currentWidget() is not None)
qtbot.mouseClick(run_dialog.done_button, Qt.LeftButton)

assert os.path.exists(run_path / dummy_file.name)

0 comments on commit 21203bb

Please sign in to comment.