# Equations class

(Shortest import: `from brian2 import Equations)`

class brian2.equations.equations.Equations(eqns, **kwds)

  Bases: `Hashable`, `Mapping`

  Container that stores equations from which models can be created.

  String equations can be of any of the following forms:

  1. `dx/dt = f : unit (flags)` (differential equation)

  2. `x = f : unit (flags)` (equation)

  3. `x : unit (flags)` (parameter)

  String equations can span several lines and contain Python-style comments starting with `#`

  Parameters:

    eqs : `str` or list of `SingleEquation` objects

    > A multiline string of equations (see above) – for internal purposes also a list of `SingleEquation` objects can be given. This is done for example when adding new equations to implement the refractory mechanism. Note that in this case the variable names are not checked to allow for “internal names”, starting with an underscore.

    kwds: keyword arguments :

    > Keyword arguments can be used to replace variables in the equation string. Arguments have to be of the form `varname=replacement`, where `varname` has to correspond to a variable name in the given equation. The replacement can be either a string (replacing a name with a new name, e.g. `tau='tau_e'`) or a value (replacing the variable name with the value, e.g. `tau=tau_e` or `tau=10*ms`).

  Attributes

  `_substituted_expressions` | Cache for equations with the subexpressions substituted
  `dependencies` | Calculate the dependencies of all differential equations and subexpressions.
  `diff_eq_expressions` | A list of (variable name, expression) tuples of all differential equations.
  `diff_eq_names` | All differential equation names.
  `dimensions` | Dictionary of all internal variables and their corresponding physical dimensions.
  `eq_expressions` | A list of (variable name, expression) tuples of all equations.
  `eq_names` | All equation names (including subexpressions).
  `identifier_checks` | A set of functions that are used to check identifiers (class attribute).
  `identifiers` | Set of all identifiers used in the equations, excluding the variables defined in the equations
  `is_stochastic` | Whether the equations are stochastic.
  `names` | All variable names defined in the equations.
  `ordered` | A list of all equations, sorted according to the order in which they should be updated
  `parameter_names` | All parameter names.
  `stochastic_type` | Returns the type of stochastic differential equations (additivive or multiplicative).
  `stochastic_variables` |
  `subexpr_names` | All subexpression names.

  Methods

  `check_flags`(allowed_flags[, incompatible_flags]) | Check the list of flags.
  `check_identifier`(identifier) | Perform all the registered checks.
  `check_identifiers`() | Check all identifiers for conformity with the rules.
  `check_units`(group, run_namespace) | Check all the units for consistency.
  `get_substituted_expressions`([variables, ...]) | Return a list of `(varname, expr)` tuples, containing all differential equations (and optionally subexpressions) with all the subexpression variables substituted with the respective expressions.
  `register_identifier_check`(func) | Register a function for checking identifiers.
  `substitute`(**kwds) |

  Details

  _substituted_expressions

    Cache for equations with the subexpressions substituted

  dependencies

    Calculate the dependencies of all differential equations and subexpressions.

  diff_eq_expressions

    A list of (variable name, expression) tuples of all differential equations.

  diff_eq_names

    All differential equation names.

  dimensions

    Dictionary of all internal variables and their corresponding physical dimensions.

  eq_expressions

    A list of (variable name, expression) tuples of all equations.

  eq_names

    All equation names (including subexpressions).

  identifier_checks

    A set of functions that are used to check identifiers (class attribute). Functions can be registered with the static method `Equations.register_identifier_check` and will be automatically used when checking identifiers

  identifiers

    Set of all identifiers used in the equations, excluding the variables defined in the equations

  is_stochastic

    Whether the equations are stochastic.

  names

    All variable names defined in the equations.

  ordered

    A list of all equations, sorted according to the order in which they should be updated

  parameter_names

    All parameter names.

  stochastic_type

    Returns the type of stochastic differential equations (additivive or multiplicative). The system is only classified as `additive` if all equations have only additive noise (or no noise).

    Returns:

      type : str

      > Either `None` (no noise variables), `'additive'` (factors for all noise variables are independent of other state variables or time), `'multiplicative'` (at least one of the noise factors depends on other state variables and/or time).

  stochastic_variables
  subexpr_names

    All subexpression names.

  check_flags(allowed_flags, incompatible_flags=None)

    Check the list of flags.

    Parameters:

      allowed_flags : dict

      > A dictionary mapping equation types (PARAMETER, DIFFERENTIAL_EQUATION, SUBEXPRESSION) to a list of strings (the allowed flags for that equation type)

      incompatible_flags : list of tuple

      > A list of flag combinations that are not allowed for the same equation.

      Notes :

      —– :

      Not specifying allowed flags for an equation type is the same as :

      specifying an empty list for it. :

    Raises

    `ValueError`

      If any flags are used that are not allowed.

  static check_identifier(identifier)

    Perform all the registered checks. Checks can be registered via `Equations.register_identifier_check`.

    Parameters:

      identifier : str

      > The identifier that should be checked

    Raises

    `ValueError`

      If any of the registered checks fails.

  check_identifiers()

    Check all identifiers for conformity with the rules.

    Raises

    `ValueError`

      If an identifier does not conform to the rules.

    See also

    `Equations.check_identifier`

      The function that is called for each identifier.

  check_units(group, run_namespace)

    Check all the units for consistency.

    Parameters:

      group : `Group`

      > The group providing the context

      run_namespace : dict-like, optional

      > An additional namespace that is used for variable lookup (if not defined, the implicit namespace of local variables is used).

      level : int, optional

      > How much further to go up in the stack to find the calling frame

    Raises

    `DimensionMismatchError`

      In case of any inconsistencies.

  get_substituted_expressions(variables=None, include_subexpressions=False)

    Return a list of `(varname, expr)` tuples, containing all differential equations (and optionally subexpressions) with all the subexpression variables substituted with the respective expressions.

    Parameters:

      variables : dict, optional

      > A mapping of variable names to `Variable`/`Function` objects.

      include_subexpressions : bool

      > Whether also to return substituted subexpressions. Defaults to `False`.

    Returns:

      expr_tuples : list of (str, `CodeString`)

      > A list of `(varname, expr)` tuples, where `expr` is a `CodeString` object with all subexpression variables substituted with the respective expression.

  static register_identifier_check(func)

    Register a function for checking identifiers.

    Parameters:

      func : callable

      > The function has to receive a single argument, the name of the identifier to check, and raise a ValueError if the identifier violates any rule.

  substitute(**kwds)

## Tutorials and examples using this

- Example COBAHH

- Example IF_curve_Hodgkin_Huxley

- Example advanced/COBAHH_approximated

- Example advanced/float_32_64_benchmark

- Example frompapers/Clopath_et_al_2010_homeostasis

- Example frompapers/Clopath_et_al_2010_no_homeostasis

- Example frompapers/Destexhe_et_al_1998

- Example frompapers/Diehl_Cook_2015

- Example frompapers/Diesmann_et_al_1999

- Example frompapers/Hindmarsh_Rose_1984

- Example frompapers/Jansen_Rit_1995_single_column

- Example frompapers/Rossant_et_al_2011bis