# Variables class

(Shortest import: `from brian2.core.variables import Variables)`

class brian2.core.variables.Variables(owner, default_index='_idx')

  Bases: `Mapping`

  A container class for storing `Variable` objects. Instances of this class are used as the `Group.variables` attribute and can be accessed as (read-only) dictionaries.

  Parameters:

    owner : `Nameable`

    > The object (typically a `Group`) “owning” the variables.

    default_index : str, optional

    > The index to use for the variables (only relevant for `ArrayVariable` and `DynamicArrayVariable`). Defaults to `'_idx'`.

  Attributes

  `indices` | A dictionary given the index name for every array name
  `owner` | A reference to the `Group` owning these variables

  Methods

  `add_arange`(name, size[, start, dtype, ...]) | Add an array, initialized with a range of integers.
  `add_array`(name, size[, dimensions, values, ...]) | Add an array (initialized with zeros).
  `add_arrays`(names, size[, dimensions, dtype, ...]) | Adds several arrays (initialized with zeros) with the same attributes (size, units, etc.).
  `add_auxiliary_variable`(name[, dimensions, ...]) | Add an auxiliary variable (most likely one that is added automatically to abstract code, e.g. `_cond` for a threshold condition), specifying its type and unit for code generation.
  `add_constant`(name, value[, dimensions]) | Add a scalar constant (e.g. the number of neurons `N`).
  `add_dynamic_array`(name, size[, dimensions, ...]) | Add a dynamic array.
  `add_object`(name, obj) | Add an arbitrary Python object.
  `add_reference`(name, group[, varname, index]) | Add a reference to a variable defined somewhere else (possibly under a different name).
  `add_references`(group, varnames[, index]) | Add all `Variable` objects from a name to `Variable` mapping with the same name as in the original mapping.
  `add_referred_subexpression`(name, group, ...) |
  `add_subexpression`(name, expr[, dimensions, ...]) | Add a named subexpression.
  `create_clock_variables`(clock[, prefix]) | Convenience function to add the `t` and `dt` (or `times`, for an `EventClock`) attributes of a `clock`.

  Details

  indices

    A dictionary given the index name for every array name

  owner

    A reference to the `Group` owning these variables

  add_arange(name, size, start=0, dtype=<class 'numpy.int32'>, constant=True, read_only=True, unique=True, index=None)

    Add an array, initialized with a range of integers.

    Parameters:

      name : str

      > The name of the variable.

      size : int

      > The size of the array.

      start : int

      > The start value of the range.

      dtype : `dtype`, optional

      > The dtype used for storing the variable. If none is given, defaults to `np.int32`.

      constant : bool, optional

      > Whether the variable’s value is constant during a run. Defaults to `True`.

      read_only : bool, optional

      > Whether this is a read-only variable, i.e. a variable that is set internally and cannot be changed by the user. Defaults to `True`.

      index : str, optional

      > The index to use for this variable. Defaults to `Variables.default_index`.

      unique : bool, optional

      > See `ArrayVariable`. Defaults to `True` here.

  add_array(name, size, dimensions=Dimension(), values=None, dtype=None, constant=False, read_only=False, scalar=False, unique=False, index=None)

    Add an array (initialized with zeros).

    Parameters:

      name : str

      > The name of the variable.

      dimensions : `Dimension`, optional

      > The physical dimensions of the variable.

      size : int

      > The size of the array.

      values : `ndarray`, optional

      > The values to initalize the array with. If not specified, the array is initialized to zero.

      dtype : `dtype`, optional

      > The dtype used for storing the variable. If none is given, defaults to core.default_float_dtype.

      constant : bool, optional

      > Whether the variable’s value is constant during a run. Defaults to `False`.

      scalar : bool, optional

      > Whether this is a scalar variable. Defaults to `False`, if set to `True`, also implies that `size` equals 1.

      read_only : bool, optional

      > Whether this is a read-only variable, i.e. a variable that is set internally and cannot be changed by the user. Defaults to `False`.

      index : str, optional

      > The index to use for this variable. Defaults to `Variables.default_index`.

      unique : bool, optional

      > See `ArrayVariable`. Defaults to `False`.

  add_arrays(names, size, dimensions=Dimension(), dtype=None, constant=False, read_only=False, scalar=False, unique=False, index=None)

    Adds several arrays (initialized with zeros) with the same attributes (size, units, etc.).

    Parameters:

      names : list of str

      > The names of the variable.

      dimensions : `Dimension`, optional

      > The physical dimensions of the variable.

      size : int

      > The sizes of the arrays.

      dtype : `dtype`, optional

      > The dtype used for storing the variables. If none is given, defaults to core.default_float_dtype.

      constant : bool, optional

      > Whether the variables’ values are constant during a run. Defaults to `False`.

      scalar : bool, optional

      > Whether these are scalar variables. Defaults to `False`, if set to `True`, also implies that `size` equals 1.

      read_only : bool, optional

      > Whether these are read-only variables, i.e. variables that are set internally and cannot be changed by the user. Defaults to `False`.

      index : str, optional

      > The index to use for these variables. Defaults to `Variables.default_index`.

      unique : bool, optional

      > See `ArrayVariable`. Defaults to `False`.

  add_auxiliary_variable(name, dimensions=Dimension(), dtype=None, scalar=False)

    Add an auxiliary variable (most likely one that is added automatically to abstract code, e.g. `_cond` for a threshold condition), specifying its type and unit for code generation.

    Parameters:

      name : str

      > The name of the variable

      dimensions : `Dimension`

      > The physical dimensions of the variable.

      dtype : `dtype`, optional

      > The dtype used for storing the variable. If none is given, defaults to core.default_float_dtype.

      scalar : bool, optional

      > Whether the variable is a scalar value (`True`) or vector-valued, e.g. defined for every neuron (`False`). Defaults to `False`.

  add_constant(name, value, dimensions=Dimension())

    Add a scalar constant (e.g. the number of neurons `N`).

    Parameters:

      name : str

      > The name of the variable

      value: reference to the variable value :

      > The value of the constant.

      dimensions : `Dimension`, optional

      > The physical dimensions of the variable. Note that the variable itself (as referenced by value) should never have units attached.

  add_dynamic_array(name, size, dimensions=Dimension(), values=None, dtype=None, constant=False, needs_reference_update=False, resize_along_first=False, read_only=False, unique=False, scalar=False, index=None)

    Add a dynamic array.

    Parameters:

      name : str

      > The name of the variable.

      dimensions : `Dimension`, optional

      > The physical dimensions of the variable.

      size : int or tuple of int

      > The (initital) size of the array.

      values : `ndarray`, optional

      > The values to initalize the array with. If not specified, the array is initialized to zero.

      dtype : `dtype`, optional

      > The dtype used for storing the variable. If none is given, defaults to core.default_float_dtype.

      constant : bool, optional

      > Whether the variable’s value is constant during a run. Defaults to `False`.

      needs_reference_update : bool, optional

      > Whether the code objects need a new reference to the underlying data at every time step. This should be set if the size of the array can be changed by other code objects. Defaults to `False`.

      scalar : bool, optional

      > Whether this is a scalar variable. Defaults to `False`, if set to `True`, also implies that `size` equals 1.

      read_only : bool, optional

      > Whether this is a read-only variable, i.e. a variable that is set internally and cannot be changed by the user. Defaults to `False`.

      index : str, optional

      > The index to use for this variable. Defaults to `Variables.default_index`.

      unique : bool, optional

      > See `DynamicArrayVariable`. Defaults to `False`.

  add_object(name, obj)

    Add an arbitrary Python object. This is only meant for internal use and therefore only names starting with an underscore are allowed.

    Parameters:

      name : str

      > The name used for this object (has to start with an underscore).

      obj : object

      > An arbitrary Python object that needs to be accessed directly from a `CodeObject`.

  add_reference(name, group, varname=None, index=None)

    Add a reference to a variable defined somewhere else (possibly under a different name). This is for example used in `Subgroup` and `Synapses` to refer to variables in the respective `NeuronGroup`.

    Parameters:

      name : str

      > The name of the variable (in this group, possibly a different name from `var.name`).

      group : `Group`

      > The group from which `var` is referenced

      varname : str, optional

      > The variable to refer to. If not given, defaults to `name`.

      index : str, optional

      > The index that should be used for this variable (defaults to `Variables.default_index`).

  add_references(group, varnames, index=None)

    Add all `Variable` objects from a name to `Variable` mapping with the same name as in the original mapping.

    Parameters:

      group : `Group`

      > The group from which the `variables` are referenced

      varnames : iterable of str

      > The variables that should be referred to in the current group

      index : str, optional

      > The index to use for all the variables (defaults to `Variables.default_index`)

  add_referred_subexpression(name, group, subexpr, index)
  add_subexpression(name, expr, dimensions=Dimension(), dtype=None, scalar=False, index=None)

    Add a named subexpression.

    Parameters:

      name : str

      > The name of the subexpression.

      dimensions : `Dimension`

      > The physical dimensions of the subexpression.

      expr : str

      > The subexpression itself.

      dtype : `dtype`, optional

      > The dtype used for the expression. Defaults to core.default_float_dtype.

      scalar : bool, optional

      > Whether this is an expression only referring to scalar variables. Defaults to `False`

      index : str, optional

      > The index to use for this variable. Defaults to `Variables.default_index`.

  create_clock_variables(clock, prefix='')

    Convenience function to add the `t` and `dt` (or `times`, for an `EventClock`) attributes of a `clock`.

    Parameters:

      clock : `BaseClock`

      > The clock that should be used for `t` and `dt` or `times`.

      prefix : str, optional

      > A prefix for the variable names. Used for example in monitors to not confuse the dynamic array of recorded times with the current time in the recorded group.