Variables class¶
(Shortest import: from brian2.core.variables import Variables)
- class brian2.core.variables.Variables(owner, default_index='_idx')[source]¶
Bases:
collections.abc.MappingA container class for storing
Variableobjects. Instances of this class are used as theGroup.variablesattribute and can be accessed as (read-only) dictionaries.- Parameters
owner :
NameableThe object (typically a
Group) “owning” the variables.default_index : str, optional
The index to use for the variables (only relevant for
ArrayVariableandDynamicArrayVariable). Defaults to'_idx'.
Attributes
A dictionary given the index name for every array name
A reference to the
Groupowning these variablesMethods
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.
add_constant(name, value[, dimensions])Add a scalar constant (e.g.
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
Variableobjects from a name toVariablemapping 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
tanddtattributes of aclock.Details
- indices¶
A dictionary given the index name for every array name
- add_arange(name, size, start=0, dtype=<class 'numpy.int32'>, constant=True, read_only=True, unique=True, index=None)[source]¶
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, optionalThe 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 toTruehere.
- add_array(name, size, dimensions=Dimension(), values=None, dtype=None, constant=False, read_only=False, scalar=False, unique=False, index=None)[source]¶
Add an array (initialized with zeros).
- Parameters
name : str
The name of the variable.
dimensions :
Dimension, optionalThe physical dimensions of the variable.
size : int
The size of the array.
values :
ndarray, optionalThe values to initalize the array with. If not specified, the array is initialized to zero.
dtype :
dtype, optionalThe 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 toTrue, also implies thatsize()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 toFalse.
- add_arrays(names, size, dimensions=Dimension(), dtype=None, constant=False, read_only=False, scalar=False, unique=False, index=None)[source]¶
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, optionalThe physical dimensions of the variable.
size : int
The sizes of the arrays.
dtype :
dtype, optionalThe 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 toTrue, also implies thatsize()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 toFalse.
- add_auxiliary_variable(name, dimensions=Dimension(), dtype=None, scalar=False)[source]¶
Add an auxiliary variable (most likely one that is added automatically to abstract code, e.g.
_condfor a threshold condition), specifying its type and unit for code generation.- Parameters
name : str
The name of the variable
dimensions :
DimensionThe physical dimensions of the variable.
dtype :
dtype, optionalThe 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 toFalse.
- add_constant(name, value, dimensions=Dimension())[source]¶
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, optionalThe 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)[source]¶
Add a dynamic array.
- Parameters
name : str
The name of the variable.
dimensions :
Dimension, optionalThe physical dimensions of the variable.
size : int or tuple of int
The (initital) size of the array.
values :
ndarray, optionalThe values to initalize the array with. If not specified, the array is initialized to zero.
dtype :
dtype, optionalThe 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 toTrue, also implies thatsize()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 toFalse.
- add_object(name, obj)[source]¶
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)[source]¶
Add a reference to a variable defined somewhere else (possibly under a different name). This is for example used in
SubgroupandSynapsesto refer to variables in the respectiveNeuronGroup.- Parameters
name : str
The name of the variable (in this group, possibly a different name from
var.name).group :
GroupThe group from which
var()is referencedvarname : 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)[source]¶
Add all
Variableobjects from a name toVariablemapping with the same name as in the original mapping.- Parameters
group :
GroupThe group from which the
variablesare referencedvarnames : 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_subexpression(name, expr, dimensions=Dimension(), dtype=None, scalar=False, index=None)[source]¶
Add a named subexpression.
- Parameters
name : str
The name of the subexpression.
dimensions :
DimensionThe physical dimensions of the subexpression.
expr : str
The subexpression itself.
dtype :
dtype, optionalThe 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
Falseindex : str, optional
The index to use for this variable. Defaults to
Variables.default_index.
- create_clock_variables(clock, prefix='')[source]¶
Convenience function to add the
tanddtattributes of aclock.- Parameters
clock :
ClockThe clock that should be used for
tanddt.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.