amici.de_export

C++ Export

This module provides all necessary functionality to specify a differential equation model and generate executable C++ simulation code. The user generally won’t have to directly call any function from this module as this will be done by amici.pysb_import.pysb2amici(), amici.sbml_import.SbmlImporter.sbml2amici() and amici.petab_import.import_model().

Module Attributes

non_unique_id_symbols

list of equations that have ids which may not be unique

CUSTOM_FUNCTIONS

custom c++ function replacements

logger

python log manager

Functions

is_valid_identifier(x)

Check whether x is a valid identifier for conditions, parameters, observables.

Classes

DEExporter(de_model[, outdir, verbose, ...])

The DEExporter class generates AMICI C++ files for a model as defined in symbolic expressions.

amici.de_export.CUSTOM_FUNCTIONS = [{'build_hint': 'Using polygamma requires libboost-math header files.', 'c++': 'boost::math::polygamma', 'include': '#include <boost/math/special_functions/polygamma.hpp>', 'sympy': 'polygamma'}, {'c++': 'amici::heaviside', 'sympy': 'Heaviside'}, {'c++': 'amici::dirac', 'sympy': 'DiracDelta'}]

custom c++ function replacements

class amici.de_export.DEExporter(de_model, outdir=None, verbose=False, assume_pow_positivity=False, compiler=None, allow_reinit_fixpar_initcond=True, generate_sensitivity_code=True, model_name='model')[source]

The DEExporter class generates AMICI C++ files for a model as defined in symbolic expressions.

Variables:
  • model – DE definition

  • verbose – more verbose output if True

  • assume_pow_positivity – if set to true, a special pow function is used to avoid problems with state variables that may become negative due to numerical errors

  • compiler – Absolute path to the compiler executable to be used to build the Python extension, e.g. /usr/bin/clang.

  • functions – carries C++ function signatures and other specifications

  • model_name – name of the model that will be used for compilation

  • model_path – path to the generated model specific files

  • model_swig_path – path to the generated swig files

  • allow_reinit_fixpar_initcond – indicates whether reinitialization of initial states depending on fixedParameters is allowed for this model

  • _build_hints – If the given model uses special functions, this set contains hints for model building.

  • _code_printer – Code printer to generate C++ code

  • generate_sensitivity_code – Specifies whether code for sensitivity computation is to be generated

Note

When importing large models (several hundreds of species or parameters), import time can potentially be reduced by using multiple CPU cores. This is controlled by setting the AMICI_IMPORT_NPROCS environment variable to the number of parallel processes that are to be used (default: 1). Note that for small models this may (slightly) increase import times.

__init__(de_model, outdir=None, verbose=False, assume_pow_positivity=False, compiler=None, allow_reinit_fixpar_initcond=True, generate_sensitivity_code=True, model_name='model')[source]

Generate AMICI C++ files for the DE provided to the constructor.

Parameters:
  • de_model (amici.de_model.DEModel) – DE model definition

  • outdir (pathlib.Path | str | None) – see amici.de_export.DEExporter.set_paths()

  • verbose (bool | int | None) – verbosity level for logging, True/False default to logging.Error/logging.DEBUG

  • assume_pow_positivity (bool | None) – if set to true, a special pow function is used to avoid problems with state variables that may become negative due to numerical errors

  • compiler (str | None) – Absolute path to the compiler executable to be used to build the Python extension, e.g. /usr/bin/clang.

  • allow_reinit_fixpar_initcond (bool | None) – see amici.de_export.DEExporter

  • generate_sensitivity_code (bool | None) – specifies whether code required for sensitivity computation will be generated

  • model_name (str | None) – name of the model to be used during code generation

compile_model()[source]

Compiles the generated code it into a simulatable module

Return type:

None

generate_model_code()[source]

Generates the native C++ code for the loaded model and a Matlab script that can be run to compile a mex file from the C++ code

Return type:

None

set_name(model_name)[source]

Sets the model name

Parameters:

model_name (str) – name of the model (may only contain upper and lower case letters, digits and underscores, and must not start with a digit)

Return type:

None

set_paths(output_dir=None)[source]

Set output paths for the model and create if necessary

Parameters:

output_dir (str | pathlib.Path | None) – relative or absolute path where the generated model code is to be placed. If None, this will default to amici-{self.model_name} in the current working directory. will be created if it does not exist.

Return type:

None

amici.de_export.is_valid_identifier(x)[source]

Check whether x is a valid identifier for conditions, parameters, observables… . Identifiers may only contain upper and lower case letters, digits and underscores, and must not start with a digit.

Parameters:

x (str) – string to check

Return type:

bool

Returns:

True if valid, False otherwise

amici.de_export.logger = <Logger amici.de_export (ERROR)>

python log manager

amici.de_export.non_unique_id_symbols = ['x_rdata', 'y']

list of equations that have ids which may not be unique