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
|
A conservation law defines the absolute the total amount of a (weighted) sum of states |
|
A Constant is a fixed variable in the model with respect to which sensitivities cannot be computed, abbreviated by k |
|
An Expressions is a recurring elements in symbolic formulas. |
|
A LogLikelihood defines the distance between measurements and experiments for a particular observable. |
|
Base class for model components |
|
The ODEExporter class generates AMICI C++ files for ODE model as defined in symbolic expressions. |
|
Defines an Ordinary Differential Equation as set of ModelQuantities. |
|
An Observable links model simulations to experimental measurements, abbreviated by y |
|
A Parameter is a free variable in the model with respect to which sensitivities may be computed, abbreviated by p |
|
A Standard Deviation SigmaY rescales the distance between simulations and measurements when computing residuals or objective functions, abbreviated by sigmay |
|
A State variable defines an entity that evolves with time according to the provided time derivative, abbreviated by x |
|
Template format used in AMICI (see string.template for more details). |
Functions Summary
|
Load source file, apply template substitution as provided in templateData and save as targetFile. |
|
Typecasts the value to sympy.Float if possible, and ensures the value is a symbolic expression. |
|
Generates the sparse symbolic identifiers, symbolic identifiers, sparse matrix, column pointers and row values for a symbolic variable |
|
Generate identifier symbol for a reaction flux. |
|
Generates the appropriate measurement symbol for the provided observable |
|
Constructs the extern function declaration for a given function |
|
Constructs amici::Model::* override implementation for a given function |
|
Constructs the function declaration for an index function of a given function |
Constructs the amici::Model:: function implementation for an index function of a given function |
|
|
Generate code for switch statement |
Check whether x is a valid identifier for conditions, parameters, observables. |
|
|
Strips typedef info from a function signature |
A faster implementation of sympy’s is_zero_matrix |
|
|
Wrapper around symbolic jacobian with some additional checks that reduce computation time for large matrices |
|
Wrapper around symbolic multiplication with some additional checks that reduce computation time for large matrices |
|
Subsitutes expressions completely flattening them out. |
|
Strips pysb info from a |
|
Central function to create symbols with consistent, canonical assumptions |
|
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.
-
amici.ode_export.
cast_to_sym
(value, input_name)[source]¶ Typecasts the value to sympy.Float if possible, and ensures the value is a symbolic expression.
- Parameters
value (
typing.Union
[typing.SupportsFloat
,sympy.core.expr.Expr
,sympy.logic.boolalg.BooleanAtom
]) – value to be castinput_name (
str
) – name of input variable
- Return type
- Returns
typecast value
-
amici.ode_export.
csc_matrix
(matrix, rownames, colnames, identifier=0, pattern_only=False)[source]¶ Generates the sparse symbolic identifiers, symbolic identifiers, sparse matrix, column pointers and row values for a symbolic variable
- Parameters
matrix (
sympy.matrices.dense.MutableDenseMatrix
) – dense matrix to be sparsifiedrownames (
typing.List
[sympy.core.symbol.Symbol
]) – ids of the variable of which the derivative is computed (assuming matrix is the jacobian)colnames (
typing.List
[sympy.core.symbol.Symbol
]) – ids of the variable with respect to which the derivative is computed (assuming matrix is the jacobian)identifier (
typing.Optional
[int
]) – additional identifier that gets appended to symbol names to ensure their uniqueness in outer loopspattern_only (
typing.Optional
[bool
]) – flag for computing sparsity pattern without whole matrix
- Return type
typing.Tuple
[typing.List
[int
],typing.List
[int
],sympy.matrices.dense.MutableDenseMatrix
,typing.List
[str
],sympy.matrices.dense.MutableDenseMatrix
]- Returns
symbol_col_ptrs, symbol_row_vals, sparse_list, symbol_list, sparse_matrix
-
amici.ode_export.
generate_flux_symbol
(reaction_index)[source]¶ Generate identifier symbol for a reaction flux. This function will always return the same unique python object for a given entity.
- Parameters
reaction_index (
int
) – index of the reaction to which the flux corresponds- Return type
- Returns
identifier symbol
-
amici.ode_export.
generate_measurement_symbol
(observable_id)[source]¶ Generates the appropriate measurement symbol for the provided observable
- Parameters
observable_id (
typing.Union
[str
,sympy.core.symbol.Symbol
]) – symbol (or string representation) of the observable- Returns
symbol for the corresponding measurement
-
amici.ode_export.
get_function_extern_declaration
(fun, name)[source]¶ Constructs the extern function declaration for a given function
-
amici.ode_export.
get_model_override_implementation
(fun, name)[source]¶ Constructs amici::Model::* override implementation for a given function
-
amici.ode_export.
get_sunindex_extern_declaration
(fun, name, indextype)[source]¶ Constructs the function declaration for an index function of a given function
-
amici.ode_export.
get_sunindex_override_implementation
(fun, name, indextype)[source]¶ Constructs the amici::Model:: function implementation for an index function of a given function
-
amici.ode_export.
get_switch_statement
(condition, cases, indentation_level=0, indentation_step=' ')[source]¶ Generate code for switch statement
- Parameters
condition (
str
) – Condition for switchcases (
typing.Dict
[int
,typing.List
[str
]]) – Cases as dict with expressions as keys and statement as list of stringsindentation_level (
typing.Optional
[int
]) – indentation levelindentation_step (
typing.Optional
[str
]) – indentation whitespace per level
- Returns
Code for switch expression as list of strings
-
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.
-
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
-
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
eq (
sympy.matrices.dense.MutableDenseMatrix
) – equationsym_var (
sympy.matrices.dense.MutableDenseMatrix
) – differentiation variable
- Return type
- 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
x (
typing.Union
[sympy.matrices.dense.MutableDenseMatrix
,sympy.matrices.sparse.MutableSparseMatrix
]) – educt 1y (
sympy.matrices.dense.MutableDenseMatrix
) – educt 2
- Return type
typing.Union
[sympy.matrices.dense.MutableDenseMatrix
,sympy.matrices.sparse.MutableSparseMatrix
]- Returns
product
-
amici.ode_export.
smart_subs_dict
(sym, subs, field=None, reverse=True)[source]¶ Subsitutes expressions completely flattening them out. Requires sorting of expressions with toposort.
- Parameters
sym (
sympy.core.expr.Expr
) – Symbolic expression in which expressions will be substitutedsubs (
typing.Dict
[sympy.core.symbol.Symbol
,typing.Union
[typing.Dict
[str
,sympy.core.expr.Expr
],sympy.core.expr.Expr
]]) – Substitutionsfield (
typing.Optional
[str
]) – Field of substitution expressions in subs.values(), if applicablereverse (
bool
) – Whether ordering in subs should be reversed. Note that substitution requires the reverse order of what is required for evaluation.
- Return type
- Returns
Substituted symbolic expression
-
amici.ode_export.
strip_pysb
(symbol)[source]¶ Strips pysb info from a
pysb.Component
object- Parameters
symbol (
sympy.core.basic.Basic
) – symbolic expression- Return type
- Returns
stripped expression
-
amici.ode_export.
symbol_with_assumptions
(name)[source]¶ Central function to create symbols with consistent, canonical assumptions
- Parameters
name (
str
) – name of the symbol- Returns
symbol with canonical assumptions