diff --git a/src/ert/cli/monitor.py b/src/ert/cli/monitor.py index 89831e1079b..921b584f222 100644 --- a/src/ert/cli/monitor.py +++ b/src/ert/cli/monitor.py @@ -136,7 +136,7 @@ def _print_result(self, failed: bool, failed_message: str | None) -> None: ) def _print_progress(self, event: SnapshotUpdateEvent) -> None: - current_iteration = min(event.total_iterations, event.current_iteration + 1) + current_iteration = min(event.total_iterations, event.iteration + 1) if self._start_time is not None: elapsed = datetime.now() - self._start_time else: diff --git a/src/ert/ensemble_evaluator/event.py b/src/ert/ensemble_evaluator/event.py index 856557968f3..5639269fd6f 100644 --- a/src/ert/ensemble_evaluator/event.py +++ b/src/ert/ensemble_evaluator/event.py @@ -6,7 +6,6 @@ @dataclass class _UpdateEvent: iteration_label: str - current_iteration: int total_iterations: int progress: float realization_count: int diff --git a/src/ert/gui/simulation/run_dialog.py b/src/ert/gui/simulation/run_dialog.py index 82e76aa0295..b01fc33fe37 100644 --- a/src/ert/gui/simulation/run_dialog.py +++ b/src/ert/gui/simulation/run_dialog.py @@ -296,6 +296,9 @@ def is_simulation_done(self) -> bool: def _current_tab_changed(self, index: int) -> None: widget = self._tab_widget.widget(index) + if isinstance(widget, RealizationWidget): + widget.refresh_current_selection() + self.fm_step_frame.setHidden(isinstance(widget, UpdateWidget)) @Slot(QModelIndex, int, int) diff --git a/src/ert/gui/simulation/view/realization.py b/src/ert/gui/simulation/view/realization.py index 6859829e362..00cd593962d 100644 --- a/src/ert/gui/simulation/view/realization.py +++ b/src/ert/gui/simulation/view/realization.py @@ -81,6 +81,10 @@ def setSnapshotModel(self, model: QAbstractItemModel) -> None: def clearSelection(self) -> None: self._real_view.clearSelection() + def refresh_current_selection(self) -> None: + selected_reals = self._real_view.selectedIndexes() + self._item_clicked(selected_reals[0]) + class RealizationDelegate(QStyledItemDelegate): def __init__(self, size: QSize, parent: QObject) -> None: diff --git a/src/ert/run_models/base_run_model.py b/src/ert/run_models/base_run_model.py index a426c5be7a1..b028e52f68c 100644 --- a/src/ert/run_models/base_run_model.py +++ b/src/ert/run_models/base_run_model.py @@ -462,7 +462,6 @@ def send_snapshot_event(self, event: Event, iteration: int) -> None: self.send_event( FullSnapshotEvent( iteration_label=f"Running forecast for iteration: {iteration}", - current_iteration=iteration, total_iterations=self._total_iterations, progress=current_progress, realization_count=realization_count, @@ -487,7 +486,6 @@ def send_snapshot_event(self, event: Event, iteration: int) -> None: self.send_event( SnapshotUpdateEvent( iteration_label=f"Running forecast for iteration: {iteration}", - current_iteration=iteration, total_iterations=self._total_iterations, progress=current_progress, realization_count=realization_count, diff --git a/tests/ert/unit_tests/cli/test_cli_monitor.py b/tests/ert/unit_tests/cli/test_cli_monitor.py index 0cf175d1059..5ed5cbbccca 100644 --- a/tests/ert/unit_tests/cli/test_cli_monitor.py +++ b/tests/ert/unit_tests/cli/test_cli_monitor.py @@ -77,7 +77,6 @@ def test_print_progress(): monitor._start_time = datetime.now() general_event = SnapshotUpdateEvent( iteration_label="Test Phase", - current_iteration=0, total_iterations=2, progress=0.5, realization_count=100, diff --git a/tests/ert/unit_tests/gui/simulation/test_run_dialog.py b/tests/ert/unit_tests/gui/simulation/test_run_dialog.py index 0287e5ff9c4..61939e09373 100644 --- a/tests/ert/unit_tests/gui/simulation/test_run_dialog.py +++ b/tests/ert/unit_tests/gui/simulation/test_run_dialog.py @@ -119,7 +119,6 @@ def test_large_snapshot( FullSnapshotEvent( snapshot=large_snapshot, iteration_label="Foo", - current_iteration=0, total_iterations=1, progress=0.5, realization_count=4, @@ -129,7 +128,6 @@ def test_large_snapshot( FullSnapshotEvent( snapshot=large_snapshot, iteration_label="Foo", - current_iteration=0, total_iterations=1, progress=0.5, realization_count=4, @@ -172,7 +170,6 @@ def test_large_snapshot( .build(["0"], state.REALIZATION_STATE_UNKNOWN) ), iteration_label="Foo", - current_iteration=0, total_iterations=1, progress=0.25, realization_count=4, @@ -184,7 +181,6 @@ def test_large_snapshot( [], status=state.REALIZATION_STATE_FINISHED ), iteration_label="Foo", - current_iteration=0, total_iterations=1, progress=0.5, realization_count=4, @@ -212,7 +208,6 @@ def test_large_snapshot( .build(["0"], state.REALIZATION_STATE_UNKNOWN) ), iteration_label="Foo", - current_iteration=0, total_iterations=1, progress=0.25, realization_count=4, @@ -224,7 +219,6 @@ def test_large_snapshot( ["0"], status=state.REALIZATION_STATE_FINISHED ), iteration_label="Foo", - current_iteration=0, total_iterations=1, progress=0.5, realization_count=4, @@ -256,7 +250,6 @@ def test_large_snapshot( .build(["0", "1"], state.REALIZATION_STATE_UNKNOWN) ), iteration_label="Foo", - current_iteration=0, total_iterations=1, progress=0.25, realization_count=4, @@ -273,7 +266,6 @@ def test_large_snapshot( ) .build(["1"], status=state.REALIZATION_STATE_RUNNING), iteration_label="Foo", - current_iteration=0, total_iterations=1, progress=0.5, realization_count=4, @@ -290,7 +282,6 @@ def test_large_snapshot( ) .build(["0"], status=state.REALIZATION_STATE_FAILED), iteration_label="Foo", - current_iteration=0, total_iterations=1, progress=0.5, realization_count=4, @@ -316,7 +307,6 @@ def test_large_snapshot( .build(["0"], state.REALIZATION_STATE_UNKNOWN) ), iteration_label="Foo", - current_iteration=0, total_iterations=1, progress=0.25, realization_count=4, @@ -335,7 +325,6 @@ def test_large_snapshot( .build(["0"], state.REALIZATION_STATE_UNKNOWN) ), iteration_label="Foo", - current_iteration=0, total_iterations=1, progress=0.5, realization_count=4, @@ -377,7 +366,6 @@ def test_run_dialog(events, tab_widget_count, qtbot: QtBot, run_dialog, event_qu .build(["0"], state.REALIZATION_STATE_UNKNOWN) ), iteration_label="Foo", - current_iteration=0, total_iterations=1, progress=0.25, realization_count=4, @@ -396,7 +384,6 @@ def test_run_dialog(events, tab_widget_count, qtbot: QtBot, run_dialog, event_qu ) .build(["0"], status=state.REALIZATION_STATE_RUNNING), iteration_label="Foo", - current_iteration=0, total_iterations=1, progress=0.5, realization_count=4, @@ -415,7 +402,6 @@ def test_run_dialog(events, tab_widget_count, qtbot: QtBot, run_dialog, event_qu ) .build(["0"], status=state.REALIZATION_STATE_FINISHED), iteration_label="Foo", - current_iteration=0, total_iterations=1, progress=1, realization_count=4, @@ -486,7 +472,6 @@ def test_run_dialog_memory_usage_showing( ) ), iteration_label="Foo", - current_iteration=0, total_iterations=1, progress=0.25, realization_count=4, @@ -519,7 +504,6 @@ def test_run_dialog_memory_usage_showing( .build(["0", "1"], status=state.REALIZATION_STATE_UNKNOWN) ), iteration_label="Foo", - current_iteration=0, total_iterations=1, progress=0.25, realization_count=4, @@ -778,3 +762,98 @@ def test_that_design_matrix_show_parameters_button_is_visible( assert isinstance(show_dm_parameters, QPushButton) else: assert show_dm_parameters is None + + +@pytest.mark.parametrize( + "events,tab_widget_count", + [ + pytest.param( + [ + FullSnapshotEvent( + snapshot=( + SnapshotBuilder() + .add_fm_step( + fm_step_id="0", + index="0", + name="fm_step_0", + status=state.FORWARD_MODEL_STATE_START, + ) + .build(["0", "1"], state.REALIZATION_STATE_UNKNOWN) + ), + iteration_label="Foo", + total_iterations=1, + progress=0.5, + realization_count=2, + status_count={"Finished": 1, "Pending": 1}, + iteration=0, + ), + FullSnapshotEvent( + snapshot=( + SnapshotBuilder() + .add_fm_step( + fm_step_id="0", + index="0", + name="fm_step_0", + status=state.FORWARD_MODEL_STATE_START, + ) + .build(["0", "1"], state.REALIZATION_STATE_FINISHED) + ), + iteration_label="Foo", + total_iterations=1, + progress=0.5, + realization_count=2, + status_count={"Finished": 1, "Pending": 1}, + iteration=1, + ), + EndEvent(failed=False, msg=""), + ], + 2, + id="changing from between tabs", + ), + ], +) +def test_forward_model_overview_label_selected_on_tab_change( + events, tab_widget_count, qtbot: QtBot, event_queue, run_dialog +): + run_dialog.run_experiment() + for event in events: + event_queue.put(event) + + def qt_bot_click_realization(realization_index: int, iteration: int) -> None: + view = run_dialog._tab_widget.widget(iteration)._real_view + model_index = view.model().index(realization_index, 0) + view.scrollTo(model_index) + rect = view.visualRect(model_index) + click_pos = rect.center() + qtbot.mouseClick(view.viewport(), Qt.LeftButton, pos=click_pos) + + def qt_bot_click_tab_index(tab_index: int) -> None: + tab_bar = run_dialog._tab_widget.tabBar() + tab_rect = tab_bar.tabRect(tab_index) + click_pos = tab_rect.center() + qtbot.mouseClick(tab_bar, Qt.LeftButton, pos=click_pos) + + # verify two tabs present + qtbot.waitUntil( + lambda: run_dialog._tab_widget.count() == tab_widget_count, timeout=5000 + ) + qtbot.waitUntil(lambda: run_dialog.is_simulation_done() == True, timeout=5000) + + qt_bot_click_tab_index(0) + fm_step_label = run_dialog.findChild(QLabel, name="fm_step_label") + assert "Realization id 0 in iteration 0" in fm_step_label.text() + + qt_bot_click_realization(1, 0) + assert "Realization id 1 in iteration 0" in fm_step_label.text() + + qt_bot_click_tab_index(1) + assert "Realization id 0 in iteration 1" in fm_step_label.text() + + qt_bot_click_realization(1, 1) + assert "Realization id 1 in iteration 1" in fm_step_label.text() + + qt_bot_click_tab_index(0) + assert "Realization id 1 in iteration 0" in fm_step_label.text() + + qt_bot_click_tab_index(1) + assert "Realization id 1 in iteration 1" in fm_step_label.text()