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

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.

conservation_law_has_multispecies(tcl)

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.

free_symbols()

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

get_conservation_laws()

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

num_cons_law()

Number of conservation laws.

num_const()

Number of Constants.

num_events()

Number of Events.

num_expr()

Number of Expressions.

num_obs()

Number of Observables.

num_par()

Number of Parameters.

num_state_reinits()

Number of solver states which would be reinitialized after preequilibration

num_states_rdata()

Number of states.

num_states_solver()

Number of states after applying conservation laws.

parse_events()

This functions 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

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[, force_generate])

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

state_has_conservation_law(ix)

Checks whether the state at specified index has a conservation law set

state_has_fixed_parameter_initial_condition(ix)

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

state_is_constant(ix)

Checks whether the temporal derivative of the state is zero

sym(name[, stripped])

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

sym_names()

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
add_component(component, insert_first=False)[source]

Adds a new ModelQuantity to the model.

Parameters
Return type

None

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_j

  • abundance_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

None

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

bool

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

sympy.matrices.dense.MutableDenseMatrix

Returns

matrix of symbolic formulas

free_symbols()[source]

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

Return type

typing.Set[sympy.core.basic.Basic]

generate_basic_variables(*, from_sbml=False)[source]

Generates the symbolic identifiers for all variables in ODEModel.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 (typing.List[int]) – list of state indices for which counts are to be computed

Return type

typing.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

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

None

name(name)[source]

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

Parameters

name (str) – name of the symbolic variable

Return type

typing.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_events()[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

parse_events()[source]

This functions 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

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

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

typing.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

sym(name, stripped=False)[source]

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

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

  • stripped (typing.Optional[bool]) – should additional class information be stripped from the symbolic variables (default=False)

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

typing.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

typing.List[float]

Returns

list containing the numeric values