Skip to content

Commit 5689168

Browse files
authored
Add test triggered at time-point without measurements (#105)
Unlike the other test cases with non-initial PEtab conditions (`0016` and `0022`), this test case includes a condition that is triggered at a time point without any measurement values. I have confirmed that the output matches what is computed by PEtab.jl. I believe this is important to test because many ODE solver libraries, unless configured otherwise, save model output immediately after an event/callback (e.g., diffrax in Jax). In this test, that behavior is not required, and if an importer always saves model output following a PEtab condition event, this test case may cause indexing issues when computing the model output. * Add test for unbounded priors * Add test case triggered at time-point without measurements * Use default SBML model * Fix style
1 parent d686cf2 commit 5689168

File tree

13 files changed

+217
-0
lines changed

13 files changed

+217
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
from inspect import cleandoc
2+
3+
from petab.v2.C import *
4+
from petab.v2 import Problem
5+
from petabtests import PetabV2TestCase, analytical_a, analytical_b, DEFAULT_SBML_FILE
6+
7+
DESCRIPTION = cleandoc("""
8+
## Objective
9+
10+
This case tests applies a PEtab condition at a non-initial time point,
11+
where the condition is triggered at a time point that does not have any
12+
measurements.
13+
14+
## Model
15+
16+
A simple conversion reaction `A <=> B` in a single compartment, following
17+
mass action kinetics.
18+
""")
19+
20+
# problem --------------------------------------------------------------------
21+
a0 = 1
22+
b0 = 1
23+
k1 = 0.8
24+
k2 = 0.6
25+
problem = Problem()
26+
27+
problem.add_condition(
28+
"condition1",
29+
"condition1",
30+
A="A + 5.0",
31+
)
32+
problem.add_experiment("experiment1", 0, "", 7, "condition1")
33+
34+
35+
problem.add_observable("obs_a", "A", noise_formula="0.5")
36+
problem.add_measurement("obs_a", experiment_id="experiment1", time=0, measurement=0.7)
37+
problem.add_measurement("obs_a", experiment_id="experiment1", time=10, measurement=0.1)
38+
39+
problem.add_parameter("k1", lb=0, ub=10, nominal_value=k1, estimate=True)
40+
problem.add_parameter("k2", lb=0, ub=10, nominal_value=k2, estimate=True)
41+
42+
43+
# solutions ------------------------------------------------------------------
44+
45+
simulation_df = problem.measurement_df.copy(deep=True).rename(
46+
columns={MEASUREMENT: SIMULATION}
47+
)
48+
# in the model, concentrations are used, which do not depend on the
49+
# compartment size, so that the species values should stay the same
50+
a7 = analytical_a(7.0, a0=a0, b0=b0, k1=k1, k2=k2)
51+
b7 = analytical_b(7.0, a0=a0, b0=b0, k1=k1, k2=k2)
52+
simulation_df[SIMULATION] = [
53+
a0,
54+
analytical_a(3.0, a0=(a7 + 5.0), b0=b7, k1=k1, k2=k2)
55+
]
56+
57+
case = PetabV2TestCase.from_problem(
58+
id=28,
59+
brief="Simulation. None t0 condition applied at time-point "
60+
"without measurements.",
61+
description=DESCRIPTION,
62+
model=DEFAULT_SBML_FILE,
63+
problem=problem,
64+
simulation_df=simulation_df,
65+
)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# PEtab test case 0028
2+
3+
## Objective
4+
5+
This case tests applies a PEtab condition at a non-initial time point,
6+
where the condition is triggered at a time point that does not have any
7+
measurements.
8+
9+
## Model
10+
11+
A simple conversion reaction `A <=> B` in a single compartment, following
12+
mass action kinetics.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
condition_files:
2+
- _conditions.tsv
3+
experiment_files:
4+
- _experiments.tsv
5+
format_version: 2.0.0
6+
mapping_files:
7+
- _mapping.tsv
8+
measurement_files:
9+
- _measurements.tsv
10+
model_files:
11+
model_0:
12+
language: sbml
13+
location: _model.xml
14+
observable_files:
15+
- _observables.tsv
16+
parameter_files:
17+
- _parameters.tsv
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
chi2: 35.00133792381521
2+
llh: -17.95225166719706
3+
simulation_files:
4+
- _simulations.tsv
5+
tol_chi2: 0.001
6+
tol_llh: 0.001
7+
tol_simulations: 0.001
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
conditionId targetId targetValue
2+
condition1 A A + 5.0
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
experimentId time conditionId
2+
experiment1 0.0
3+
experiment1 7.0 condition1
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
petabEntityId modelEntityId name
2+
condition1 condition1
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
modelId observableId experimentId time measurement observableParameters noiseParameters
2+
obs_a experiment1 0.0 0.7
3+
obs_a experiment1 10.0 0.1
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<sbml xmlns="http://www.sbml.org/sbml/level2/version4" level="2" version="4">
3+
<model id="conversion_reaction_0" name="Conversion Reaction 0">
4+
5+
<listOfUnitDefinitions>
6+
<unitDefinition id="volume" name="volume">
7+
<listOfUnits>
8+
<unit kind="litre" exponent="1" scale="-3" multiplier="1"/>
9+
</listOfUnits>
10+
</unitDefinition>
11+
<unitDefinition id="substance" name="substance">
12+
<listOfUnits>
13+
<unit kind="mole" exponent="1" scale="-3" multiplier="1"/>
14+
</listOfUnits>
15+
</unitDefinition>
16+
</listOfUnitDefinitions>
17+
18+
<listOfCompartments>
19+
<compartment id="compartment" name="compartment" spatialDimensions="3" size="1" constant="true">
20+
</compartment>
21+
</listOfCompartments>
22+
23+
<listOfSpecies>
24+
<species id="A" name="A" compartment="compartment" initialConcentration="2" boundaryCondition="false" constant="false">
25+
</species>
26+
<species id="B" name="B" compartment="compartment" initialConcentration="2" boundaryCondition="false" constant="false">
27+
</species>
28+
</listOfSpecies>
29+
30+
<listOfParameters>
31+
<parameter id="a0" name="a0" value="1" constant="true">
32+
</parameter>
33+
<parameter id="b0" name="b0" value="1" constant="true">
34+
</parameter>
35+
<parameter id="k1" name="k1" value="0" constant="true">
36+
</parameter>
37+
<parameter id="k2" name="k2" value="0" constant="true">
38+
</parameter>
39+
</listOfParameters>
40+
41+
<listOfInitialAssignments>
42+
<initialAssignment symbol="A">
43+
<math xmlns="http://www.w3.org/1998/Math/MathML">
44+
<ci> a0 </ci>
45+
</math>
46+
</initialAssignment>
47+
<initialAssignment symbol="B">
48+
<math xmlns="http://www.w3.org/1998/Math/MathML">
49+
<ci> b0 </ci>
50+
</math>
51+
</initialAssignment>
52+
</listOfInitialAssignments>
53+
54+
<listOfReactions>
55+
<reaction id="fwd" name="fwd" reversible="false">
56+
<listOfReactants>
57+
<speciesReference species="A" stoichiometry="1"/>
58+
</listOfReactants>
59+
<listOfProducts>
60+
<speciesReference species="B" stoichiometry="1"/>
61+
</listOfProducts>
62+
<kineticLaw>
63+
<math xmlns="http://www.w3.org/1998/Math/MathML">
64+
<apply>
65+
<times/>
66+
<ci> compartment </ci>
67+
<ci> k1 </ci>
68+
<ci> A </ci>
69+
</apply>
70+
</math>
71+
</kineticLaw>
72+
</reaction>
73+
<reaction id="rev" name="rev" reversible="false">
74+
<listOfReactants>
75+
<speciesReference species="B" stoichiometry="1"/>
76+
</listOfReactants>
77+
<listOfProducts>
78+
<speciesReference species="A" stoichiometry="1"/>
79+
</listOfProducts>
80+
<kineticLaw>
81+
<math xmlns="http://www.w3.org/1998/Math/MathML">
82+
<apply>
83+
<times/>
84+
<ci> compartment </ci>
85+
<ci> k2 </ci>
86+
<ci> B </ci>
87+
</apply>
88+
</math>
89+
</kineticLaw>
90+
</reaction>
91+
</listOfReactions>
92+
93+
</model>
94+
</sbml>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
observableId observableName observableFormula noiseFormula noiseDistribution observablePlaceholders noisePlaceholders
2+
obs_a A 0.500000000000000 normal

0 commit comments

Comments
 (0)