amici.ode_export

C++ Export

This module provides all necessary functionality specify an ODE 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().

Classes

ODEExporter(ode_model[, outdir, verbose, ...])

The ODEExporter class generates AMICI C++ files for ODE model as defined in symbolic expressions.

ODEModel([verbose, simplify, cache_simplify])

Defines an Ordinary Differential Equation as set of ModelQuantities.

TemplateAmici(template)

Template format used in AMICI (see string.Template for more details).

Functions Summary

apply_template(source_file, target_file, ...)

Load source file, apply template substitution as provided in templateData and save as targetFile.

get_function_extern_declaration(fun, name)

Constructs the extern function declaration for a given function

get_model_override_implementation(fun, name)

Constructs amici::Model::* override implementation for a given function

get_sunindex_extern_declaration(fun, name, ...)

Constructs the function declaration for an index function of a given function

get_sunindex_override_implementation(fun, ...)

Constructs the amici::Model function implementation for an index function of a given function

is_valid_identifier(x)

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

remove_typedefs(signature)

Strips typedef info from a function signature

smart_is_zero_matrix(x)

A faster implementation of sympy's is_zero_matrix

smart_jacobian(eq, sym_var)

Wrapper around symbolic jacobian with some additional checks that reduce computation time for large matrices

smart_multiply(x, y)

Wrapper around symbolic multiplication with some additional checks that reduce computation time for large matrices

var_in_function_signature(name, varname)

Checks if the values for a symbolic variable is passed in the signature of a function

Functions

amici.ode_export.apply_template(source_file, target_file, template_data)[source]

Load source file, apply template substitution as provided in templateData and save as targetFile.

Parameters
  • source_file (str) – relative or absolute path to template file

  • target_file (str) – relative or absolute path to output file

  • template_data (typing.Dict[str, str]) – template keywords to substitute (key is template variable without TemplateAmici.delimiter)

Return type

None

amici.ode_export.get_function_extern_declaration(fun, name)[source]

Constructs the extern function declaration for a given function

Parameters
  • fun (str) – function name

  • name (str) – model name

Return type

str

Returns

C++ function definition string

amici.ode_export.get_model_override_implementation(fun, name, nobody=False)[source]

Constructs amici::Model::* override implementation for a given function

Parameters
  • fun (str) – function name

  • name (str) – model name

  • nobody (bool) – whether the function has a nontrivial implementation

Return type

str

Returns

C++ function implementation string

amici.ode_export.get_sunindex_extern_declaration(fun, name, indextype)[source]

Constructs the function declaration for an index function of a given function

Parameters
  • fun (str) – function name

  • name (str) – model name

  • indextype (str) – index function {‘colptrs’, ‘rowvals’}

Return type

str

Returns

C++ function declaration string

amici.ode_export.get_sunindex_override_implementation(fun, name, indextype, nobody=False)[source]

Constructs the amici::Model function implementation for an index function of a given function

Parameters
  • fun (str) – function name

  • name (str) – model name

  • indextype (str) – index function {‘colptrs’, ‘rowvals’}

  • nobody (bool) – whether the corresponding function has a nontrivial implementation

Return type

str

Returns

C++ function implementation string

amici.ode_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.ode_export.remove_typedefs(signature)[source]

Strips typedef info from a function signature

Parameters

signature (str) – function signature

Return type

str

Returns

string that can be used to construct function calls with the same variable names and ordering as in the function signature

amici.ode_export.smart_is_zero_matrix(x)[source]

A faster implementation of sympy’s is_zero_matrix

Avoids repeated indexer type checks and double iteration to distinguish False/None. Found to be about 100x faster for large matrices.

Parameters

x (typing.Union[sympy.matrices.dense.MutableDenseMatrix, sympy.matrices.sparse.MutableSparseMatrix]) – Matrix to check

Return type

bool

amici.ode_export.smart_jacobian(eq, sym_var)[source]

Wrapper around symbolic jacobian with some additional checks that reduce computation time for large matrices

Parameters
Return type

sympy.matrices.sparse.MutableSparseMatrix

Returns

jacobian of eq wrt sym_var

amici.ode_export.smart_multiply(x, y)[source]

Wrapper around symbolic multiplication with some additional checks that reduce computation time for large matrices

Parameters
Return type

typing.Union[sympy.matrices.dense.MutableDenseMatrix, sympy.matrices.sparse.MutableSparseMatrix]

Returns

product

amici.ode_export.var_in_function_signature(name, varname)[source]

Checks if the values for a symbolic variable is passed in the signature of a function

Parameters
  • name (str) – name of the function

  • varname (str) – name of the symbolic variable

Return type

bool

Returns

boolean indicating whether the variable occurs in the function signature