amici.ode_export.ODEModel¶
-
class
amici.ode_export.
ODEModel
(verbose=False, simplify=<function powsimp>)[source]¶ Defines an Ordinary Differential Equation as set of ModelQuantities. This class provides general purpose interfaces to ompute arbitrary symbolic derivatives that are necessary for model simulation or sensitivity computation
- Variables
_states – list of state variables
_observables – list of observables
_sigmays – list of sigmays
_parameters – list of parameters
_loglikelihoods – list of loglikelihoods
_expressions – list of expressions instances
_conservationlaws – list of conservation laws
_symboldim_funs – define functions that compute model dimensions, these are functions as the underlying symbolic expressions have not been populated at compile time
_eqs – carries symbolic formulas of the symbolic variables of the model
_sparseeqs – carries linear list of all symbolic formulas for sparsified variables
_vals – carries numeric values of symbolic identifiers of the symbolic variables of the model
_names – carries names of symbolic identifiers of the symbolic variables of the model
_syms – carries symbolic identifiers of the symbolic variables of the model
_strippedsyms – carries symbolic identifiers that were stripped of additional class information
_sparsesyms – carries linear list of all symbolic identifiers for sparsified variables
_colptrs – carries column pointers for sparsified variables. See SUNMatrixContent_Sparse definition in <sunmatrix/sunmatrix_sparse.h>
_rowvals – carries row values for sparsified variables. See SUNMatrixContent_Sparse definition in <sunmatrix/sunmatrix_sparse.h>
_equation_prototype – defines the attribute from which an equation should be generated via list comprehension (see
ODEModel._generate_equation()
)_variable_prototype – defines the attribute from which a variable should be generated via list comprehension (see
ODEModel._generate_symbol()
)_value_prototype – defines the attribute from which a value should be generated via list comprehension (see
ODEModel._generate_value()
)_total_derivative_prototypes – defines how a total derivative equation is computed for an equation, key defines the name and values should be arguments for ODEModel.totalDerivative()
_lock_total_derivative – add chainvariables to this set when computing total derivative from a partial derivative call to enforce a partial derivative in the next recursion. prevents infinite recursion
_simplify – If not None, this function will be used to simplify symbolic derivative expressions. Receives sympy expressions as only argument. To apply multiple simplifications, wrap them in a lambda expression.
_x0_fixedParameters_idx – Index list of subset of states for which x0_fixedParameters was computed
_w_recursion_depth – recursion depth in w, quantified as nilpotency of dwdw
_has_quadratic_nllh – whether all observables have a gaussian noise model, i.e. whether res and FIM make sense.
-
__init__
(verbose=False, simplify=<function powsimp>)[source] Create a new ODEModel instance.
- Parameters
verbose (
typing.Union
[bool
,int
,None
]) – verbosity level for logging, True/False default tologging.DEBUG
/logging.ERROR
simplify (
typing.Optional
[typing.Callable
]) – seeODEModel._simplify()
Methods Summary
__init__
([verbose, simplify])Create a new ODEModel instance.
add_component
(component[, insert_first])Adds a new ModelQuantity to the model.
add_conservation_law
(state, total_abundance, …)Adds a new conservation law to the model.
colptrs
(name)Returns (and constructs if necessary) the column pointers for a sparsified symbolic variable.
Checks whether a conservation law has multiple species or it just defines one constant species
eq
(name)Returns (and constructs if necessary) the formulas for a symbolic entity.
Returns list of free symbols that appear in ODE rhs and initial conditions.
generate_basic_variables
(*[, from_sbml])Generates the symbolic identifiers for all variables in ODEModel.variable_prototype
get_appearance_counts
(idxs)Counts how often a state appears in the time derivative of another state and expressions for a subset of states
Returns a list of states with conservation law set
import_from_sbml_importer
(si[, compute_cls])Imports a model specification from a
amici.sbml_import.SbmlImporter
instance.name
(name)Returns (and constructs if necessary) the names of a symbolic variable
Number of conservation laws.
Number of Constants.
num_expr
()Number of Expressions.
num_obs
()Number of Observables.
num_par
()Number of Parameters.
Number of solver states which would be reinitialized after preequilibration
Number of states.
Number of states after applying conservation laws.
rowvals
(name)Returns (and constructs if necessary) the row values for a sparsified symbolic variable.
sparseeq
(name)Returns (and constructs if necessary) the sparsified formulas for a sparsified symbolic variable.
sparsesym
(name)Returns (and constructs if necessary) the sparsified identifiers for a sparsified symbolic variable.
Checks whether the state at specified index has a conservation law set
Checks whether the state at specified index has a fixed parameter initial condition
Checks whether the temporal derivative of the state is zero
sym
(name[, stripped])Returns (and constructs if necessary) the identifiers for a symbolic entity.
Returns a list of names of generated symbolic variables
sym_or_eq
(name, varname)Returns symbols or equations depending on whether a given variable appears in the function signature or not.
val
(name)Returns (and constructs if necessary) the numeric values of a symbolic entity
Methods
-
__init__
(verbose=False, simplify=<function powsimp>)[source]¶ Create a new ODEModel instance.
- Parameters
verbose (
typing.Union
[bool
,int
,None
]) – verbosity level for logging, True/False default tologging.DEBUG
/logging.ERROR
simplify (
typing.Optional
[typing.Callable
]) – seeODEModel._simplify()
-
add_component
(component, insert_first=False)[source]¶ Adds a new ModelQuantity to the model.
- Parameters
component (
amici.ode_export.ModelQuantity
) – model quantity to be addedinsert_first (
typing.Optional
[bool
]) – whether to add quantity first or last, relevant when components may refer to other components of the same type.
- Return type
-
add_conservation_law
(state, total_abundance, state_expr, abundance_expr)[source]¶ Adds a new conservation law to the model. A conservation law is defined by the conserved quantity T = sum_i(a_i * x_i), where a_i are coefficients and x_i are different state variables.
- Parameters
state (
sympy.core.symbol.Symbol
) – symbolic identifier of the state that should be replaced by the conservation law (x_j)total_abundance (
sympy.core.symbol.Symbol
) – symbolic identifier of the total abundance (T/a_j)state_expr (
sympy.core.expr.Expr
) – symbolic algebraic formula that replaces the the state. This is used to compute the numeric value of of state during simulations. x_j = T/a_j - sum_i≠j(a_i * x_i)/a_jabundance_expr (
sympy.core.expr.Expr
) – symbolic algebraic formula that computes the value of the conserved quantity. This is used to update the numeric value for total_abundance after (re-)initialization. T/a_j = sum_i≠j(a_i * x_i)/a_j + x_j
- Return type
-
colptrs
(name)[source]¶ Returns (and constructs if necessary) the column pointers for a sparsified symbolic variable.
- Parameters
name (
str
) – name of the symbolic variable- Return type
typing.Union
[typing.List
[sympy.core.numbers.Number
],typing.List
[typing.List
[sympy.core.numbers.Number
]]]- Returns
list containing the column pointers
-
conservation_law_has_multispecies
(tcl)[source]¶ Checks whether a conservation law has multiple species or it just defines one constant species
- Parameters
tcl (
amici.ode_export.ConservationLaw
) – conservation law- Return type
- Returns
boolean indicating if conservation_law is not None
-
eq
(name)[source]¶ Returns (and constructs if necessary) the formulas for a symbolic entity.
- Parameters
name (
str
) – name of the symbolic variable- Return type
- Returns
matrix of symbolic formulas
-
free_symbols
()[source]¶ Returns list of free symbols that appear in ODE rhs and initial conditions.
- Return type
-
generate_basic_variables
(*, from_sbml=False)[source]¶ Generates the symbolic identifiers for all variables in ODEModel.variable_prototype
- Return type
-
get_appearance_counts
(idxs)[source]¶ Counts how often a state appears in the time derivative of another state and expressions for a subset of states
- Parameters
idxs (
typing.List
[int
]) – list of state indices for which counts are to be computed- Return type
- Returns
list of counts for the states ordered according to the provided indices
-
get_conservation_laws
()[source]¶ Returns a list of states with conservation law set
- Return type
typing.List
[typing.Tuple
[sympy.core.symbol.Symbol
,sympy.core.basic.Basic
]]- Returns
list of state identifiers
-
import_from_sbml_importer
(si, compute_cls=True)[source]¶ Imports a model specification from a
amici.sbml_import.SbmlImporter
instance.- Parameters
si (
amici.sbml_import.SbmlImporter
) – imported SBML model- Return type
-
name
(name)[source]¶ Returns (and constructs if necessary) the names of a symbolic variable
- Parameters
name (
str
) – name of the symbolic variable- Return type
- Returns
list of names
-
num_cons_law
()[source]¶ Number of conservation laws.
- Return type
- Returns
number of conservation laws
-
num_state_reinits
()[source]¶ Number of solver states which would be reinitialized after preequilibration
- Return type
- Returns
number of state variable symbols with reinitialization
-
num_states_solver
()[source]¶ Number of states after applying conservation laws.
- Return type
- Returns
number of state variable symbols
-
rowvals
(name)[source]¶ Returns (and constructs if necessary) the row values for a sparsified symbolic variable.
- Parameters
name (
str
) – name of the symbolic variable- Return type
typing.Union
[typing.List
[sympy.core.numbers.Number
],typing.List
[typing.List
[sympy.core.numbers.Number
]]]- Returns
list containing the row values
-
sparseeq
(name)[source]¶ Returns (and constructs if necessary) the sparsified formulas for a sparsified symbolic variable.
- Parameters
name – name of the symbolic variable
- Return type
- Returns
linearized matrix containing the symbolic formulas
-
sparsesym
(name)[source]¶ Returns (and constructs if necessary) the sparsified identifiers for a sparsified symbolic variable.
- Parameters
name (
str
) – name of the symbolic variable- Return type
- Returns
linearized Matrix containing the symbolic identifiers
-
state_has_conservation_law
(ix)[source]¶ Checks whether the state at specified index has a conservation law set
-
state_has_fixed_parameter_initial_condition
(ix)[source]¶ Checks whether the state at specified index has a fixed parameter initial condition
-
sym
(name, stripped=False)[source]¶ Returns (and constructs if necessary) the identifiers for a symbolic entity.
- Parameters
name (
str
) – name of the symbolic variablestripped (
typing.Optional
[bool
]) – should additional class information be stripped from the symbolic variables (default=False)
- Return type
- Returns
matrix of symbolic identifiers
-
sym_names
()[source]¶ Returns a list of names of generated symbolic variables
- Return type
- Returns
list of names
-
sym_or_eq
(name, varname)[source]¶ Returns symbols or equations depending on whether a given variable appears in the function signature or not.
- Parameters
- Return type
- Returns
the variable symbols if the variable is part of the signature and the variable equations otherwise.