diff --git a/src/ert/gui/tools/load_results/load_results_panel.py b/src/ert/gui/tools/load_results/load_results_panel.py index 04e6313acd2..077244386a0 100644 --- a/src/ert/gui/tools/load_results/load_results_panel.py +++ b/src/ert/gui/tools/load_results/load_results_panel.py @@ -1,5 +1,7 @@ from __future__ import annotations +from pathlib import Path + from qtpy.QtCore import Qt, Signal from qtpy.QtWidgets import QFormLayout, QMessageBox, QTextEdit, QWidget @@ -63,7 +65,8 @@ def __init__(self, facade: LibresFacade, notifier: ErtNotifier): self._iterations_model, # type: ignore "load_results_manually/iterations", ) - self._iterations_field.setValidator(IntegerArgument(from_value=0)) + + self._iterations_field.setValidator(self._iter_validator) self._iterations_field.setObjectName("iterations_field_lrm") layout.addRow("Iteration to load:", self._iterations_field) @@ -76,6 +79,14 @@ def __init__(self, facade: LibresFacade, notifier: ErtNotifier): self.setLayout(layout) + @property + def _iter_validator(self) -> IntegerArgument: + cur_run_path = self.readCurrentRunPath().replace("", "0") + curent_iter = 0 + while Path(cur_run_path.replace("", str(curent_iter))).exists(): + curent_iter += 1 + return IntegerArgument(from_value=0, to_value=curent_iter - 1) + def readCurrentRunPath(self) -> str: current_ensemble = self._notifier.current_ensemble_name run_path = self._facade.run_path diff --git a/src/ert/libres_facade.py b/src/ert/libres_facade.py index a3be07222e3..56555a57aa4 100644 --- a/src/ert/libres_facade.py +++ b/src/ert/libres_facade.py @@ -145,6 +145,7 @@ def load_from_forward_model( ), realisations, ensemble=ensemble, + iteration=iteration, ) nr_loaded = self._load_from_run_path( self.config.model_config.num_realizations, diff --git a/src/ert/run_arg.py b/src/ert/run_arg.py index 9116b263bcc..fa38b5d7d5d 100644 --- a/src/ert/run_arg.py +++ b/src/ert/run_arg.py @@ -29,8 +29,10 @@ def create_run_arguments( runpaths: Runpaths, active_realizations: Union[List[bool], npt.NDArray[np.bool_]], ensemble: Ensemble, + iteration: Optional[int] = None, ) -> List[RunArg]: - iteration = ensemble.iteration + if iteration is None: + iteration = ensemble.iteration run_args = [] runpaths.set_ert_ensemble(ensemble.name) paths = runpaths.get_paths(range(len(active_realizations)), iteration)