amici.de_model

Symbolic differential equation model.

Classes

DEModel([verbose, simplify, cache_simplify])

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 to logging.DEBUG/logging.ERROR

  • simplify (collections.abc.Callable | None) – see DEModel._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:
Return type:

None

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:
Return type:

None

add_spline(spline, spline_expr)[source]

Add a spline to the model.

Parameters:
Return type:

None

algebraic_states()[source]

Get all algebraic states.

Return type:

list[amici.de_model_components.AlgebraicState]

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:

bool

Returns:

boolean indicating if conservation_law is not None

conservation_laws()[source]

Get all conservation laws.

Return type:

list[amici.de_model_components.ConservationLaw]

constants()[source]

Get all constants.

Return type:

list[amici.de_model_components.Constant]

differential_states()[source]

Get all differential states.

Return type:

list[amici.de_model_components.DifferentialState]

dynamic_indices(name)[source]

Return the indices of dynamic expressions in the given model entity.

Parameters:

name (str) – Name of the model entity.

Return type:

list[int]

Returns:

List of indices of dynamic expressions.

eq(name)[source]

Returns (and constructs if necessary) the formulas for a symbolic entity.

Parameters:

name (str) – name of the symbolic variable

Return type:

sympy.matrices.dense.MutableDenseMatrix

Returns:

matrix of symbolic formulas

event_observables()[source]

Get all event observables.

Return type:

list[amici.de_model_components.EventObservable]

events()[source]

Get all events.

Return type:

list[amici.de_model_components.Event]

expressions()[source]

Get all expressions.

Return type:

list[amici.de_model_components.Expression]

free_symbols()[source]

Returns list of free symbols that appear in RHS and initial conditions.

Return type:

set[sympy.core.basic.Basic]

generate_basic_variables()[source]

Generates the symbolic identifiers for all variables in DEModel._variable_prototype

Return type:

None

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 (list[int]) – list of state indices for which counts are to be computed

Return type:

list[int]

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:

list[tuple[sympy.core.symbol.Symbol, sympy.core.expr.Expr]]

Returns:

list of state identifiers

get_observable_transformations()[source]

List of observable transformations

Return type:

list[amici.import_utils.ObservableTransformation]

Returns:

list of transformations

get_solver_indices()[source]

Returns a mapping that maps rdata species indices to solver indices

Return type:

dict[int, int]

Returns:

dictionary mapping rdata species indices to solver indices

is_ode()[source]

Check if model is ODE model.

Return type:

bool

log_likelihood_rzs()[source]

Get all event observable regularization log likelihoods.

Return type:

list[amici.de_model_components.LogLikelihoodRZ]

log_likelihood_ys()[source]

Get all observable log likelihoodss.

Return type:

list[amici.de_model_components.LogLikelihoodY]

log_likelihood_zs()[source]

Get all event observable log likelihoods.

Return type:

list[amici.de_model_components.LogLikelihoodZ]

name(name)[source]

Returns (and constructs if necessary) the names of a symbolic variable

Parameters:

name (str) – name of the symbolic variable

Return type:

list[str]

Returns:

list of names

num_cons_law()[source]

Number of conservation laws.

Return type:

int

Returns:

number of conservation laws

num_const()[source]

Number of Constants.

Return type:

int

Returns:

number of constant symbols

num_eventobs()[source]

Number of Event Observables.

Return type:

int

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:

int

Returns:

number of events

num_events_solver()[source]

Number of Events.

Return type:

int

Returns:

number of event symbols (length of the root vector in AMICI)

num_expr()[source]

Number of Expressions.

Return type:

int

Returns:

number of expression symbols

num_obs()[source]

Number of Observables.

Return type:

int

Returns:

number of observable symbols

num_par()[source]

Number of Parameters.

Return type:

int

Returns:

number of parameter symbols

num_state_reinits()[source]

Number of solver states which would be reinitialized after preequilibration

Return type:

int

Returns:

number of state variable symbols with reinitialization

num_states_rdata()[source]

Number of states.

Return type:

int

Returns:

number of state variable symbols

num_states_solver()[source]

Number of states after applying conservation laws.

Return type:

int

Returns:

number of state variable symbols

observables()[source]

Get all observables.

Return type:

list[amici.de_model_components.Observable]

parameters()[source]

Get all parameters.

Return type:

list[amici.de_model_components.Parameter]

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:

None

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

sigma_ys()[source]

Get all observable sigmas.

Return type:

list[amici.de_model_components.SigmaY]

sigma_zs()[source]

Get all event observable sigmas.

Return type:

list[amici.de_model_components.SigmaZ]

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:

sympy.matrices.dense.MutableDenseMatrix

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.

Parameters:
  • name (str) – name of the symbolic variable

  • force_generate (bool) – whether the symbols should be generated if not available

Return type:

list[str]

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

Parameters:

ix (int) – state index

Return type:

bool

Returns:

boolean indicating if conservation_law is not None

state_has_fixed_parameter_initial_condition(ix)[source]

Checks whether the state at specified index has a fixed parameter initial condition

Parameters:

ix (int) – state index

Return type:

bool

Returns:

boolean indicating if any of the initial condition free variables is contained in the model constants

state_is_constant(ix)[source]

Checks whether the temporal derivative of the state is zero

Parameters:

ix (int) – state index

Return type:

bool

Returns:

boolean indicating if constant over time

states()[source]

Get all states.

Return type:

list[amici.de_model_components.State]

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.

Parameters:

name (str) – Name of the model entity.

Return type:

list[int]

Returns:

List of indices of static expressions.

sym(name)[source]

Returns (and constructs if necessary) the identifiers for a symbolic entity.

Parameters:

name (str) – name of the symbolic variable

Return type:

sympy.matrices.dense.MutableDenseMatrix

Returns:

matrix of symbolic identifiers

sym_names()[source]

Returns a list of names of generated symbolic variables

Return type:

list[str]

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:
  • name (str) – name of function for which the signature should be checked

  • varname (str) – name of the variable which should be contained in the function signature

Return type:

sympy.matrices.dense.MutableDenseMatrix

Returns:

the variable symbols if the variable is part of the signature and the variable equations otherwise.

val(name)[source]

Returns (and constructs if necessary) the numeric values of a symbolic entity

Parameters:

name (str) – name of the symbolic variable

Return type:

list[sympy.core.numbers.Number]

Returns:

list containing the numeric values