diff --git a/petab_select/ui.py b/petab_select/ui.py index 778e363a..4d14ebd3 100644 --- a/petab_select/ui.py +++ b/petab_select/ui.py @@ -1,3 +1,4 @@ +import copy from pathlib import Path from typing import Dict, List, Optional, Union @@ -76,10 +77,29 @@ def candidates( candidate_space.exclude_hashes(calibrated_models) # Set the predecessor model to the previous predecessor model. + predecessor_model = candidate_space.previous_predecessor_model + + # If the predecessor model has not yet been calibrated, then calibrate it. + if ( + predecessor_model.get_criterion( + criterion, + raise_on_failure=False, + ) + is None + ): + candidate_space.models = [copy.deepcopy(predecessor_model)] + # Dummy zero likelihood, which the predecessor model will + # improve on after it's actually calibrated. + predecessor_model.set_criterion(Criterion.LH, 0.0) + return candidate_space + + # Exclude the calibrated predecessor model. + if not candidate_space.excluded(predecessor_model): + candidate_space.exclude(predecessor_model) + # Set the new predecessor_model from the initial model or # by calling ui.best to find the best model to jump to if # this is not the first step of the search. - predecessor_model = candidate_space.previous_predecessor_model if newly_calibrated_models: predecessor_model = problem.get_best( newly_calibrated_models.values(),