Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dilpath committed Dec 3, 2024
1 parent 74fed0b commit 8e799eb
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
1 change: 0 additions & 1 deletion petab_select/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ def __getitem__(
case ModelHash() | str():
return self._models[self._hashes.index(key)]
case slice():
print(key)
return self.__class__(self._models[key])
case Iterable():
# TODO sensible to yield here?
Expand Down
10 changes: 7 additions & 3 deletions petab_select/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import numpy as np
import petab.v1 as petab

from . import analyze
from .candidate_space import CandidateSpace, FamosCandidateSpace
from .constants import (
CANDIDATE_SPACE,
Expand Down Expand Up @@ -159,9 +160,10 @@ def start_iteration(
# by calling ui.best to find the best model to jump to if
# this is not the first step of the search.
if candidate_space.latest_iteration_calibrated_models:
predecessor_model = problem.get_best(
candidate_space.latest_iteration_calibrated_models,
predecessor_model = analyze.get_best(
models=candidate_space.latest_iteration_calibrated_models,
criterion=criterion,
compare=problem.compare,
)
# If the new predecessor model isn't better than the previous one,
# keep the previous one.
Expand Down Expand Up @@ -352,7 +354,9 @@ def get_best(
The best model.
"""
# TODO return list, when multiple models are equally "best"
return problem.get_best(models=models, criterion=criterion)
return analyze.get_best(
models=models, criterion=criterion, compare=problem.compare
)


def write_summary_tsv(
Expand Down
9 changes: 4 additions & 5 deletions test/candidate_space/test_famos.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from more_itertools import one

import petab_select
from petab_select import Method
from petab_select import Method, Models
from petab_select.constants import (
CANDIDATE_SPACE,
MODEL_HASH,
Expand Down Expand Up @@ -126,8 +126,7 @@ def parse_summary_to_progress_list(summary_tsv: str) -> tuple[Method, set]:
return progress_list

progress_list = []
all_calibrated_models = {}
calibrated_models = {}
all_calibrated_models = Models()

candidate_space = petab_select_problem.new_candidate_space()
candidate_space.summary_tsv.unlink(missing_ok=True)
Expand All @@ -145,7 +144,7 @@ def parse_summary_to_progress_list(summary_tsv: str) -> tuple[Method, set]:
)

# Calibrate candidate models
calibrated_models = {}
calibrated_models = Models()
for candidate_model in iteration[UNCALIBRATED_MODELS]:
calibrate(candidate_model)
calibrated_models[candidate_model.get_hash()] = candidate_model
Expand All @@ -155,7 +154,7 @@ def parse_summary_to_progress_list(summary_tsv: str) -> tuple[Method, set]:
candidate_space=iteration[CANDIDATE_SPACE],
calibrated_models=calibrated_models,
)
all_calibrated_models.update(iteration_results[MODELS])
all_calibrated_models += iteration_results[MODELS]
candidate_space = iteration_results[CANDIDATE_SPACE]

# Stop iteration if there are no candidate models
Expand Down
10 changes: 10 additions & 0 deletions test/cli/input/models.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
- criteria: {}
model_id: model_1
model_subspace_id: M
model_subspace_indices:
- 0
- 1
- 1
parameters:
k1: 0.2
k2: estimate
Expand All @@ -10,6 +15,11 @@
petab_yaml: ../../../doc/examples/model_selection/petab_problem.yaml
- criteria: {}
model_id: model_2
model_subspace_id: M
model_subspace_indices:
- 1
- 1
- 0
parameters:
k1: estimate
k2: estimate
Expand Down

0 comments on commit 8e799eb

Please sign in to comment.