Skip to content

Commit

Permalink
Restart experiment will update the shapshot only
Browse files Browse the repository at this point in the history
Fix restart test to expect the total number of realizations when restart happens
Update progress bar info on total number of reals
  • Loading branch information
xjules committed Sep 25, 2024
1 parent 535e314 commit e1ac40c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
17 changes: 14 additions & 3 deletions src/ert/gui/simulation/run_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ def __init__(

self.on_run_model_event.connect(self._on_event)

self._restart = False

def _current_tab_changed(self, index: int) -> None:
widget = self._tab_widget.widget(index)
self.fm_step_frame.setHidden(isinstance(widget, UpdateWidget))
Expand Down Expand Up @@ -348,8 +350,10 @@ def closeEvent(self, a0: Optional[QCloseEvent]) -> None:
a0.ignore()

def run_experiment(self, restart: bool = False) -> None:
self._snapshot_model.reset()
self._tab_widget.clear()
self._restart = restart
if restart is False:
self._snapshot_model.reset()
self._tab_widget.clear()

port_range = None
if self._run_model.queue_system == QueueSystem.LOCAL:
Expand Down Expand Up @@ -431,7 +435,14 @@ def _on_event(self, event: object) -> None:
self.done_button.setHidden(False)
elif isinstance(event, FullSnapshotEvent):
if event.snapshot is not None:
self._snapshot_model._add_snapshot(event.snapshot, str(event.iteration))
if self._restart:
self._snapshot_model._update_snapshot(
event.snapshot, str(event.iteration)
)
else:
self._snapshot_model._add_snapshot(
event.snapshot, str(event.iteration)
)
self.update_total_progress(event.progress, event.iteration_label)
self._progress_widget.update_progress(
event.status_count, event.realization_count
Expand Down
9 changes: 6 additions & 3 deletions src/ert/run_models/base_run_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ def get_current_status(self) -> dict[str, int]:
for real in all_realizations.values():
status[str(real["status"])] += 1

status["Finished"] += self.active_realizations.count(False)
return status

def get_memory_consumption(self) -> int:
Expand All @@ -409,10 +410,10 @@ def get_memory_consumption(self) -> int:

def _current_progress(self) -> tuple[float, int]:
current_iter = max(list(self._iter_snapshot.keys()))
done_realizations = 0
done_realizations = self.active_realizations.count(False)
all_realizations = self._iter_snapshot[current_iter].reals
current_progress = 0.0
realization_count = len(all_realizations)
realization_count = len(self.active_realizations)

if all_realizations:
for real in all_realizations.values():
Expand All @@ -422,7 +423,9 @@ def _current_progress(self) -> tuple[float, int]:
]:
done_realizations += 1

realization_progress = float(done_realizations) / len(all_realizations)
realization_progress = float(done_realizations) / len(
self.active_realizations
)
current_progress = (
(current_iter + realization_progress) / self._total_iterations
if self._total_iterations != 1
Expand Down
16 changes: 10 additions & 6 deletions tests/ert/ui_tests/gui/test_restart_ensemble_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,15 @@ def handle_dialog():
qtbot.waitUntil(run_dialog.restart_button.isVisible, timeout=60000)
qtbot.waitUntil(lambda: run_dialog._tab_widget.currentWidget() is not None)

# Assert that the number of boxes in the detailed view is
# equal to the number of previously failed realizations
# We expect to have the same amount of realizations in list_model
# since we reuse the snapshot_model
realization_widget = run_dialog._tab_widget.currentWidget()
assert isinstance(realization_widget, RealizationWidget)
list_model = realization_widget._real_view.model()
assert list_model
assert list_model.rowCount() == len(failed_realizations)
assert (
list_model.rowCount() == experiment_panel.config.model_config.num_realizations
)

# Second restart
assert any(run_dialog._run_model._create_mask_from_failed_realizations())
Expand All @@ -142,12 +144,14 @@ def handle_dialog():
qtbot.waitUntil(run_dialog.done_button.isVisible, timeout=60000)
qtbot.waitUntil(lambda: run_dialog._tab_widget.currentWidget() is not None)

# Assert that the number of boxes in the detailed view is
# equal to the number of previously failed realizations
# We expect to have the same amount of realizations in list_model
# since we reuse the snapshot_model
realization_widget = run_dialog._tab_widget.currentWidget()
assert isinstance(realization_widget, RealizationWidget)
list_model = realization_widget._real_view.model()
assert list_model
assert list_model.rowCount() == len(failed_realizations)
assert (
list_model.rowCount() == experiment_panel.config.model_config.num_realizations
)

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

0 comments on commit e1ac40c

Please sign in to comment.