Skip to content

Commit 79ee875

Browse files
committed
test
1 parent 3939bf6 commit 79ee875

4 files changed

Lines changed: 86 additions & 5 deletions

File tree

petab/v2/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
models, # noqa: F401, E402
3838
)
3939
from .conditions import * # noqa: F403, F401, E402
40+
from .core import * # noqa: F401, E402
4041
from .experiments import ( # noqa: F401, E402
4142
get_experiment_df,
4243
write_experiment_df,

petab/v2/converters.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ class ExperimentsToEventsConverter:
4040
#: ID of the parameter that indicates whether the model is in
4141
# the pre-equilibration phase (1) or not (0).
4242
PREEQ_INDICATOR = "_petab_preequilibration_indicator"
43+
4344
#: The condition ID of the condition that sets the
4445
#: pre-equilibration indicator to 1.
4546
CONDITION_ID_PREEQ_ON = "_petab_preequilibration_on"
47+
4648
#: The condition ID of the condition that sets the
4749
#: pre-equilibration indicator to 0.
4850
CONDITION_ID_PREEQ_OFF = "_petab_preequilibration_off"
@@ -69,7 +71,7 @@ def __init__(self, problem: Problem, default_priority: float = None):
6971
self._original_problem = problem
7072
self._new_problem = deepcopy(self._original_problem)
7173

72-
self._model = self._new_problem.model.sbml_model
74+
self._model: libsbml.Model = self._new_problem.model.sbml_model
7375
self._preeq_indicator = self.PREEQ_INDICATOR
7476

7577
# The maximum event priority that was found in the unprocessed model.
@@ -85,7 +87,7 @@ def _get_experiment_indicator_condition_id(
8587
"""Get the condition ID for the experiment indicator parameter."""
8688
return f"_petab_experiment_condition_{experiment_id}"
8789

88-
def _preprocess(self):
90+
def _preprocess(self) -> None:
8991
"""Check whether we can handle the given problem and store some model
9092
information."""
9193
model = self._model
@@ -184,7 +186,7 @@ def convert(self) -> Problem:
184186

185187
return self._new_problem
186188

187-
def _convert_experiment(self, experiment: Experiment):
189+
def _convert_experiment(self, experiment: Experiment) -> None:
188190
"""Convert a single experiment to SBML events."""
189191
model = self._model
190192
experiment.sort_periods()
@@ -323,7 +325,9 @@ def _create_event_assignments_for_period(
323325
)
324326

325327
@staticmethod
326-
def _change_to_event_assignment(change: Change, event: libsbml.Event):
328+
def _change_to_event_assignment(
329+
change: Change, event: libsbml.Event
330+
) -> None:
327331
"""Convert a PEtab ``Change`` to an SBML event assignment."""
328332
sbml_model = event.getModel()
329333

petab/v2/problem.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ def validate(
838838
)
839839

840840
validation_results = ValidationResultList()
841-
if self.config.extensions:
841+
if self.config and self.config.extensions:
842842
extensions = ",".join(self.config.extensions.keys())
843843
validation_results.append(
844844
ValidationIssue(

tests/v2/test_converters.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
from math import inf
2+
3+
from petab.v2 import Change, Condition, Experiment, ExperimentPeriod, Problem
4+
from petab.v2.converters import ExperimentsToEventsConverter
5+
from petab.v2.models.sbml_model import SbmlModel
6+
7+
8+
def test_experiments_to_events_converter():
9+
"""Test the ExperimentsToEventsConverter."""
10+
ant_model = """
11+
species X = 0
12+
X' = 1
13+
"""
14+
problem = Problem()
15+
problem.model = SbmlModel.from_antimony(ant_model)
16+
problem.add_condition("c1", X=1)
17+
problem.add_condition("c2", X=2)
18+
problem.add_experiment("e1", -inf, "c1", 10, "c2")
19+
20+
converter = ExperimentsToEventsConverter(problem)
21+
converted = converter.convert()
22+
assert converted.validate().has_errors() is False
23+
24+
assert isinstance(converted.model, SbmlModel)
25+
sbml_model = converted.model.sbml_model
26+
27+
assert sbml_model.getNumEvents() == 2
28+
assert converted.condition_table.conditions == [
29+
Condition(
30+
id="_petab_preequilibration_on",
31+
changes=[
32+
Change(
33+
target_id="_petab_preequilibration_indicator",
34+
target_value=1,
35+
)
36+
],
37+
),
38+
Condition(
39+
id="_petab_preequilibration_off",
40+
changes=[
41+
Change(
42+
target_id="_petab_preequilibration_indicator",
43+
target_value=0,
44+
)
45+
],
46+
),
47+
Condition(
48+
id="_petab_experiment_condition_e1",
49+
changes=[
50+
Change(
51+
target_id="_petab_experiment_indicator_e1", target_value=1
52+
)
53+
],
54+
),
55+
]
56+
assert converted.experiment_table.experiments == [
57+
Experiment(
58+
id="e1",
59+
periods=[
60+
ExperimentPeriod(
61+
time=-inf,
62+
condition_ids=[
63+
"_petab_experiment_condition_e1",
64+
"_petab_preequilibration_on",
65+
],
66+
),
67+
ExperimentPeriod(
68+
time=10.0,
69+
condition_ids=[
70+
"_petab_experiment_condition_e1",
71+
"_petab_preequilibration_off",
72+
],
73+
),
74+
],
75+
),
76+
]

0 commit comments

Comments
 (0)