Skip to content

Commit

Permalink
Merge pull request #640 from ICB-DCM/develop
Browse files Browse the repository at this point in the history
0.10.1 Release
  • Loading branch information
yannikschaelte authored Mar 4, 2019
2 parents fda9636 + f9f4c76 commit fb033df
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 52 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ python/sdist/amici/amici_wrap_without_hdf5.cxx
python/sdist/build/*
python/sdist/amici/git_version.txt

python/sdist/dist

AMICI_guide.pdf

ThirdParty/bionetgen.tar.gz
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ Online documentation is available as [github-pages](http://icb-dcm.github.io/AMI
## Current build status

[![PyPI version](https://badge.fury.io/py/amici.svg)](https://badge.fury.io/py/amici)
[![Build Status](https://travis-ci.org/ICB-DCM/AMICI.svg?branch=master)](https://travis-ci.org/ICB-DCM/AMICI)
[![Build Status](https://travis-ci.com/ICB-DCM/AMICI.svg?branch=master)](https://travis-ci.com/ICB-DCM/AMICI)
[![CodeCov](https://codecov.io/gh/ICB-DCM/AMICI/branch/master/graph/badge.svg)](https://codecov.io/gh/ICB-DCM/AMICI)
[![Codacy](https://api.codacy.com/project/badge/Grade/945235766e344a7fa36278feab915ff6)](https://www.codacy.com/app/FFroehlich/AMICI?utm_source=github.com&utm_medium=referral&utm_content=ICB-DCM/AMICI&utm_campaign=Badge_Grade)
10 changes: 9 additions & 1 deletion include/amici/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,7 @@ class Model : public AbstractModel {

/**
* @brief Reports whether the model has parameter names set.
* Also returns true if the number of corresponding variables is just zero.
* @return boolean indicating whether parameter names were set
*/
virtual bool hasParameterNames() const;
Expand All @@ -962,6 +963,7 @@ class Model : public AbstractModel {

/**
* @brief Reports whether the model has state names set.
* Also returns true if the number of corresponding variables is just zero.
* @return boolean indicating whether state names were set
*/
virtual bool hasStateNames() const;
Expand All @@ -974,6 +976,7 @@ class Model : public AbstractModel {

/**
* @brief Reports whether the model has fixed parameter names set.
* Also returns true if the number of corresponding variables is just zero.
* @return boolean indicating whether fixed parameter names were set
*/
virtual bool hasFixedParameterNames() const;
Expand All @@ -986,6 +989,7 @@ class Model : public AbstractModel {

/**
* @brief Reports whether the model has observable names set.
* Also returns true if the number of corresponding variables is just zero.
* @return boolean indicating whether observabke names were set
*/
virtual bool hasObservableNames() const;
Expand All @@ -998,6 +1002,7 @@ class Model : public AbstractModel {

/**
* @brief Reports whether the model has parameter ids set.
* Also returns true if the number of corresponding variables is just zero.
* @return boolean indicating whether parameter ids were set
*/
virtual bool hasParameterIds() const;
Expand Down Expand Up @@ -1057,7 +1062,8 @@ class Model : public AbstractModel {

/**
* @brief Reports whether the model has state ids set.
* @return
* Also returns true if the number of corresponding variables is just zero.
* @return boolean indicating whether state ids were set
*/
virtual bool hasStateIds() const;

Expand All @@ -1069,6 +1075,7 @@ class Model : public AbstractModel {

/**
* @brief Reports whether the model has fixed parameter ids set.
* Also returns true if the number of corresponding variables is just zero.
* @return boolean indicating whether fixed parameter ids were set
*/
virtual bool hasFixedParameterIds() const;
Expand All @@ -1081,6 +1088,7 @@ class Model : public AbstractModel {

/**
* @brief Reports whether the model has observable ids set.
* Also returns true if the number of corresponding variables is just zero.
* @return boolean indicating whether observale ids were set
*/
virtual bool hasObservableIds() const;
Expand Down
29 changes: 16 additions & 13 deletions python/amici/pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,28 +367,31 @@ def _get_names_or_ids(model, variable, by_id):
# check whether variable type permitted
variable_options = ['Parameter', 'FixedParameter', 'Observable', 'State']
if variable not in variable_options:
raise ValueError('variable must be in ' + str(variable_options))
raise ValueError('Variable must be in ' + str(variable_options))

# functions to extract attributes
namegetter = getattr(model, 'get' + variable + 'Names')
idgetter = getattr(model, 'get' + variable + 'Ids')
# extract attributes
names = list(getattr(model, f'get{variable}Names')())
ids = list(getattr(model, f'get{variable}Ids')())

# find out if model has names and ids
has_names = getattr(model, f'has{variable}Names')()
has_ids = getattr(model, f'has{variable}Ids')()

# extract labels
if not by_id and len(set(namegetter())) == len(namegetter()) \
and getattr(model, f"has{variable}Names")():
if not by_id and has_names and len(set(names)) == len(names):
# use variable names
return list(namegetter())
elif getattr(model, f"has{variable}Ids")():
return names
elif has_ids:
# use variable ids
return list(idgetter())
return ids
else:
# unable to create unique labels
if by_id:
raise RuntimeError(f"Model {variable} ids are not set.")
msg = f"Model {variable} ids are not set."
else:
raise RuntimeError(
f"Model {variable} names are not unique and "
f"{variable} ids are not set.")
msg = f"Model {variable} names are not unique and " \
f"{variable} ids are not set."
raise ValueError(msg)


def _get_specialized_fixed_parameters(
Expand Down
69 changes: 41 additions & 28 deletions python/amici/sbml_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class SbmlImporter:
symbols: dict carrying symbolic definitions @type dict
SBMLreader: the libSBML sbml reader [!not storing this will result
sbml_reader: the libSBML sbml reader [!not storing this will result
in a segfault!]
sbml_doc: document carrying the sbml definition [!not storing this
Expand Down Expand Up @@ -76,58 +76,61 @@ class SbmlImporter:
"""

def __init__(self, SBMLFile, show_sbml_warnings=False):
def __init__(
self,
sbml_source: str,
show_sbml_warnings: bool = False,
from_file: bool = True):
"""Create a new Model instance.
Arguments:
SBMLFile: Path to SBML file where the model is specified @type string
sbml_source: Either a path to SBML file where the model is specified.
Or a model string as created by sbml.sbmlWriter().writeSBMLToString().
@type string
show_sbml_warnings: indicates whether libSBML warnings should be
displayed @type bool
show_sbml_warnings: Indicates whether libSBML warnings should be
displayed (default = True). @type bool
from_file: Whether `sbml_source` is a file name (True, default), or an
sbml string (False). @type bool
Returns:
SbmlImporter instance with attached SBML document
SbmlImporter instance with attached SBML document
Raises:
"""
self.sbml_reader = sbml.SBMLReader()

if from_file:
sbml_doc = self.sbml_reader.readSBMLFromFile(sbml_source)
else:
sbml_doc = self.sbml_reader.readSBMLFromString(sbml_source)
self.sbml_doc = sbml_doc

self.show_sbml_warnings = show_sbml_warnings

self.loadSBMLFile(SBMLFile)
# process document
self.process_document()

self.sbml = self.sbml_doc.getModel()

"""Long and short names for model components"""
# Long and short names for model components
self.symbols = dict()
self.reset_symbols()

def reset_symbols(self):
"""Reset the symbols attribute to default values
Arguments:
Returns:
Raises:
"""
self.symbols = default_symbols

def loadSBMLFile(self, SBMLFile):
"""Parse the provided SBML file.
def process_document(self):
"""Validate and simplify document.
Arguments:
SBMLFile: path to SBML file @type str
Returns:
Raises:
"""

self.SBMLreader = sbml.SBMLReader()
self.sbml_doc = self.SBMLreader.readSBML(SBMLFile)

# Ensure we got a valid SBML model, otherwise further processing
# might lead to undefined results
self.sbml_doc.validateSBML()
Expand All @@ -149,7 +152,17 @@ def loadSBMLFile(self, SBMLFile):
# check the error log just once after all conversion/validation calls.
checkLibSBMLErrors(self.sbml_doc, self.show_sbml_warnings)

self.sbml = self.sbml_doc.getModel()
def reset_symbols(self):
"""Reset the symbols attribute to default values
Arguments:
Returns:
Raises:
"""
self.symbols = default_symbols

def sbml2amici(self,
modelName,
Expand Down
16 changes: 8 additions & 8 deletions src/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,19 +489,19 @@ int Model::setParametersByNameRegex(std::string const& par_name_regex, realtype
return n_found;
}

bool Model::hasStateIds() const { return nx_rdata && !getStateIds().empty(); }
bool Model::hasStateIds() const { return nx_rdata == 0 || !getStateIds().empty(); }

std::vector<std::string> Model::getStateIds() const {
return std::vector<std::string>();
}

bool Model::hasFixedParameterIds() const { return nk() && !getFixedParameterIds().empty(); }
bool Model::hasFixedParameterIds() const { return nk() == 0 || !getFixedParameterIds().empty(); }

std::vector<std::string> Model::getFixedParameterIds() const {
return std::vector<std::string>();
}

bool Model::hasObservableIds() const { return ny && !getObservableIds().empty(); }
bool Model::hasObservableIds() const { return ny == 0 || !getObservableIds().empty(); }

std::vector<std::string> Model::getObservableIds() const {
return std::vector<std::string>();
Expand Down Expand Up @@ -794,23 +794,23 @@ int Model::plist(int pos) const{
return plist_.at(pos);
}

bool Model::hasParameterNames() const { return np() && !getParameterNames().empty(); }
bool Model::hasParameterNames() const { return np() == 0 || !getParameterNames().empty(); }

std::vector<std::string> Model::getParameterNames() const { return std::vector<std::string>(); }

bool Model::hasStateNames() const { return nx_rdata && !getStateNames().empty(); }
bool Model::hasStateNames() const { return nx_rdata == 0 || !getStateNames().empty(); }

std::vector<std::string> Model::getStateNames() const { return std::vector<std::string>(); }

bool Model::hasFixedParameterNames() const { return nk() && !getFixedParameterNames().empty(); }
bool Model::hasFixedParameterNames() const { return nk() == 0 || !getFixedParameterNames().empty(); }

std::vector<std::string> Model::getFixedParameterNames() const { return std::vector<std::string>(); }

bool Model::hasObservableNames() const { return ny && !getObservableNames().empty(); }
bool Model::hasObservableNames() const { return ny == 0 || !getObservableNames().empty(); }

std::vector<std::string> Model::getObservableNames() const { return std::vector<std::string>(); }

bool Model::hasParameterIds() const { return np() && !getParameterIds().empty(); }
bool Model::hasParameterIds() const { return np() == 0 || !getParameterIds().empty(); }

std::vector<std::string> Model::getParameterIds() const {
return std::vector<std::string>();
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.10.0
0.10.1

0 comments on commit fb033df

Please sign in to comment.