Skip to content

Commit

Permalink
git subrepo clone (merge) --branch=v0.11.18 --force [email protected]:AM…
Browse files Browse the repository at this point in the history
…ICI-dev/AMICI.git deps/AMICI (#350)

subrepo:
  subdir:   "deps/AMICI"
  merged:   "bd3b89d3"
upstream:
  origin:   "[email protected]: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"
  • Loading branch information
dweindl committed Jul 13, 2021
1 parent f580d40 commit 3b13b04
Show file tree
Hide file tree
Showing 23 changed files with 479 additions and 122 deletions.
8 changes: 4 additions & 4 deletions deps/AMICI/.gitrepo
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
;
[subrepo]
remote = [email protected]:ICB-DCM/AMICI.git
branch = develop
commit = 8ef53c8808437cafc171d6ab9545a59d61bb83af
parent = eb33a10abde3faf2835ce846482817df06afcfe1
cmdver = 0.4.1
branch = v0.11.18
commit = bd3b89d3839e6518532d547e54e7fe66ef3cfec3
parent = 98a0746a708be9e43c7daeb54ec38bcb6709f7d9
cmdver = 0.4.3
method = merge
24 changes: 24 additions & 0 deletions deps/AMICI/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,30 @@

## v0.X Series

### v0.11.18 (2021-07-12)

New:
* Allow specifying maximum integration time via
`amici::Solver::setMaxTime()` (#1530)
* Py: Add `failfast` and `num_threads` argument to `simulate_petab`
(#1528, #1524)
* Enable typehints / static type checking for AMICI-generated model modules
(#1514) (`amici.ModelModule`, available with Python>=3.8)

Fixes:
* Python: Fix unused argument `generate_sensitivity_code` in `pysb2amici`
(#1526)
* Python: Fix C(++) stdout redirection which could have let to deadlocks in
exotic situations (#1529)
* Py: Fixed deprecation warning (#1525)
* Py: Proper typehints for SWIG interface (#1523), enabling better static type
checking and IDE integration (available with Python>=3.9)
* C++: Fixed clang compiler warning (#1521)
* C++: Fix inherited variadic ctor in exception class (#1520)
* PEtab: More informative output for unhandled species overrides (#1519)
* Return SbmlImporter from PEtab model import (#1517)


### v0.11.17 (2021-05-30)

Fixes:
Expand Down
2 changes: 2 additions & 0 deletions deps/AMICI/include/amici/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,14 @@ constexpr int AMICI_TOO_MUCH_WORK= -1;
constexpr int AMICI_TOO_MUCH_ACC= -2;
constexpr int AMICI_ERR_FAILURE= -3;
constexpr int AMICI_CONV_FAILURE= -4;
constexpr int AMICI_RHSFUNC_FAIL= -8;
constexpr int AMICI_ILL_INPUT= -22;
constexpr int AMICI_ERROR= -99;
constexpr int AMICI_NO_STEADY_STATE= -81;
constexpr int AMICI_DAMPING_FACTOR_ERROR= -86;
constexpr int AMICI_SINGULAR_JACOBIAN= -809;
constexpr int AMICI_NOT_IMPLEMENTED= -999;
constexpr int AMICI_MAX_TIME_EXCEEDED = -1000;
constexpr int AMICI_SUCCESS= 0;
constexpr int AMICI_DATA_RETURN= 1;
constexpr int AMICI_ROOT_RETURN= 2;
Expand Down
6 changes: 3 additions & 3 deletions deps/AMICI/include/amici/model_dimensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,12 @@ struct ModelDimensions {
*/
int ndwdw {0};

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

/**
* Number of nonzero elements in the \f$y\f$ derivative of
* \f$dJy\f$ (dimension `nytrue`)
* Number of nonzero elements in the \f$ y \f$ derivative of
* \f$ dJy \f$ (dimension `nytrue`)
*/
std::vector<int> ndJydy;

Expand Down
19 changes: 19 additions & 0 deletions deps/AMICI/include/amici/serialization.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <cassert>
#include <fstream>
#include <iostream>
#include <chrono>

#include <boost/serialization/array.hpp>
#include <boost/serialization/vector.hpp>
Expand Down Expand Up @@ -83,6 +84,24 @@ void serialize(Archive &ar, amici::Solver &s, const unsigned int /*version*/) {
ar &s.cpu_time_;
ar &s.cpu_timeB_;
ar &s.rdata_mode_;
ar &s.maxtime_;
}

/**
* @brief Serialize std::chrono::duration to boost archive
* @param ar Archive
* @param d Duration
*/
template <class Archive, class Period, class Rep>
void serialize(Archive &ar, std::chrono::duration<Period, Rep> &d, const unsigned int /*version*/) {
Period tmp_period;
if (Archive::is_loading::value) {
ar &tmp_period;
d = std::chrono::duration<Period, Rep>(tmp_period);
} else {
tmp_period = d.count();
ar &tmp_period;
}
}

/**
Expand Down
50 changes: 41 additions & 9 deletions deps/AMICI/include/amici/solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <cmath>
#include <functional>
#include <memory>
#include <chrono>

namespace amici {

Expand Down Expand Up @@ -47,6 +48,9 @@ namespace amici {
*/
class Solver {
public:
/** Type of what is passed to Sundials solvers as user_data */
using user_data_type = std::pair<Model *, Solver const*>;

Solver() = default;

/**
Expand Down Expand Up @@ -468,6 +472,30 @@ class Solver {
*/
void setMaxSteps(long int maxsteps);

/**
* @brief Returns the maximum time allowed for integration
* @return Time in seconds
*/
double getMaxTime() const;

/**
* @brief Set the maximum time allowed for integration
* @param maxtime Time in seconds
*/
void setMaxTime(double maxtime);

/**
* @brief Start timer for tracking integration time
*/
void startTimer() const;

/**
* @brief Check whether maximum integration time was exceeded
* @return True if the maximum integration time was exceeded,
* false otherwise.
*/
bool timeExceeded() const;

/**
* @brief returns the maximum number of solver steps for the backward
* problem
Expand Down Expand Up @@ -1113,21 +1141,16 @@ class Solver {
virtual void setErrHandlerFn() const = 0;

/**
* @brief Attaches the user data instance (here this is a Model) to the
* forward problem
*
* @param model Model instance
* @brief Attaches the user data to the forward problem
*/
virtual void setUserData(Model *model) const = 0;
virtual void setUserData() const = 0;

/**
* @brief attaches the user data instance (here this is a Model) to the
* backward problem
* @brief attaches the user data to the backward problem
*
* @param which identifier of the backwards problem
* @param model Model instance
*/
virtual void setUserDataB(int which, Model *model) const = 0;
virtual void setUserDataB(int which) const = 0;

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

/** Sundials user_data */
mutable user_data_type user_data;

/** internal sensitivity method flag used to select the sensitivity solution
* method. Only applies for Forward Sensitivities. */
InternalSensitivityMethod ism_ {InternalSensitivityMethod::simultaneous};
Expand All @@ -1540,6 +1566,12 @@ class Solver {
/** maximum number of allowed integration steps */
long int maxsteps_ {10000};

/** Maximum wall-time for integration in seconds */
std::chrono::duration<double, std::ratio<1>> maxtime_ {std::chrono::duration<double>::max()};

/** Time at which solver timer was started */
mutable std::chrono::time_point<std::chrono::system_clock> starttime_;

/** linear solver for the forward problem */
mutable std::unique_ptr<SUNLinSolWrapper> linear_solver_;

Expand Down
4 changes: 2 additions & 2 deletions deps/AMICI/include/amici/solver_cvodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ class CVodeSolver : public Solver {

void setErrHandlerFn() const override;

void setUserData(Model *model) const override;
void setUserData() const override;

void setUserDataB(int which, Model *model) const override;
void setUserDataB(int which) const override;

void setMaxNumSteps(long int mxsteps) const override;

Expand Down
4 changes: 2 additions & 2 deletions deps/AMICI/include/amici/solver_idas.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ class IDASolver : public Solver {

void setErrHandlerFn() const override;

void setUserData(Model *model) const override;
void setUserData() const override;

void setUserDataB(int which, Model *model) const override;
void setUserDataB(int which) const override;

void setMaxNumSteps(long int mxsteps) const override;

Expand Down
34 changes: 19 additions & 15 deletions deps/AMICI/python/amici/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,13 @@
:var has_clibs:
boolean indicating if this is the full package with swig interface or
the raw package without
:var capture_cstdout:
context to redirect C/C++ stdout to python stdout if python stdout was
redirected (doing nothing if not redirected).
"""

import importlib
import os
import re
import sys
from contextlib import suppress
from contextlib import suppress, contextmanager
from types import ModuleType as ModelModule
from typing import Optional, Union, Sequence, List

Expand Down Expand Up @@ -84,14 +81,22 @@ def _imported_from_setup() -> bool:
return False


# redirect C/C++ stdout to python stdout if python stdout is redirected,
# e.g. in ipython notebook
capture_cstdout = suppress
if sys.stdout != sys.__stdout__:
try:
from wurlitzer import sys_pipes as capture_cstdout
except ModuleNotFoundError:
pass
try:
from wurlitzer import sys_pipes
except ModuleNotFoundError:
sys_pipes = suppress


@contextmanager
def _capture_cstdout():
"""Redirect C/C++ stdout to python stdout if python stdout is redirected,
e.g. in ipython notebook"""
if sys.stdout == sys.__stdout__:
yield
else:
with sys_pipes():
yield


# Initialize AMICI paths
amici_path = _get_amici_path()
Expand Down Expand Up @@ -188,8 +193,7 @@ def runAmiciSimulation(
:returns:
ReturnData object with simulation results
"""

with capture_cstdout():
with _capture_cstdout():
rdata = amici.runAmiciSimulation(_get_ptr(solver), _get_ptr(edata),
_get_ptr(model))
return numpy.ReturnDataView(rdata)
Expand Down Expand Up @@ -235,7 +239,7 @@ def runAmiciSimulations(
:returns: list of simulation results
"""
with capture_cstdout():
with _capture_cstdout():
edata_ptr_vector = amici.ExpDataPtrVector(edata_list)
rdata_ptr_list = amici.runAmiciSimulations(_get_ptr(solver),
edata_ptr_vector,
Expand Down
13 changes: 7 additions & 6 deletions deps/AMICI/python/amici/custom_commands.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
"""Custom setuptools commands for AMICI installation"""

import contextlib
import glob
import os
import subprocess
import sys
from shutil import copyfile
from typing import Dict, List, Tuple

from amici.swig import fix_typehints
from amici.setuptools import generate_swig_interface_files
from setuptools.command.build_clib import build_clib
from setuptools.command.build_ext import build_ext
Expand Down Expand Up @@ -142,9 +142,6 @@ def run(self):
log.debug("running AmiciDevelop")

if not self.no_clibs:
generate_swig_interface_files(
swig_outdir=os.path.join(os.path.abspath(os.getcwd()),
"amici"))
self.get_finalized_command('build_clib').run()

develop.run(self)
Expand Down Expand Up @@ -226,8 +223,11 @@ def run(self):
log.info(f"copying {src} -> {dest}")
copyfile(src, dest)

generate_swig_interface_files(
swig_outdir=os.path.join(build_dir, 'amici'))
swig_outdir = os.path.join(os.path.abspath(build_dir), "amici")
generate_swig_interface_files(swig_outdir=swig_outdir)
swig_py_module_path = os.path.join(swig_outdir, 'amici.py')
log.debug("updating typehints")
fix_typehints(swig_py_module_path, swig_py_module_path)

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

4 changes: 2 additions & 2 deletions deps/AMICI/python/amici/parameter_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ def __init__(


class ParameterMapping(Sequence):
"""Parameter mapping for multiple conditions.
r"""Parameter mapping for multiple conditions.
This can be used like a list of :class:`ParameterMappingForCondition`\\ s.
This can be used like a list of :class:`ParameterMappingForCondition`\ s.
:param parameter_mappings:
List of parameter mappings for specific conditions.
Expand Down
14 changes: 12 additions & 2 deletions deps/AMICI/python/amici/petab_objective.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ def simulate_petab(
edatas: List[AmiciExpData] = None,
parameter_mapping: ParameterMapping = None,
scaled_parameters: Optional[bool] = False,
log_level: int = logging.WARNING
log_level: int = logging.WARNING,
num_threads: int = 1,
failfast: bool = True,
) -> Dict[str, Any]:
"""Simulate PEtab model.
Expand Down Expand Up @@ -78,6 +80,12 @@ def simulate_petab(
are assumed to be in linear scale.
:param log_level:
Log level, see :mod:`amici.logging` module.
:param num_threads:
Number of threads to use for simulating multiple conditions
(only used if compiled with OpenMP).
:param failfast:
Returns as soon as an integration failure is encountered, skipping
any remaining simulations.
:return:
Dictionary of
Expand Down Expand Up @@ -136,7 +144,9 @@ def simulate_petab(
amici_model=amici_model)

# Simulate
rdatas = amici.runAmiciSimulations(amici_model, solver, edata_list=edatas)
rdatas = amici.runAmiciSimulations(
amici_model, solver, edata_list=edatas,
num_threads=num_threads, failfast=failfast)

# Compute total llh
llh = sum(rdata['llh'] for rdata in rdatas)
Expand Down
Loading

0 comments on commit 3b13b04

Please sign in to comment.