amici.de_model
Symbolic differential equation model.
Classes
|
Defines a Differential Equation as set of ModelQuantities. |
- class amici.de_model.DEModel(verbose=False, simplify=<function _default_simplify>, cache_simplify=False)[source]
Defines a Differential Equation as set of ModelQuantities. This class provides general purpose interfaces to compute arbitrary symbolic derivatives that are necessary for model simulation or sensitivity computation.
- Variables:
_differential_states – list of differential state variables
_algebraic_states – list of algebraic state variables
_observables – list of observables
_event_observables – list of event observables
_sigma_ys – list of sigmas for observables
_sigma_zs – list of sigmas for event observables
_parameters – list of parameters
_log_likelihood_ys – list of loglikelihoods for observables
_log_likelihood_zs – list of loglikelihoods for event observables
_log_likelihood_rzs – list of loglikelihoods for event observable regularizations
_expressions – list of expressions instances
_conservation_laws – 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 the names of symbolic identifiers of the symbolic variables of the model
_syms – carries symbolic identifiers of the symbolic variables of the model
_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
OEModel._generate_equation()
)_variable_prototype – defines the attribute from which a variable should be generated via list comprehension (see
DEModel._generate_symbol()
)_value_prototype – defines the attribute from which a value should be generated via list comprehension (see
DEModel._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
DEModel.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.
_static_indices – dict of lists list of indices of static variables for different model entities.
_z2event – list of event indices for each event observable
- __init__(verbose=False, simplify=<function _default_simplify>, cache_simplify=False)[source]
Create a new DEModel instance.
- Parameters:
verbose (
bool
|int
|None
) – verbosity level for logging, True/False default tologging.DEBUG
/logging.ERROR
simplify (
collections.abc.Callable
|None
) – seeDEModel._simplify()
cache_simplify (
bool
) – Whether to cache calls to the simplify method. Can e.g. decrease import times for models with events.
- add_component(component, insert_first=False)[source]
Adds a new ModelQuantity to the model.
- Parameters:
component (
amici.de_model_components.ModelQuantity
) – model quantity to be addedinsert_first (
bool
|None
) – 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, coefficients)[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\))coefficients (
dict
[sympy.core.symbol.Symbol
,sympy.core.expr.Expr
]) – Dictionary of coefficients {x_i: a_i}
- Return type:
- add_spline(spline, spline_expr)[source]
Add a spline to the model.
- Parameters:
spline (
amici.splines.AbstractSpline
) – Spline instance to be addedspline_expr (
sympy.core.expr.Expr
) – Sympy function representation of spline fromspline.ode_model_symbol()
.
- 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:
list
[sympy.core.numbers.Number
] |list
[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.de_model_components.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 RHS and initial conditions.
- Return type:
- generate_basic_variables()[source]
Generates the symbolic identifiers for all variables in
DEModel._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
- get_conservation_laws()[source]
Returns a list of states with conservation law set
- Return type:
- Returns:
list of state identifiers
- get_observable_transformations()[source]
List of observable transformations
- Return type:
- Returns:
list of transformations
- num_cons_law()[source]
Number of conservation laws.
- Return type:
- Returns:
number of conservation laws
- num_eventobs()[source]
Number of Event Observables.
- Return type:
- Returns:
number of event observable symbols
- num_events()[source]
Total number of Events (those for which root-functions are added and those without).
- Return type:
- Returns:
number of events
- num_events_solver()[source]
Number of Events.
- Return type:
- Returns:
number of event symbols (length of the root vector in AMICI)
- 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_rdata()[source]
Number of states.
- Return type:
- Returns:
number of state variable symbols
- num_states_solver()[source]
Number of states after applying conservation laws.
- Return type:
- Returns:
number of state variable symbols
- parse_events()[source]
This function checks the right-hand side for roots of Heaviside functions or events, collects the roots, removes redundant roots, and replaces the formulae of the found roots by identifiers of AMICI’s Heaviside function implementation in the right-hand side
- Return type:
- 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:
list
[sympy.core.numbers.Number
] |list
[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, force_generate=True)[source]
Returns (and constructs if necessary) the sparsified identifiers for a sparsified symbolic variable.
- 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
- static_indices(name)[source]
Returns the indices of static expressions in the given model entity.
Static expressions are those that do not depend on time, neither directly nor indirectly.
- sym(name)[source]
Returns (and constructs if necessary) the identifiers for a symbolic entity.
- Parameters:
name (
str
) – name of the symbolic variable- Return type:
- Returns:
matrix of symbolic identifiers
- 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.