Skip to content

Commit 65e327d

Browse files
committed
update templates, regenerate test models
1 parent a5e9822 commit 65e327d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+342
-121
lines changed

models/model_calvetti_py/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ int main() {
3838
solver->set_relative_tolerance(1e-8);
3939

4040
// Run the simulation using default parameters set during model import
41-
// (can be changed using model->setParameters() or model->setParameterBy*())
41+
// (can be changed using model->set_free_parameters() or model->set_free_parameter_by*())
4242
auto rdata = run_simulation(*solver, nullptr, *model);
4343

4444
// Print observable time course
@@ -69,7 +69,7 @@ int main() {
6969
// Print state sensitivities sx...
7070
// ... for the first timepoint...
7171
int i_time = 0;
72-
// ... with respect to the first parameter
72+
// ... with respect to the first free parameter
7373
int i_nplist = 0;
7474

7575
// get identifiers from model

models/model_calvetti_py/model_calvetti_py.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace amici::model_model_calvetti_py {
55

66
// clang-format off
77

8-
std::array<const char*, 0> parameter_names = {
8+
std::array<const char*, 0> free_parameter_names = {
99

1010
};
1111

@@ -65,7 +65,7 @@ std::array<const char*, 17> expression_names = {
6565
"flux_r0", // w[16]
6666
};
6767

68-
std::array<const char*, 0> parameter_ids = {
68+
std::array<const char*, 0> free_parameter_ids = {
6969

7070
};
7171

models/model_calvetti_py/model_calvetti_py.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ class Model_model_calvetti_py : public amici::Model_DAE {
144144
},
145145
amici::SimulationParameters(
146146
std::vector<realtype>{0.28999999999999998, 0.73999999999999999, 0.44, 0.080000000000000002, 0.27000000000000002, 0.17999999999999999}, // fixedParameters
147-
std::vector<realtype>{} // dynamic parameters
147+
std::vector<realtype>{} // free parameters
148148
),
149149
amici::SecondOrderMode::none, // o2mode
150150
std::vector<realtype>{1.0, 1.0, 1.0, 0.0, 0.0, 0.0}, // idlist
@@ -421,7 +421,7 @@ class Model_model_calvetti_py : public amici::Model_DAE {
421421
}
422422

423423
/**
424-
* @brief Get names of the model parameters
424+
* @brief Get names of the free model parameters
425425
* @return the names
426426
*/
427427
std::vector<std::string> get_free_parameter_names() const override {
@@ -478,7 +478,7 @@ class Model_model_calvetti_py : public amici::Model_DAE {
478478
}
479479

480480
/**
481-
* @brief Get ids of the model parameters
481+
* @brief Get ids of the free model parameters
482482
* @return the ids
483483
*/
484484
std::vector<std::string> get_free_parameter_ids() const override {
@@ -557,7 +557,7 @@ class Model_model_calvetti_py : public amici::Model_DAE {
557557
* @return AMICI git commit hash
558558
*/
559559
std::string get_amici_commit() const override {
560-
return "f005fac9e2de7c3c90be2ac55d4ad165471ed1e7";
560+
return "40190b46b1b398e321314ded4169fe910b37c484";
561561
}
562562

563563
bool has_quadratic_llh() const override {

models/model_calvetti_py/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""AMICI model package setup"""
22

3+
import importlib.metadata
34
import os
45
import sys
56
from pathlib import Path
@@ -8,7 +9,6 @@
89
from amici.custom_commands import AmiciBuildCMakeExtension
910
from cmake_build_extension import CMakeExtension
1011
from setuptools import find_namespace_packages, setup
11-
import importlib.metadata
1212

1313

1414
def get_extension() -> CMakeExtension:

models/model_calvetti_py/swig/model_calvetti_py.i

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ import sysconfig
88
from pathlib import Path
99
1010
ext_suffix = sysconfig.get_config_var('EXT_SUFFIX')
11+
extension_path = Path(__file__).parent / f'_model_calvetti_py{ext_suffix}'
1112
_model_calvetti_py = amici._module_from_path(
1213
'model_calvetti_py._model_calvetti_py' if __package__ or '.' in __name__
1314
else '_model_calvetti_py',
14-
Path(__file__).parent / f'_model_calvetti_py{ext_suffix}',
15+
extension_path,
1516
)
1617
1718
def _get_import_time():
@@ -36,6 +37,28 @@ if t_imported < t_modified:
3637

3738
%module(package="model_calvetti_py",moduleimport=MODULEIMPORT) model_calvetti_py
3839

40+
// store swig version
41+
%constant int SWIG_VERSION_MAJOR = (SWIG_VERSION >> 16);
42+
%constant int SWIG_VERSION_MINOR = ((SWIG_VERSION >> 8) & 0xff);
43+
%constant int SWIG_VERSION_PATCH = (SWIG_VERSION & 0xff);
44+
45+
%pythoncode %{
46+
# SWIG version used to build the model extension as `(major, minor, patch)`
47+
_SWIG_VERSION = (SWIG_VERSION_MAJOR, SWIG_VERSION_MINOR, SWIG_VERSION_PATCH)
48+
49+
if (amici_swig := amici.amici._SWIG_VERSION) != (model_swig := _SWIG_VERSION):
50+
import warnings
51+
warnings.warn(
52+
f"SWIG version mismatch between amici ({amici_swig}) and model "
53+
f"({model_swig}). This may lead to unexpected behavior. "
54+
"In that case, please recompile the model with swig=="
55+
f"{amici_swig[0]}.{amici_swig[1]}.{amici_swig[2]} or rebuild amici "
56+
f"with swig=={model_swig[0]}.{model_swig[1]}.{model_swig[2]}.",
57+
RuntimeWarning,
58+
stacklevel=2,
59+
)
60+
%}
61+
3962
%pythoncode %{
4063
# the model-package __init__.py module (will be set during import)
4164
_model_module = None
@@ -56,7 +79,7 @@ using namespace amici;
5679
// store the time a module was imported
5780
%{
5881
#include <chrono>
59-
static std::chrono::time_point<std::chrono::system_clock> _module_import_time;
82+
static std::chrono::time_point<std::chrono::system_clock> _module_import_time = std::chrono::system_clock::now();
6083

6184
static double _get_import_time() {
6285
auto epoch = _module_import_time.time_since_epoch();
@@ -67,7 +90,9 @@ static double _get_import_time() {
6790
static double _get_import_time();
6891

6992
%init %{
70-
_module_import_time = std::chrono::system_clock::now();
93+
// NOTE: from SWIG 4.4.0 onwards, %init code is executed every time the
94+
// module is executed - not only on first import
95+
// This code ends up in `SWIG_mod_exec`.
7196
%}
7297

7398

models/model_dirac_py/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ int main() {
3838
solver->set_relative_tolerance(1e-8);
3939

4040
// Run the simulation using default parameters set during model import
41-
// (can be changed using model->setParameters() or model->setParameterBy*())
41+
// (can be changed using model->set_free_parameters() or model->set_free_parameter_by*())
4242
auto rdata = run_simulation(*solver, nullptr, *model);
4343

4444
// Print observable time course
@@ -69,7 +69,7 @@ int main() {
6969
// Print state sensitivities sx...
7070
// ... for the first timepoint...
7171
int i_time = 0;
72-
// ... with respect to the first parameter
72+
// ... with respect to the first free parameter
7373
int i_nplist = 0;
7474

7575
// get identifiers from model

models/model_dirac_py/model_dirac_py.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace amici::model_model_dirac_py {
55

66
// clang-format off
77

8-
std::array<const char*, 4> parameter_names = {
8+
std::array<const char*, 4> free_parameter_names = {
99
"p1", // p[0]
1010
"p2", // p[1]
1111
"p3", // p[2]
@@ -33,7 +33,7 @@ std::array<const char*, 1> expression_names = {
3333
"flux_r0", // w[0]
3434
};
3535

36-
std::array<const char*, 4> parameter_ids = {
36+
std::array<const char*, 4> free_parameter_ids = {
3737
"p1", // p[0]
3838
"p2", // p[1]
3939
"p3", // p[2]

models/model_dirac_py/model_dirac_py.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Solver;
1414

1515
namespace model_model_dirac_py {
1616

17-
extern std::array<const char*, 4> parameter_names;
17+
extern std::array<const char*, 4> free_parameter_names;
1818
extern std::array<const char*, 0> fixed_parameter_names;
1919
extern std::array<const char*, 2> state_names;
2020
extern std::array<const char*, 1> observable_names;
@@ -144,7 +144,7 @@ class Model_model_dirac_py : public amici::Model_ODE {
144144
},
145145
amici::SimulationParameters(
146146
std::vector<realtype>{}, // fixedParameters
147-
std::vector<realtype>{1.0, 0.5, 2.0, 3.0} // dynamic parameters
147+
std::vector<realtype>{1.0, 0.5, 2.0, 3.0} // free parameters
148148
),
149149
amici::SecondOrderMode::none, // o2mode
150150
std::vector<realtype>{1.0, 1.0}, // idlist
@@ -408,12 +408,12 @@ class Model_model_dirac_py : public amici::Model_ODE {
408408
}
409409

410410
/**
411-
* @brief Get names of the model parameters
411+
* @brief Get names of the free model parameters
412412
* @return the names
413413
*/
414-
std::vector<std::string> get_parameter_names() const override {
415-
return std::vector<std::string>(parameter_names.begin(),
416-
parameter_names.end());
414+
std::vector<std::string> get_free_parameter_names() const override {
415+
return std::vector<std::string>(free_parameter_names.begin(),
416+
free_parameter_names.end());
417417
}
418418

419419
/**
@@ -465,7 +465,7 @@ class Model_model_dirac_py : public amici::Model_ODE {
465465
}
466466

467467
/**
468-
* @brief Get ids of the model parameters
468+
* @brief Get ids of the free model parameters
469469
* @return the ids
470470
*/
471471
std::vector<std::string> get_free_parameter_ids() const override {
@@ -544,7 +544,7 @@ class Model_model_dirac_py : public amici::Model_ODE {
544544
* @return AMICI git commit hash
545545
*/
546546
std::string get_amici_commit() const override {
547-
return "f005fac9e2de7c3c90be2ac55d4ad165471ed1e7";
547+
return "40190b46b1b398e321314ded4169fe910b37c484";
548548
}
549549

550550
bool has_quadratic_llh() const override {

models/model_dirac_py/model_dirac_py/model_dirac_py.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# This file was automatically generated by SWIG (https://www.swig.org).
2-
# Version 4.3.1
2+
# Version 4.4.0
33
#
44
# Do not make changes to this file unless you know what you are doing - modify
55
# the SWIG interface file instead.
@@ -14,10 +14,11 @@
1414
from pathlib import Path
1515

1616
ext_suffix = sysconfig.get_config_var('EXT_SUFFIX')
17+
extension_path = Path(__file__).parent / f'_model_dirac_py{ext_suffix}'
1718
_model_dirac_py = amici._module_from_path(
1819
'model_dirac_py._model_dirac_py' if __package__ or '.' in __name__
1920
else '_model_dirac_py',
20-
Path(__file__).parent / f'_model_dirac_py{ext_suffix}',
21+
extension_path,
2122
)
2223

2324
def _get_import_time():
@@ -86,6 +87,25 @@ class _SwigNonDynamicMeta(type):
8687
__setattr__ = _swig_setattr_nondynamic_class_variable(type.__setattr__)
8788

8889

90+
SWIG_VERSION_MAJOR = _model_dirac_py.SWIG_VERSION_MAJOR
91+
SWIG_VERSION_MINOR = _model_dirac_py.SWIG_VERSION_MINOR
92+
SWIG_VERSION_PATCH = _model_dirac_py.SWIG_VERSION_PATCH
93+
94+
# SWIG version used to build the model extension as `(major, minor, patch)`
95+
_SWIG_VERSION = (SWIG_VERSION_MAJOR, SWIG_VERSION_MINOR, SWIG_VERSION_PATCH)
96+
97+
if (amici_swig := amici.amici._SWIG_VERSION) != (model_swig := _SWIG_VERSION):
98+
import warnings
99+
warnings.warn(
100+
f"SWIG version mismatch between amici ({amici_swig}) and model "
101+
f"({model_swig}). This may lead to unexpected behavior. "
102+
"In that case, please recompile the model with swig=="
103+
f"{amici_swig[0]}.{amici_swig[1]}.{amici_swig[2]} or rebuild amici "
104+
f"with swig=={model_swig[0]}.{model_swig[1]}.{model_swig[2]}.",
105+
RuntimeWarning,
106+
stacklevel=2,
107+
)
108+
89109

90110
# the model-package __init__.py module (will be set during import)
91111
_model_module = None

models/model_dirac_py/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""AMICI model package setup"""
22

3+
import importlib.metadata
34
import os
45
import sys
56
from pathlib import Path
@@ -8,7 +9,6 @@
89
from amici.custom_commands import AmiciBuildCMakeExtension
910
from cmake_build_extension import CMakeExtension
1011
from setuptools import find_namespace_packages, setup
11-
import importlib.metadata
1212

1313

1414
def get_extension() -> CMakeExtension:

0 commit comments

Comments
 (0)