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

Fix mismatch between selected iteration and visually indicated realization selected #9547

Merged
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
2 changes: 1 addition & 1 deletion src/ert/cli/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion src/ert/ensemble_evaluator/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
@dataclass
class _UpdateEvent:
iteration_label: str
current_iteration: int
total_iterations: int
progress: float
realization_count: int
Expand Down
3 changes: 3 additions & 0 deletions src/ert/gui/simulation/run_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions src/ert/gui/simulation/view/realization.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 0 additions & 2 deletions src/ert/run_models/base_run_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
1 change: 0 additions & 1 deletion tests/ert/unit_tests/cli/test_cli_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
111 changes: 95 additions & 16 deletions tests/ert/unit_tests/gui/simulation/test_run_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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()
Loading