Skip to content

Commit

Permalink
Add symbol names to python-wrapped models and make them available in …
Browse files Browse the repository at this point in the history
…python (Closes #64) (#346)

* core() Add symbol names to python-wrapped models and make them available in python (Closes #64)

* feature(core) add functions to check for set symbol names

* Rewrap test models

* ci(osx) Let osx build fail until #348 is resolved

* ci(osx) go back to standard brew python

* ci() move buildAmici to script
  • Loading branch information
dweindl authored Jul 6, 2018
1 parent f1e8756 commit 17b29a0
Show file tree
Hide file tree
Showing 14 changed files with 142 additions and 24 deletions.
33 changes: 28 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ branches:
- staging

matrix:
fast_finish: true
include:
- os: linux
dist: xenial
Expand Down Expand Up @@ -38,9 +39,9 @@ matrix:
- brew update # without this homebrew can stumble over wrong ruby version
- travis_wait brew install gcc || brew link --overwrite gcc # fix linker warning regarding /usr/local/include/c++
- brew install hdf5 cppcheck swig doxygen ragel graphviz homebrew/cask/mactex
- brew install zoidbergwill/python/python36
- brew upgrade python
after_success:
- cd $BASE_DIR # cd to base dir for correct relative pah in deploy
- cd $BASE_DIR # cd to base dir for correct relative path in deploy
deploy:
provider: pages
local-dir: doc
Expand All @@ -50,24 +51,46 @@ matrix:
verbose: true
on:
branch: master


allow_failures:
# allow osx build to fail until symengine/homebrew/python3.7 issue is resolved
- os: osx
osx_image: xcode9.3
compiler: clang
before_install:
- brew update # without this homebrew can stumble over wrong ruby version
- travis_wait brew install gcc || brew link --overwrite gcc # fix linker warning regarding /usr/local/include/c++
- brew install hdf5 cppcheck swig doxygen ragel graphviz homebrew/cask/mactex
- brew upgrade python
after_success:
- cd $BASE_DIR # cd to base dir for correct relative path in deploy
deploy:
provider: pages
local-dir: doc
skip-cleanup: true
github-token: $GITHUB_TOKEN # Set in the settings page of your repository, as a secure variable
keep-history: false
verbose: true
on:
branch: master

install:
# Python distutils only looks for `swig` and does not find `swig3.0`
- export BASE_DIR=`pwd`
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then mkdir -p ~/bin/ && ln -s /usr/bin/swig3.0 ~/bin/swig && export PATH=~/bin/:$PATH; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then pyenv versions; fi
- pyenv versions
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then pyenv shell 2.7 3.6; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export PATH=/Users/travis/Library/Python/3.6/bin:$PATH; fi
- pip3 install --user --upgrade pip setuptools wheel pkgconfig doxypypy coverage scipy
- ./scripts/buildSuiteSparse.sh
- ./scripts/buildSundials.sh
- ./scripts/buildCpputest.sh
- ./scripts/buildAmici.sh

script:
# - cd $BASE_DIR/python/sdist
# - python3 setup.py sdist --dist-dir=$BASE_DIR/build/python/
# - python3 -m pip install $BASE_DIR/build/python/amici-*.tar.gz --verbose
- ./scripts/buildAmici.sh
- cd $BASE_DIR
- ./scripts/run-cpputest.sh
- ./scripts/run-cppcheck.sh
Expand Down
50 changes: 50 additions & 0 deletions include/amici/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,56 @@ namespace amici {
*/
int checkFinite(const int N,const realtype *array, const char* fun) const;


/**
* @brief Reports whether the model has parameter names set.
* @return
*/
virtual bool hasParameterNames() const { return np() && !getParameterNames().empty(); }

/**
* @brief Get names of the model parameters
* @return the names
*/
virtual std::vector<std::string> getParameterNames() const { return std::vector<std::string>(); }


/**
* @brief Reports whether the model has state names set.
* @return
*/
virtual bool hasStateNames() const { return nx && !getStateNames().empty(); }

/**
* @brief Get names of the model states
* @return the names
*/
virtual std::vector<std::string> getStateNames() const { return std::vector<std::string>(); }

/**
* @brief Reports whether the model has fixed parameter names set.
* @return
*/
virtual bool hasFixedParameterNames() const { return nk() && !getFixedParameterNames().empty(); }

/**
* @brief Get names of the fixed model parameters
* @return the names
*/
virtual std::vector<std::string> getFixedParameterNames() const { return std::vector<std::string>(); }

/**
* @brief Reports whether the model has observable names set.
* @return
*/
virtual bool hasObservableNames() const { return ny && !getObservableNames().empty(); }

/**
* @brief Get names of the observables
* @return the names
*/
virtual std::vector<std::string> getObservableNames() const { return std::vector<std::string>(); }

/** number of states */
const int nx;
/** number of states in the unaugmented system */
Expand Down
4 changes: 2 additions & 2 deletions models/model_dirac/model_dirac.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef _amici_model_dirac_h
#define _amici_model_dirac_h
/* Generated by amiwrap (R2017b) 413f6c54d956e878a95406f02808fafd1272c1cd */
/* Generated by amiwrap (R2017b) f1e875655d8b056a0adf3c71f583fe988f257a06 */
#include <cmath>
#include <memory>
#include "amici/defines.h"
Expand Down Expand Up @@ -62,7 +62,7 @@ class Model_model_dirac : public amici::Model_ODE {

virtual amici::Model* clone() const override { return new Model_model_dirac(*this); };

const char* getAmiciVersion() const { return "413f6c54d956e878a95406f02808fafd1272c1cd"; };
const char* getAmiciVersion() const { return "f1e875655d8b056a0adf3c71f583fe988f257a06"; };

virtual void fJ(realtype *J, const realtype t, const realtype *x, const double *p, const double *k, const realtype *h, const realtype *w, const realtype *dwdx) override {
J_model_dirac(J, t, x, p, k, h, w, dwdx);
Expand Down
4 changes: 2 additions & 2 deletions models/model_events/model_events.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef _amici_model_events_h
#define _amici_model_events_h
/* Generated by amiwrap (R2017b) 413f6c54d956e878a95406f02808fafd1272c1cd */
/* Generated by amiwrap (R2017b) f1e875655d8b056a0adf3c71f583fe988f257a06 */
#include <cmath>
#include <memory>
#include "amici/defines.h"
Expand Down Expand Up @@ -76,7 +76,7 @@ class Model_model_events : public amici::Model_ODE {

virtual amici::Model* clone() const override { return new Model_model_events(*this); };

const char* getAmiciVersion() const { return "413f6c54d956e878a95406f02808fafd1272c1cd"; };
const char* getAmiciVersion() const { return "f1e875655d8b056a0adf3c71f583fe988f257a06"; };

virtual void fJ(realtype *J, const realtype t, const realtype *x, const double *p, const double *k, const realtype *h, const realtype *w, const realtype *dwdx) override {
J_model_events(J, t, x, p, k, h, w, dwdx);
Expand Down
4 changes: 2 additions & 2 deletions models/model_jakstat_adjoint/model_jakstat_adjoint.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef _amici_model_jakstat_adjoint_h
#define _amici_model_jakstat_adjoint_h
/* Generated by amiwrap (R2017b) 413f6c54d956e878a95406f02808fafd1272c1cd */
/* Generated by amiwrap (R2017b) f1e875655d8b056a0adf3c71f583fe988f257a06 */
#include <cmath>
#include <memory>
#include "amici/defines.h"
Expand Down Expand Up @@ -65,7 +65,7 @@ class Model_model_jakstat_adjoint : public amici::Model_ODE {

virtual amici::Model* clone() const override { return new Model_model_jakstat_adjoint(*this); };

const char* getAmiciVersion() const { return "413f6c54d956e878a95406f02808fafd1272c1cd"; };
const char* getAmiciVersion() const { return "f1e875655d8b056a0adf3c71f583fe988f257a06"; };

virtual void fJ(realtype *J, const realtype t, const realtype *x, const double *p, const double *k, const realtype *h, const realtype *w, const realtype *dwdx) override {
J_model_jakstat_adjoint(J, t, x, p, k, h, w, dwdx);
Expand Down
4 changes: 2 additions & 2 deletions models/model_jakstat_adjoint_o2/model_jakstat_adjoint_o2.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef _amici_model_jakstat_adjoint_o2_h
#define _amici_model_jakstat_adjoint_o2_h
/* Generated by amiwrap (R2017b) 413f6c54d956e878a95406f02808fafd1272c1cd */
/* Generated by amiwrap (R2017b) f1e875655d8b056a0adf3c71f583fe988f257a06 */
#include <cmath>
#include <memory>
#include "amici/defines.h"
Expand Down Expand Up @@ -65,7 +65,7 @@ class Model_model_jakstat_adjoint_o2 : public amici::Model_ODE {

virtual amici::Model* clone() const override { return new Model_model_jakstat_adjoint_o2(*this); };

const char* getAmiciVersion() const { return "413f6c54d956e878a95406f02808fafd1272c1cd"; };
const char* getAmiciVersion() const { return "f1e875655d8b056a0adf3c71f583fe988f257a06"; };

virtual void fJ(realtype *J, const realtype t, const realtype *x, const double *p, const double *k, const realtype *h, const realtype *w, const realtype *dwdx) override {
J_model_jakstat_adjoint_o2(J, t, x, p, k, h, w, dwdx);
Expand Down
4 changes: 2 additions & 2 deletions models/model_nested_events/model_nested_events.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef _amici_model_nested_events_h
#define _amici_model_nested_events_h
/* Generated by amiwrap (R2017b) 413f6c54d956e878a95406f02808fafd1272c1cd */
/* Generated by amiwrap (R2017b) f1e875655d8b056a0adf3c71f583fe988f257a06 */
#include <cmath>
#include <memory>
#include "amici/defines.h"
Expand Down Expand Up @@ -65,7 +65,7 @@ class Model_model_nested_events : public amici::Model_ODE {

virtual amici::Model* clone() const override { return new Model_model_nested_events(*this); };

const char* getAmiciVersion() const { return "413f6c54d956e878a95406f02808fafd1272c1cd"; };
const char* getAmiciVersion() const { return "f1e875655d8b056a0adf3c71f583fe988f257a06"; };

virtual void fJ(realtype *J, const realtype t, const realtype *x, const double *p, const double *k, const realtype *h, const realtype *w, const realtype *dwdx) override {
J_model_nested_events(J, t, x, p, k, h, w, dwdx);
Expand Down
4 changes: 2 additions & 2 deletions models/model_neuron/model_neuron.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef _amici_model_neuron_h
#define _amici_model_neuron_h
/* Generated by amiwrap (R2017b) 413f6c54d956e878a95406f02808fafd1272c1cd */
/* Generated by amiwrap (R2017b) f1e875655d8b056a0adf3c71f583fe988f257a06 */
#include <cmath>
#include <memory>
#include "amici/defines.h"
Expand Down Expand Up @@ -79,7 +79,7 @@ class Model_model_neuron : public amici::Model_ODE {

virtual amici::Model* clone() const override { return new Model_model_neuron(*this); };

const char* getAmiciVersion() const { return "413f6c54d956e878a95406f02808fafd1272c1cd"; };
const char* getAmiciVersion() const { return "f1e875655d8b056a0adf3c71f583fe988f257a06"; };

virtual void fJ(realtype *J, const realtype t, const realtype *x, const double *p, const double *k, const realtype *h, const realtype *w, const realtype *dwdx) override {
J_model_neuron(J, t, x, p, k, h, w, dwdx);
Expand Down
4 changes: 2 additions & 2 deletions models/model_neuron_o2/model_neuron_o2.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef _amici_model_neuron_o2_h
#define _amici_model_neuron_o2_h
/* Generated by amiwrap (R2017b) 413f6c54d956e878a95406f02808fafd1272c1cd */
/* Generated by amiwrap (R2017b) f1e875655d8b056a0adf3c71f583fe988f257a06 */
#include <cmath>
#include <memory>
#include "amici/defines.h"
Expand Down Expand Up @@ -81,7 +81,7 @@ class Model_model_neuron_o2 : public amici::Model_ODE {

virtual amici::Model* clone() const override { return new Model_model_neuron_o2(*this); };

const char* getAmiciVersion() const { return "413f6c54d956e878a95406f02808fafd1272c1cd"; };
const char* getAmiciVersion() const { return "f1e875655d8b056a0adf3c71f583fe988f257a06"; };

virtual void fJ(realtype *J, const realtype t, const realtype *x, const double *p, const double *k, const realtype *h, const realtype *w, const realtype *dwdx) override {
J_model_neuron_o2(J, t, x, p, k, h, w, dwdx);
Expand Down
4 changes: 2 additions & 2 deletions models/model_robertson/model_robertson.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef _amici_model_robertson_h
#define _amici_model_robertson_h
/* Generated by amiwrap (R2017b) 413f6c54d956e878a95406f02808fafd1272c1cd */
/* Generated by amiwrap (R2017b) f1e875655d8b056a0adf3c71f583fe988f257a06 */
#include <cmath>
#include <memory>
#include "amici/defines.h"
Expand Down Expand Up @@ -63,7 +63,7 @@ class Model_model_robertson : public amici::Model_DAE {

virtual amici::Model* clone() const override { return new Model_model_robertson(*this); };

const char* getAmiciVersion() const { return "413f6c54d956e878a95406f02808fafd1272c1cd"; };
const char* getAmiciVersion() const { return "f1e875655d8b056a0adf3c71f583fe988f257a06"; };

virtual void fJ(realtype *J, const realtype t, const realtype *x, const double *p, const double *k, const realtype *h, const realtype cj, const realtype *dx, const realtype *w, const realtype *dwdx) override {
J_model_robertson(J, t, x, p, k, h, cj, dx, w, dwdx);
Expand Down
4 changes: 2 additions & 2 deletions models/model_steadystate/model_steadystate.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef _amici_model_steadystate_h
#define _amici_model_steadystate_h
/* Generated by amiwrap (R2017b) 413f6c54d956e878a95406f02808fafd1272c1cd */
/* Generated by amiwrap (R2017b) f1e875655d8b056a0adf3c71f583fe988f257a06 */
#include <cmath>
#include <memory>
#include "amici/defines.h"
Expand Down Expand Up @@ -62,7 +62,7 @@ class Model_model_steadystate : public amici::Model_ODE {

virtual amici::Model* clone() const override { return new Model_model_steadystate(*this); };

const char* getAmiciVersion() const { return "413f6c54d956e878a95406f02808fafd1272c1cd"; };
const char* getAmiciVersion() const { return "f1e875655d8b056a0adf3c71f583fe988f257a06"; };

virtual void fJ(realtype *J, const realtype t, const realtype *x, const double *p, const double *k, const realtype *h, const realtype *w, const realtype *dwdx) override {
J_model_steadystate(J, t, x, p, k, h, w, dwdx);
Expand Down
20 changes: 19 additions & 1 deletion python/amici/sbml_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -1102,10 +1102,28 @@ def writeModelHeader(self):
'NK': str(self.n_fixed_parameters),
'O2MODE': 'amici::AMICI_O2MODE_NONE',
'PARAMETERS': str(self.parameterValues)[1:-1],
'FIXED_PARAMETERS': str(self.fixedParameterValues)[1:-1]}
'FIXED_PARAMETERS': str(self.fixedParameterValues)[1:-1],
'PARAMETER_NAMES_INITIALIZER_LIST': self.getSymbolNameInitializerList('parameter'),
'STATE_NAMES_INITIALIZER_LIST': self.getSymbolNameInitializerList('species'),
'FIXED_PARAMETER_NAMES_INITIALIZER_LIST': self.getSymbolNameInitializerList('fixed_parameter'),
'OBSERVABLE_NAMES_INITIALIZER_LIST': self.getSymbolNameInitializerList('observable'),
}
applyTemplate(os.path.join(amiciSrcPath, 'model_header.ODE_template.h'),
os.path.join(self.modelPath, str(self.modelName) + '.h'), templateData)

def getSymbolNameInitializerList(self, name):
"""Get C++ initializer list for vector of names for the given model entity
Arguments:
name: string, any key present in self.symbols
Returns:
Raises:
"""
return '\n'.join([ '"%s",' % str(symbol) for symbol in self.symbols[name]['sym'] ])

def writeCMakeFile(self):
"""Write CMake CMakeLists.txt file for this model.
Expand Down
26 changes: 26 additions & 0 deletions src/model_header.ODE_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,32 @@ class Model_TPL_MODELNAME : public amici::Model_ODE {
virtual void fz(double *z, const int ie, const realtype t, const realtype *x, const realtype *p, const realtype *k, const realtype *h) override {
}



/**
* @brief Get names of the model parameters
* @return the names
*/
virtual std::vector<std::string> getParameterNames() const { return std::vector<std::string> {TPL_PARAMETER_NAMES_INITIALIZER_LIST}; }

/**
* @brief Get names of the model states
* @return the names
*/
virtual std::vector<std::string> getStateNames() const { return std::vector<std::string> {TPL_STATE_NAMES_INITIALIZER_LIST}; }

/**
* @brief Get names of the fixed model parameters
* @return the names
*/
virtual std::vector<std::string> getFixedParameterNames() const { return std::vector<std::string> {TPL_FIXED_PARAMETER_NAMES_INITIALIZER_LIST}; }

/**
* @brief Get names of the observables
* @return the names
*/
virtual std::vector<std::string> getObservableNames() const { return std::vector<std::string> {TPL_OBSERVABLE_NAMES_INITIALIZER_LIST}; }

};

#endif /* _amici_TPL_MODELNAME_h */
1 change: 1 addition & 0 deletions swig/amici.i
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ using namespace amici;
%template(DoubleVector) std::vector<realtype>;
%template(IntVector) std::vector<int>;
%template(ParameterScalingVector) std::vector<amici::AMICI_parameter_scaling>;
%template(StringVector) std::vector<std::string>;

0 comments on commit 17b29a0

Please sign in to comment.