Skip to content

Commit 731ad05

Browse files
authored
Merge branch 'develop' into check_grad_sbml_test_suite
2 parents 7de0769 + da3a9ef commit 731ad05

File tree

10 files changed

+90
-10
lines changed

10 files changed

+90
-10
lines changed

.github/workflows/test_windows.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ on:
88
pull_request:
99
branches:
1010
- master
11-
# TODO: remove before merge
12-
- develop
1311

1412
jobs:
1513
build:
@@ -87,12 +85,6 @@ jobs:
8785
--ignore-glob=*test_splines.py \
8886
python/tests
8987
90-
# TODO <REMOVE BEFORE MERGE>
91-
- name: Python tests splines
92-
if: ${{ github.base_ref == 'develop' || github.event.merge_group.base_ref == 'develop'}}
93-
run: python -m pytest python/tests/test_splines.py
94-
# TODO </REMOVE BEFORE MERGE>
95-
9688
- name: Python tests splines
9789
if: ${{ github.base_ref == 'master' || github.event.merge_group.base_ref == 'master'}}
9890
run: python -m pytest python/tests/test_splines.py

CHANGELOG.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,38 @@
22

33
## v0.X Series
44

5+
### v0.18.0 (2023-05-26)
6+
Features:
7+
* More efficient handling of splines in SBML models
8+
by @paulstapor, @lcontento, @dweindl
9+
in https://github.com/AMICI-dev/AMICI/pull/1515
10+
* Partial support of current PEtab2.0 draft, including support for PySB models
11+
by @dweindl, @FFroehlich in https://github.com/AMICI-dev/AMICI/pull/1800
12+
13+
Fixes
14+
* **Fixed incorrect forward sensitivities for models with events with**
15+
**state-dependent trigger functions**
16+
by @dweindl in https://github.com/AMICI-dev/AMICI/pull/2084
17+
* Model import: Don't create spl.h and sspl.h for models without splines
18+
by @dweindl in https://github.com/AMICI-dev/AMICI/pull/2088
19+
* SBML import - faster processing of SpeciesReference IDs
20+
by @dweindl in https://github.com/AMICI-dev/AMICI/pull/2094
21+
* Update swig ignores
22+
by @FFroehlich in https://github.com/AMICI-dev/AMICI/pull/2098
23+
* CMake: Fixed choosing SWIG via `SWIG` env variable
24+
by @dweindl in https://github.com/AMICI-dev/AMICI/pull/2100
25+
* CMake: Try FindBLAS if no other information was provided
26+
by @dweindl in https://github.com/AMICI-dev/AMICI/pull/2104
27+
* Fixed cblas error for models without solver states in combination with
28+
forward sensitivities
29+
by @dweindl in https://github.com/AMICI-dev/AMICI/pull/2108
30+
* Fixed compilation error for models with events and xdot=0
31+
by @dweindl in https://github.com/AMICI-dev/AMICI/pull/2111
32+
* Fixed import error for models with events and 0 states
33+
by @dweindl in https://github.com/AMICI-dev/AMICI/pull/2112
34+
35+
**Full Changelog**: https://github.com/AMICI-dev/AMICI/compare/v0.17.1...v0.18.0
36+
537
### v0.17.1 (2023-05-10)
638

739
This release fixes two bugs:

python/sdist/amici/de_export.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1993,6 +1993,10 @@ def _compute_equation(self, name: str) -> None:
19931993
]
19941994

19951995
elif name == "deltasx":
1996+
if self.num_states_solver() * self.num_par() == 0:
1997+
self._eqs[name] = []
1998+
return
1999+
19962000
event_eqs = []
19972001
for ie, event in enumerate(self._events):
19982002
tmp_eq = sp.zeros(self.num_states_solver(), self.num_par())

python/sdist/amici/petab_util.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ def get_states_in_condition_table(
5858
return states
5959
import pysb.pattern
6060

61+
if not petab_problem.model.model.species:
62+
import pysb.bng
63+
64+
pysb.bng.generate_equations(petab_problem.model.model)
65+
6166
try:
6267
spm = pysb.pattern.SpeciesPatternMatcher(
6368
model=petab_problem.model.model

python/sdist/amici/swig_wrappers.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"""Convenience wrappers for the swig interface"""
22
import logging
33
import sys
4+
5+
import warnings
46
from contextlib import contextmanager, suppress
57
from typing import Any, Dict, List, Optional, Sequence, Union
68

@@ -102,6 +104,18 @@ def runAmiciSimulation(
102104
:returns:
103105
ReturnData object with simulation results
104106
"""
107+
if (
108+
model.ne > 0
109+
and solver.getSensitivityMethod()
110+
== amici_swig.SensitivityMethod.adjoint
111+
and solver.getSensitivityOrder() == amici_swig.SensitivityOrder.first
112+
):
113+
warnings.warn(
114+
"Adjoint sensitivity analysis for models with discontinuous right hand sides (events/piecewise functions) has not been thoroughly tested."
115+
"Sensitivities might be wrong. Tracked at https://github.com/AMICI-dev/AMICI/issues/18. "
116+
"Adjoint sensitivity analysis may work if the location of the discontinuity is not parameter-dependent, but we still recommend testing accuracy of gradients."
117+
)
118+
105119
with _capture_cstdout():
106120
rdata = amici_swig.runAmiciSimulation(
107121
_get_ptr(solver), _get_ptr(edata), _get_ptr(model)
@@ -152,6 +166,18 @@ def runAmiciSimulations(
152166
153167
:returns: list of simulation results
154168
"""
169+
if (
170+
model.ne > 0
171+
and solver.getSensitivityMethod()
172+
== amici_swig.SensitivityMethod.adjoint
173+
and solver.getSensitivityOrder() == amici_swig.SensitivityOrder.first
174+
):
175+
warnings.warn(
176+
"Adjoint sensitivity analysis for models with discontinuous right hand sides (events/piecewise functions) has not been thoroughly tested. "
177+
"Sensitivities might be wrong. Tracked at https://github.com/AMICI-dev/AMICI/issues/18. "
178+
"Adjoint sensitivity analysis may work if the location of the discontinuity is not parameter-dependent, but we still recommend testing accuracy of gradients."
179+
)
180+
155181
with _capture_cstdout():
156182
edata_ptr_vector = amici_swig.ExpDataPtrVector(edata_list)
157183
rdata_ptr_list = amici_swig.runAmiciSimulations(

python/tests/test_splines.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import os
1010

1111
import numpy as np
12+
from amici.testing import skip_on_valgrind
1213
from splines_utils import (
1314
check_splines_full,
1415
example_spline_1,
@@ -17,6 +18,7 @@
1718
)
1819

1920

21+
@skip_on_valgrind
2022
def test_multiple_splines(**kwargs):
2123
"""
2224
Test a SBML model containing multiple splines.

python/tests/test_splines_python.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99

1010
import amici
1111
import sympy as sp
12+
from amici.testing import skip_on_valgrind
1213

1314

15+
@skip_on_valgrind
1416
def test_SplineUniform():
1517
spline = amici.splines.CubicHermiteSpline(
1618
sbml_id="f",
@@ -27,6 +29,7 @@ def test_SplineUniform():
2729
assert math.isclose(float(spline.evaluate(1.00)), 1.0)
2830

2931

32+
@skip_on_valgrind
3033
def test_SplineNonUniform():
3134
spline = amici.splines.CubicHermiteSpline(
3235
sbml_id="f",
@@ -43,6 +46,7 @@ def test_SplineNonUniform():
4346
assert math.isclose(float(spline.evaluate(1.00)), 1.0)
4447

4548

49+
@skip_on_valgrind
4650
def test_SplineExplicit():
4751
spline = amici.splines.CubicHermiteSpline(
4852
sbml_id="f",
@@ -62,6 +66,7 @@ def test_SplineExplicit():
6266
assert math.isclose(float(spline.evaluate(1.00)), 0.75)
6367

6468

69+
@skip_on_valgrind
6570
def test_SplineZeroBC():
6671
spline = amici.splines.CubicHermiteSpline(
6772
sbml_id="f",
@@ -77,6 +82,7 @@ def test_SplineZeroBC():
7782
assert math.isclose(float(spline.evaluate(1.00)), 1.0)
7883

7984

85+
@skip_on_valgrind
8086
def test_SplineLogarithmic():
8187
spline = amici.splines.CubicHermiteSpline(
8288
sbml_id="f",
@@ -96,6 +102,7 @@ def test_SplineLogarithmic():
96102
assert math.isclose(float(spline.evaluate(1.00)), 0.75)
97103

98104

105+
@skip_on_valgrind
99106
def test_SplineUniformConstantExtrapolation():
100107
spline = amici.splines.CubicHermiteSpline(
101108
sbml_id="f",
@@ -117,6 +124,7 @@ def test_SplineUniformConstantExtrapolation():
117124
assert math.isclose(float(spline.evaluate(3.00)), 1.0)
118125

119126

127+
@skip_on_valgrind
120128
def test_SplineUniformLinearExtrapolation():
121129
spline = amici.splines.CubicHermiteSpline(
122130
sbml_id="f",
@@ -138,6 +146,7 @@ def test_SplineUniformLinearExtrapolation():
138146
assert math.isclose(float(spline.evaluate(3.00)), 4.0)
139147

140148

149+
@skip_on_valgrind
141150
def test_SplineUniformPolynomialExtrapolation():
142151
spline = amici.splines.CubicHermiteSpline(
143152
sbml_id="f",
@@ -159,6 +168,7 @@ def test_SplineUniformPolynomialExtrapolation():
159168
assert math.isclose(float(spline.evaluate(3.00)), -248.0)
160169

161170

171+
@skip_on_valgrind
162172
def test_SplineUniformPeriodicExtrapolation():
163173
spline = amici.splines.CubicHermiteSpline(
164174
sbml_id="f",
@@ -180,6 +190,7 @@ def test_SplineUniformPeriodicExtrapolation():
180190
assert math.isclose(float(spline.evaluate(2.75)), 0.47265625)
181191

182192

193+
@skip_on_valgrind
183194
def test_SplineNonUniformPeriodicExtrapolation():
184195
spline = amici.splines.CubicHermiteSpline(
185196
sbml_id="f",
@@ -201,13 +212,15 @@ def test_SplineNonUniformPeriodicExtrapolation():
201212
assert math.isclose(float(spline.evaluate(2.05)), 1.5296875)
202213

203214

215+
@skip_on_valgrind
204216
def check_gradient(spline, t, params, params_values, expected, rel_tol=1e-9):
205217
value = spline.evaluate(t)
206218
subs = {pname: pvalue for (pname, pvalue) in zip(params, params_values)}
207219
for p, exp in zip(params, expected):
208220
assert math.isclose(float(value.diff(p).subs(subs)), exp, rel_tol=rel_tol)
209221

210222

223+
@skip_on_valgrind
211224
def test_SplineUniformSensitivity():
212225
params = (a, b, c) = sp.symbols("a b c")
213226
params_values = [0.5, 1.0, 2.5]
@@ -230,6 +243,7 @@ def test_SplineUniformSensitivity():
230243
check_gradient(spline, 1.00, params, params_values, [-6.0, 1.0, 3.0])
231244

232245

246+
@skip_on_valgrind
233247
def test_SplineNonUniformSensitivity():
234248
params = (a, b, c) = sp.symbols("a b c")
235249
params_values = [0.5, 1.0, 2.5]
@@ -250,6 +264,7 @@ def test_SplineNonUniformSensitivity():
250264
check_gradient(spline, 1.00, params, params_values, [-6.0, 1.0, 3.0])
251265

252266

267+
@skip_on_valgrind
253268
def test_SplineExplicitSensitivity():
254269
params = (a, b, c) = sp.symbols("a b c")
255270
params_values = [0.5, 1.0, 2.5]
@@ -280,6 +295,7 @@ def test_SplineExplicitSensitivity():
280295
check_gradient(spline, 1.00, params, params_values, [-6.0, 1.0, 3.0])
281296

282297

298+
@skip_on_valgrind
283299
def test_SplineLogarithmicSensitivity():
284300
params = (a, b, c) = sp.symbols("a b c")
285301
params_values = [0.5, 1.0, 2.5]

python/tests/test_splines_short.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import numpy as np
99
import sympy as sp
1010
from amici.splines import CubicHermiteSpline, UniformGrid
11+
from amici.testing import skip_on_valgrind
1112
from splines_utils import check_splines_full, example_spline_1
1213

1314

@@ -20,6 +21,7 @@ def test_spline_piecewise(**kwargs):
2021
check_splines_full(spline, params, tols, **kwargs)
2122

2223

24+
@skip_on_valgrind
2325
def test_two_splines(**kwargs):
2426
"""
2527
Test a SBML model containing two splines.
@@ -68,6 +70,7 @@ def test_two_splines(**kwargs):
6870
check_splines_full(splines, params, tols, check_piecewise=False, **kwargs)
6971

7072

73+
@skip_on_valgrind
7174
def test_splines_plist():
7275
"""
7376
Test if AMICI's spline implementation

tests/benchmark-models/benchmark_models.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Borghans_BiophysChem1997:
2323
llh: 83.3237191357272
2424
t_sim: 0.005
2525
t_fwd: 0.5
26-
t_adj: 0.1
26+
t_adj: 0.2
2727
note: benchmark collection reference value matches up to sign when applying log10-correction +sum(log(meas*log(10)) / 2
2828

2929
Brannmark_JBC2010:

version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.17.1
1+
0.18.0

0 commit comments

Comments
 (0)