Skip to content

Commit

Permalink
Remove concept indeterminate
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas-el committed Jun 13, 2024
1 parent 55d56ee commit 091a179
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 75 deletions.
4 changes: 0 additions & 4 deletions src/ert/cli/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,6 @@ def _print_result(self, failed: bool, failed_message: Optional[str]) -> None:
)

def _print_progress(self, event: SnapshotUpdateEvent) -> None:
if event.indeterminate:
# indeterminate, no progress to be shown
return

current_phase = min(event.total_phases, event.current_phase + 1)
if self._start_time is not None:
elapsed = datetime.now() - self._start_time
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 @@ -10,7 +10,6 @@ class _UpdateEvent:
current_phase: int
total_phases: int
progress: float
indeterminate: bool
iteration: int


Expand Down
21 changes: 5 additions & 16 deletions src/ert/gui/simulation/run_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,7 @@
from ert.gui.ertwidgets.message_box import ErtMessageBox
from ert.gui.model.job_list import JobListProxyModel
from ert.gui.model.progress_proxy import ProgressProxyModel
from ert.gui.model.snapshot import (
COLUMNS,
FileRole,
IterNum,
RealIens,
SnapshotModel,
)
from ert.gui.model.snapshot import COLUMNS, FileRole, IterNum, RealIens, SnapshotModel
from ert.gui.tools.file import FileDialog
from ert.gui.tools.plot.plot_tool import PlotTool
from ert.run_models import (
Expand Down Expand Up @@ -112,7 +106,7 @@ def __init__(

self._progress_view = ProgressView(self)
self._progress_view.setModel(progress_proxy_model)
self._progress_view.setIndeterminate(True)
self._progress_view.set_active_progress(False)

legend_view = LegendView(self)
legend_view.setModel(progress_proxy_model)
Expand Down Expand Up @@ -356,12 +350,7 @@ def _on_simulation_done(self, failed, failed_msg):
self.kill_button.setHidden(True)
self.restart_button.setVisible(self._run_model.has_failed_realizations())
self.restart_button.setEnabled(self._run_model.support_restart)
self._total_progress_bar.setValue(100)
self._total_progress_label.setText(
_TOTAL_PROGRESS_TEMPLATE.format(
total_progress=100, phase_name=self._run_model.getPhaseName()
)
)
self.update_total_progress(1.0, self._run_model.getPhaseName())
self._notifier.set_is_simulation_running(False)
if failed:
self.fail_msg_box = ErtMessageBox(
Expand Down Expand Up @@ -393,14 +382,14 @@ def _on_event(self, event: object):
elif isinstance(event, FullSnapshotEvent):
if event.snapshot is not None:
self._snapshot_model._add_snapshot(event.snapshot, event.iteration)
self._progress_view.setIndeterminate(event.indeterminate)
self._progress_view.set_active_progress()
self.update_total_progress(event.progress, event.phase_name)
elif isinstance(event, SnapshotUpdateEvent):
if event.partial_snapshot is not None:
self._snapshot_model._add_partial_snapshot(
event.partial_snapshot, event.iteration
)
self._progress_view.setIndeterminate(event.indeterminate)
self._progress_view.set_active_progress()
self.update_total_progress(event.progress, event.phase_name)
elif isinstance(event, RunModelUpdateBeginEvent):
iteration = event.iteration
Expand Down
9 changes: 4 additions & 5 deletions src/ert/gui/simulation/view/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import math

from qtpy.QtCore import QModelIndex, QSize, Qt, Slot
from qtpy.QtCore import QModelIndex, QSize, Qt
from qtpy.QtGui import QColor, QPainter
from qtpy.QtWidgets import (
QProgressBar,
Expand Down Expand Up @@ -45,10 +45,9 @@ def __init__(self, parent=None) -> None:
def setModel(self, model) -> None:
self._progress_tree_view.setModel(model)

@Slot(bool)
def setIndeterminate(self, enable: bool) -> None:
self._progress_bar.setVisible(enable)
self._progress_tree_view.setVisible(not enable)
def set_active_progress(self, enable: bool = True) -> None:
self._progress_bar.setVisible(not enable)
self._progress_tree_view.setVisible(enable)


class ProgressDelegate(QStyledItemDelegate):
Expand Down
30 changes: 7 additions & 23 deletions src/ert/run_models/base_run_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ def __init__(

self.start_time: Optional[int] = None
self.stop_time: Optional[int] = None
self._indeterminate: bool = False
self._failed: bool = False
self._exception: Optional[Exception] = None
self._error_messages: MutableSequence[str] = []
Expand Down Expand Up @@ -356,19 +355,12 @@ def setPhaseCount(self, phase_count: int) -> None:
def currentPhase(self) -> int:
return self._phase

def setPhaseName(
self, phase_name: str, indeterminate: Optional[bool] = None
) -> None:
def setPhaseName(self, phase_name: str) -> None:
self._phase_name = phase_name
self.setIndeterminate(indeterminate)

def getPhaseName(self) -> str:
return self._phase_name

def setIndeterminate(self, indeterminate: Optional[bool]) -> None:
if indeterminate is not None:
self._indeterminate = indeterminate

def isFinished(self) -> bool:
return self._phase == self._phase_count or self.hasRunFailed()

Expand All @@ -395,16 +387,13 @@ def _simulationEnded(self) -> None:
self.stop_time = int(time.time())
self.send_end_event()

def setPhase(
self, phase: int, phase_name: str, indeterminate: Optional[bool] = None
) -> None:
self.setPhaseName(phase_name)
def setPhase(self, phase: int, phase_name: str) -> None:
if not 0 <= phase <= self._phase_count:
raise ValueError(
f"Phase must be integer between (inclusive) 0 and {self._phase_count}"
)

self.setIndeterminate(indeterminate)
self.setPhaseName(phase_name)

if phase == self._phase_count:
self._simulationEnded()
Expand All @@ -418,9 +407,6 @@ def get_runtime(self) -> Union[int, float]:
return time.time() - self.start_time
return self.stop_time - self.start_time

def isIndeterminate(self) -> bool:
return not self.isFinished() and self._indeterminate

@staticmethod
def checkHaveSufficientRealizations(
num_successful_realizations: int, minimum_realizations: int
Expand Down Expand Up @@ -482,7 +468,6 @@ def send_snapshot_event(self, event: CloudEvent) -> None:
phase_name=self.getPhaseName(),
current_phase=self.currentPhase(),
total_phases=self.phaseCount(),
indeterminate=self.isIndeterminate(),
progress=self._progress(),
iteration=iter_,
snapshot=copy.deepcopy(snapshot),
Expand All @@ -502,7 +487,6 @@ def send_snapshot_event(self, event: CloudEvent) -> None:
phase_name=self.getPhaseName(),
current_phase=self.currentPhase(),
total_phases=self.phaseCount(),
indeterminate=self.isIndeterminate(),
progress=self._progress(),
iteration=iter_,
partial_snapshot=partial,
Expand Down Expand Up @@ -660,17 +644,17 @@ def _evaluate_and_postprocess(
iteration = run_context.iteration

phase_string = f"Running simulation for iteration: {iteration}"
self.setPhase(iteration, phase_string, indeterminate=False)
self.setPhase(iteration, phase_string)
create_run_path(run_context, self.ert_config)

phase_string = f"Pre processing for iteration: {iteration}"
self.setPhaseName(phase_string, indeterminate=True)
self.setPhaseName(phase_string)
self.ert.runWorkflows(
HookRuntime.PRE_SIMULATION, self._storage, run_context.ensemble
)

phase_string = f"Running forecast for iteration: {iteration}"
self.setPhaseName(phase_string, indeterminate=False)
self.setPhaseName(phase_string)

successful_realizations = self.run_ensemble_evaluator(
run_context, evaluator_server_config
Expand Down Expand Up @@ -706,7 +690,7 @@ def _evaluate_and_postprocess(
event_logger.info(f"Experiment run finished in: {self.get_runtime()}s")

phase_string = f"Post processing for iteration: {iteration}"
self.setPhaseName(phase_string, indeterminate=True)
self.setPhaseName(phase_string)
self.ert.runWorkflows(
HookRuntime.POST_SIMULATION, self._storage, run_context.ensemble
)
Expand Down
2 changes: 1 addition & 1 deletion src/ert/run_models/ensemble_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def run_experiment(
self,
evaluator_server_config: EvaluatorServerConfig,
) -> RunContext:
self.setPhaseName(self.run_message(), indeterminate=False)
self.setPhaseName(self.run_message())
experiment = self._storage.create_experiment(
name=self.simulation_arguments.experiment_name,
parameters=self.ert_config.ensemble_config.parameter_configuration,
Expand Down
2 changes: 1 addition & 1 deletion src/ert/run_models/ensemble_smoother.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def run_experiment(

log_msg = "Running ES"
logger.info(log_msg)
self.setPhaseName(log_msg, indeterminate=True)
self.setPhaseName(log_msg)
experiment = self._storage.create_experiment(
parameters=self.ert_config.ensemble_config.parameter_configuration,
observations=self.ert_config.observations.datasets,
Expand Down
2 changes: 1 addition & 1 deletion src/ert/run_models/evaluate_ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def run_experiment(
self,
evaluator_server_config: EvaluatorServerConfig,
) -> RunContext:
self.setPhaseName("Running evaluate experiment...", indeterminate=False)
self.setPhaseName("Running evaluate experiment...")

ensemble_id = self.simulation_arguments.current_ensemble
ensemble_uuid = UUID(ensemble_id)
Expand Down
8 changes: 3 additions & 5 deletions src/ert/run_models/iterated_ensemble_smoother.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ def analyzeStep(
iteration: int,
initial_mask: npt.NDArray[np.bool_],
) -> None:
self.setPhaseName("Analyzing...", indeterminate=True)

self.setPhaseName("Pre processing update...", indeterminate=True)
self.setPhaseName("Pre processing update...")
self.ert.runWorkflows(HookRuntime.PRE_UPDATE, self._storage, prior_storage)
try:
smoother_snapshot, self.sies_smoother = iterative_smoother_update(
Expand All @@ -107,7 +105,7 @@ def analyzeStep(
f"Update algorithm failed with the following error: {e}"
) from e

self.setPhaseName("Post processing update...", indeterminate=True)
self.setPhaseName("Post processing update...")
self.ert.runWorkflows(HookRuntime.POST_UPDATE, self._storage, posterior_storage)

def run_experiment(
Expand All @@ -126,7 +124,7 @@ def run_experiment(
f'iteration{"s" if (iteration_count != 1) else ""}.'
)
logger.info(log_msg)
self.setPhaseName(log_msg, indeterminate=True)
self.setPhaseName(log_msg)

target_ensemble_format = self._simulation_arguments.target_ensemble
experiment = self._storage.create_experiment(
Expand Down
6 changes: 3 additions & 3 deletions src/ert/run_models/multiple_data_assimilation.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def run_experiment(

log_msg = f"Running ES-MDA with normalized weights {weights}"
logger.info(log_msg)
self.setPhaseName(log_msg, indeterminate=True)
self.setPhaseName(log_msg)

restart_run = self._simulation_arguments.restart_run
target_ensemble_format = self._simulation_arguments.target_ensemble
Expand Down Expand Up @@ -189,7 +189,7 @@ def run_experiment(
self._evaluate_and_postprocess(posterior_context, evaluator_server_config)
prior_context = posterior_context

self.setPhaseName("Post processing...", indeterminate=True)
self.setPhaseName("Post processing...")

self.setPhase(iteration_count + 1, "Experiment completed.")

Expand All @@ -204,7 +204,7 @@ def update(
next_iteration = prior_context.iteration + 1

phase_string = f"Analyzing iteration: {next_iteration} with weight {weight}"
self.setPhase(self.currentPhase() + 1, phase_string, indeterminate=True)
self.setPhase(self.currentPhase() + 1, phase_string)
try:
return smoother_update(
prior_context.ensemble,
Expand Down
1 change: 0 additions & 1 deletion tests/unit_tests/cli/test_cli_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ def test_print_progress():
current_phase=0,
total_phases=2,
progress=0.5,
indeterminate=False,
iteration=0,
)

Expand Down
Loading

0 comments on commit 091a179

Please sign in to comment.