diff --git a/doc/examples/example_cli_famos.ipynb b/doc/examples/example_cli_famos.ipynb index a1d32a1..c413cb7 100644 --- a/doc/examples/example_cli_famos.ipynb +++ b/doc/examples/example_cli_famos.ipynb @@ -142,7 +142,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "petab_select/candidate_space.py:1137: RuntimeWarning: Model `model_subspace_1-0001011010010010` has been previously excluded from the candidate space so is skipped here.\n", + "petab_select/petab_select/candidate_space.py:1142: RuntimeWarning: Model `model_subspace_1-0001011010010010` has been previously excluded from the candidate space so is skipped here.\n", " return_value = self.inner_candidate_space.consider(model)\n" ] }, diff --git a/doc/examples/workflow_cli.ipynb b/doc/examples/workflow_cli.ipynb index 6f4cf83..9acf36b 100644 --- a/doc/examples/workflow_cli.ipynb +++ b/doc/examples/workflow_cli.ipynb @@ -817,7 +817,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "id": "d5d03cd6", "metadata": {}, "outputs": [ @@ -825,7 +825,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "output_cli/best_model_petab/problem.yaml\n" + "petab_select/doc/examples/output_cli/best_model_petab/problem.yaml\n" ] } ], diff --git a/doc/examples/workflow_python.ipynb b/doc/examples/workflow_python.ipynb index 170c767..cbc7afb 100644 --- a/doc/examples/workflow_python.ipynb +++ b/doc/examples/workflow_python.ipynb @@ -230,7 +230,7 @@ ], "source": [ "local_best_model = petab_select.ui.get_best(\n", - " problem=select_problem, models=iteration_results[MODELS].values()\n", + " problem=select_problem, models=iteration_results[MODELS]\n", ")\n", "print_model(local_best_model)" ] @@ -322,10 +322,10 @@ " problem=select_problem, candidate_space=iteration_results[CANDIDATE_SPACE]\n", ")\n", "local_best_model = petab_select.ui.get_best(\n", - " problem=select_problem, models=iteration_results[MODELS].values()\n", + " problem=select_problem, models=iteration_results[MODELS]\n", ")\n", "\n", - "for candidate_model in iteration_results[MODELS].values():\n", + "for candidate_model in iteration_results[MODELS]:\n", " if candidate_model.get_hash() == local_best_model.get_hash():\n", " print(BOLD_TEXT + \"BEST MODEL OF CURRENT ITERATION\" + NORMAL_TEXT)\n", " print_model(candidate_model)" @@ -372,10 +372,10 @@ " problem=select_problem, candidate_space=iteration_results[CANDIDATE_SPACE]\n", ")\n", "local_best_model = petab_select.ui.get_best(\n", - " problem=select_problem, models=iteration_results[MODELS].values()\n", + " problem=select_problem, models=iteration_results[MODELS]\n", ")\n", "\n", - "for candidate_model in iteration_results[MODELS].values():\n", + "for candidate_model in iteration_results[MODELS]:\n", " if candidate_model.get_hash() == local_best_model.get_hash():\n", " print(BOLD_TEXT + \"BEST MODEL OF CURRENT ITERATION\" + NORMAL_TEXT)\n", " print_model(candidate_model)" @@ -415,10 +415,10 @@ " problem=select_problem, candidate_space=iteration_results[CANDIDATE_SPACE]\n", ")\n", "local_best_model = petab_select.ui.get_best(\n", - " problem=select_problem, models=iteration_results[MODELS].values()\n", + " problem=select_problem, models=iteration_results[MODELS]\n", ")\n", "\n", - "for candidate_model in iteration_results[MODELS].values():\n", + "for candidate_model in iteration_results[MODELS]:\n", " if candidate_model.get_hash() == local_best_model.get_hash():\n", " print(BOLD_TEXT + \"BEST MODEL OF CURRENT ITERATION\" + NORMAL_TEXT)\n", " print_model(candidate_model)" @@ -501,7 +501,7 @@ "source": [ "best_model = petab_select.ui.get_best(\n", " problem=select_problem,\n", - " models=iteration_results[CANDIDATE_SPACE].calibrated_models.values(),\n", + " models=iteration_results[CANDIDATE_SPACE].calibrated_models,\n", ")\n", "print_model(best_model)" ] diff --git a/petab_select/candidate_space.py b/petab_select/candidate_space.py index b559bbc..8af42c1 100644 --- a/petab_select/candidate_space.py +++ b/petab_select/candidate_space.py @@ -1002,7 +1002,13 @@ def __init__( else: self.most_distant_max_number = 1 - self.best_models = Models() + # TODO update to new `Models` type. Currently problematic because the + # order of `best_models` matters. This would be fine for `Models` to + # handle, except that `Models._update` will use a pre-existing index + # if there is a model with the same hash. FIXME regenerate the expected + # FAMoS models when `best_models` never contains duplicate models... + # Also add a `sort` method to `Models` to sort by criterion. + self.best_models = [] self.best_model_of_current_run = predecessor_model self.jumped_to_most_distant = False diff --git a/petab_select/models.py b/petab_select/models.py index 49359b4..fa0cf57 100644 --- a/petab_select/models.py +++ b/petab_select/models.py @@ -176,7 +176,10 @@ def __setitem__(self, key: ModelIndex, item: ModelLike) -> None: self.append(item) def _update(self, index: int, item: ModelLike) -> None: - """Update the models by adding a new model or overwriting an old model. + """Update the models by adding a new model, with possible replacement. + + If the instance contains a model with a matching hash, that model + will be replaced. Args: index: