Skip to content

Commit c25dd97

Browse files
committed
git subrepo clone (merge) --branch=v0.11.18 --force git@github.com:AMICI-dev/AMICI.git deps/AMICI (#350)
subrepo: subdir: "deps/AMICI" merged: "bd3b89d3" upstream: origin: "git@github.com:AMICI-dev/AMICI.git" branch: "v0.11.18" commit: "bd3b89d3" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo" commit: "be9f02a"
1 parent 7b8d895 commit c25dd97

23 files changed

+479
-122
lines changed

deps/AMICI/.gitrepo

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
;
66
[subrepo]
77
remote = git@github.com:ICB-DCM/AMICI.git
8-
branch = develop
9-
commit = 8ef53c8808437cafc171d6ab9545a59d61bb83af
10-
parent = eb33a10abde3faf2835ce846482817df06afcfe1
11-
cmdver = 0.4.1
8+
branch = v0.11.18
9+
commit = bd3b89d3839e6518532d547e54e7fe66ef3cfec3
10+
parent = 98a0746a708be9e43c7daeb54ec38bcb6709f7d9
11+
cmdver = 0.4.3
1212
method = merge

deps/AMICI/CHANGELOG.md

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

33
## v0.X Series
44

5+
### v0.11.18 (2021-07-12)
6+
7+
New:
8+
* Allow specifying maximum integration time via
9+
`amici::Solver::setMaxTime()` (#1530)
10+
* Py: Add `failfast` and `num_threads` argument to `simulate_petab`
11+
(#1528, #1524)
12+
* Enable typehints / static type checking for AMICI-generated model modules
13+
(#1514) (`amici.ModelModule`, available with Python>=3.8)
14+
15+
Fixes:
16+
* Python: Fix unused argument `generate_sensitivity_code` in `pysb2amici`
17+
(#1526)
18+
* Python: Fix C(++) stdout redirection which could have let to deadlocks in
19+
exotic situations (#1529)
20+
* Py: Fixed deprecation warning (#1525)
21+
* Py: Proper typehints for SWIG interface (#1523), enabling better static type
22+
checking and IDE integration (available with Python>=3.9)
23+
* C++: Fixed clang compiler warning (#1521)
24+
* C++: Fix inherited variadic ctor in exception class (#1520)
25+
* PEtab: More informative output for unhandled species overrides (#1519)
26+
* Return SbmlImporter from PEtab model import (#1517)
27+
28+
529
### v0.11.17 (2021-05-30)
630

731
Fixes:

deps/AMICI/include/amici/defines.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,14 @@ constexpr int AMICI_TOO_MUCH_WORK= -1;
6868
constexpr int AMICI_TOO_MUCH_ACC= -2;
6969
constexpr int AMICI_ERR_FAILURE= -3;
7070
constexpr int AMICI_CONV_FAILURE= -4;
71+
constexpr int AMICI_RHSFUNC_FAIL= -8;
7172
constexpr int AMICI_ILL_INPUT= -22;
7273
constexpr int AMICI_ERROR= -99;
7374
constexpr int AMICI_NO_STEADY_STATE= -81;
7475
constexpr int AMICI_DAMPING_FACTOR_ERROR= -86;
7576
constexpr int AMICI_SINGULAR_JACOBIAN= -809;
7677
constexpr int AMICI_NOT_IMPLEMENTED= -999;
78+
constexpr int AMICI_MAX_TIME_EXCEEDED = -1000;
7779
constexpr int AMICI_SUCCESS= 0;
7880
constexpr int AMICI_DATA_RETURN= 1;
7981
constexpr int AMICI_ROOT_RETURN= 2;

deps/AMICI/include/amici/model_dimensions.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,12 @@ struct ModelDimensions {
148148
*/
149149
int ndwdw {0};
150150

151-
/** Number of nonzero elements in the \f$w\f$ derivative of \f$xdot\f$ */
151+
/** Number of nonzero elements in the \f$ w \f$ derivative of \f$ xdot \f$ */
152152
int ndxdotdw {0};
153153

154154
/**
155-
* Number of nonzero elements in the \f$y\f$ derivative of
156-
* \f$dJy\f$ (dimension `nytrue`)
155+
* Number of nonzero elements in the \f$ y \f$ derivative of
156+
* \f$ dJy \f$ (dimension `nytrue`)
157157
*/
158158
std::vector<int> ndJydy;
159159

deps/AMICI/include/amici/serialization.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <cassert>
1010
#include <fstream>
1111
#include <iostream>
12+
#include <chrono>
1213

1314
#include <boost/serialization/array.hpp>
1415
#include <boost/serialization/vector.hpp>
@@ -83,6 +84,24 @@ void serialize(Archive &ar, amici::Solver &s, const unsigned int /*version*/) {
8384
ar &s.cpu_time_;
8485
ar &s.cpu_timeB_;
8586
ar &s.rdata_mode_;
87+
ar &s.maxtime_;
88+
}
89+
90+
/**
91+
* @brief Serialize std::chrono::duration to boost archive
92+
* @param ar Archive
93+
* @param d Duration
94+
*/
95+
template <class Archive, class Period, class Rep>
96+
void serialize(Archive &ar, std::chrono::duration<Period, Rep> &d, const unsigned int /*version*/) {
97+
Period tmp_period;
98+
if (Archive::is_loading::value) {
99+
ar &tmp_period;
100+
d = std::chrono::duration<Period, Rep>(tmp_period);
101+
} else {
102+
tmp_period = d.count();
103+
ar &tmp_period;
104+
}
86105
}
87106

88107
/**

deps/AMICI/include/amici/solver.h

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <cmath>
1111
#include <functional>
1212
#include <memory>
13+
#include <chrono>
1314

1415
namespace amici {
1516

@@ -47,6 +48,9 @@ namespace amici {
4748
*/
4849
class Solver {
4950
public:
51+
/** Type of what is passed to Sundials solvers as user_data */
52+
using user_data_type = std::pair<Model *, Solver const*>;
53+
5054
Solver() = default;
5155

5256
/**
@@ -468,6 +472,30 @@ class Solver {
468472
*/
469473
void setMaxSteps(long int maxsteps);
470474

475+
/**
476+
* @brief Returns the maximum time allowed for integration
477+
* @return Time in seconds
478+
*/
479+
double getMaxTime() const;
480+
481+
/**
482+
* @brief Set the maximum time allowed for integration
483+
* @param maxtime Time in seconds
484+
*/
485+
void setMaxTime(double maxtime);
486+
487+
/**
488+
* @brief Start timer for tracking integration time
489+
*/
490+
void startTimer() const;
491+
492+
/**
493+
* @brief Check whether maximum integration time was exceeded
494+
* @return True if the maximum integration time was exceeded,
495+
* false otherwise.
496+
*/
497+
bool timeExceeded() const;
498+
471499
/**
472500
* @brief returns the maximum number of solver steps for the backward
473501
* problem
@@ -1113,21 +1141,16 @@ class Solver {
11131141
virtual void setErrHandlerFn() const = 0;
11141142

11151143
/**
1116-
* @brief Attaches the user data instance (here this is a Model) to the
1117-
* forward problem
1118-
*
1119-
* @param model Model instance
1144+
* @brief Attaches the user data to the forward problem
11201145
*/
1121-
virtual void setUserData(Model *model) const = 0;
1146+
virtual void setUserData() const = 0;
11221147

11231148
/**
1124-
* @brief attaches the user data instance (here this is a Model) to the
1125-
* backward problem
1149+
* @brief attaches the user data to the backward problem
11261150
*
11271151
* @param which identifier of the backwards problem
1128-
* @param model Model instance
11291152
*/
1130-
virtual void setUserDataB(int which, Model *model) const = 0;
1153+
virtual void setUserDataB(int which) const = 0;
11311154

11321155
/**
11331156
* @brief specifies the maximum number of steps for the forward
@@ -1519,6 +1542,9 @@ class Solver {
15191542
mutable std::vector<std::unique_ptr<void, std::function<void(void *)>>>
15201543
solver_memory_B_;
15211544

1545+
/** Sundials user_data */
1546+
mutable user_data_type user_data;
1547+
15221548
/** internal sensitivity method flag used to select the sensitivity solution
15231549
* method. Only applies for Forward Sensitivities. */
15241550
InternalSensitivityMethod ism_ {InternalSensitivityMethod::simultaneous};
@@ -1540,6 +1566,12 @@ class Solver {
15401566
/** maximum number of allowed integration steps */
15411567
long int maxsteps_ {10000};
15421568

1569+
/** Maximum wall-time for integration in seconds */
1570+
std::chrono::duration<double, std::ratio<1>> maxtime_ {std::chrono::duration<double>::max()};
1571+
1572+
/** Time at which solver timer was started */
1573+
mutable std::chrono::time_point<std::chrono::system_clock> starttime_;
1574+
15431575
/** linear solver for the forward problem */
15441576
mutable std::unique_ptr<SUNLinSolWrapper> linear_solver_;
15451577

deps/AMICI/include/amici/solver_cvodes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ class CVodeSolver : public Solver {
137137

138138
void setErrHandlerFn() const override;
139139

140-
void setUserData(Model *model) const override;
140+
void setUserData() const override;
141141

142-
void setUserDataB(int which, Model *model) const override;
142+
void setUserDataB(int which) const override;
143143

144144
void setMaxNumSteps(long int mxsteps) const override;
145145

deps/AMICI/include/amici/solver_idas.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@ class IDASolver : public Solver {
134134

135135
void setErrHandlerFn() const override;
136136

137-
void setUserData(Model *model) const override;
137+
void setUserData() const override;
138138

139-
void setUserDataB(int which, Model *model) const override;
139+
void setUserDataB(int which) const override;
140140

141141
void setMaxNumSteps(long int mxsteps) const override;
142142

deps/AMICI/python/amici/__init__.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,13 @@
1818
:var has_clibs:
1919
boolean indicating if this is the full package with swig interface or
2020
the raw package without
21-
:var capture_cstdout:
22-
context to redirect C/C++ stdout to python stdout if python stdout was
23-
redirected (doing nothing if not redirected).
2421
"""
2522

2623
import importlib
2724
import os
2825
import re
2926
import sys
30-
from contextlib import suppress
27+
from contextlib import suppress, contextmanager
3128
from types import ModuleType as ModelModule
3229
from typing import Optional, Union, Sequence, List
3330

@@ -84,14 +81,22 @@ def _imported_from_setup() -> bool:
8481
return False
8582

8683

87-
# redirect C/C++ stdout to python stdout if python stdout is redirected,
88-
# e.g. in ipython notebook
89-
capture_cstdout = suppress
90-
if sys.stdout != sys.__stdout__:
91-
try:
92-
from wurlitzer import sys_pipes as capture_cstdout
93-
except ModuleNotFoundError:
94-
pass
84+
try:
85+
from wurlitzer import sys_pipes
86+
except ModuleNotFoundError:
87+
sys_pipes = suppress
88+
89+
90+
@contextmanager
91+
def _capture_cstdout():
92+
"""Redirect C/C++ stdout to python stdout if python stdout is redirected,
93+
e.g. in ipython notebook"""
94+
if sys.stdout == sys.__stdout__:
95+
yield
96+
else:
97+
with sys_pipes():
98+
yield
99+
95100

96101
# Initialize AMICI paths
97102
amici_path = _get_amici_path()
@@ -188,8 +193,7 @@ def runAmiciSimulation(
188193
:returns:
189194
ReturnData object with simulation results
190195
"""
191-
192-
with capture_cstdout():
196+
with _capture_cstdout():
193197
rdata = amici.runAmiciSimulation(_get_ptr(solver), _get_ptr(edata),
194198
_get_ptr(model))
195199
return numpy.ReturnDataView(rdata)
@@ -235,7 +239,7 @@ def runAmiciSimulations(
235239
236240
:returns: list of simulation results
237241
"""
238-
with capture_cstdout():
242+
with _capture_cstdout():
239243
edata_ptr_vector = amici.ExpDataPtrVector(edata_list)
240244
rdata_ptr_list = amici.runAmiciSimulations(_get_ptr(solver),
241245
edata_ptr_vector,

deps/AMICI/python/amici/custom_commands.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
"""Custom setuptools commands for AMICI installation"""
22

3-
import contextlib
43
import glob
54
import os
65
import subprocess
76
import sys
87
from shutil import copyfile
98
from typing import Dict, List, Tuple
109

10+
from amici.swig import fix_typehints
1111
from amici.setuptools import generate_swig_interface_files
1212
from setuptools.command.build_clib import build_clib
1313
from setuptools.command.build_ext import build_ext
@@ -142,9 +142,6 @@ def run(self):
142142
log.debug("running AmiciDevelop")
143143

144144
if not self.no_clibs:
145-
generate_swig_interface_files(
146-
swig_outdir=os.path.join(os.path.abspath(os.getcwd()),
147-
"amici"))
148145
self.get_finalized_command('build_clib').run()
149146

150147
develop.run(self)
@@ -226,8 +223,11 @@ def run(self):
226223
log.info(f"copying {src} -> {dest}")
227224
copyfile(src, dest)
228225

229-
generate_swig_interface_files(
230-
swig_outdir=os.path.join(build_dir, 'amici'))
226+
swig_outdir = os.path.join(os.path.abspath(build_dir), "amici")
227+
generate_swig_interface_files(swig_outdir=swig_outdir)
228+
swig_py_module_path = os.path.join(swig_outdir, 'amici.py')
229+
log.debug("updating typehints")
230+
fix_typehints(swig_py_module_path, swig_py_module_path)
231231

232232
# Always force recompilation. The way setuptools/distutils check for
233233
# whether sources require recompilation is not reliable and may lead
@@ -326,3 +326,4 @@ def set_compiler_specific_extension_options(
326326
except AttributeError:
327327
# No compiler-specific options set
328328
pass
329+

0 commit comments

Comments
 (0)