Variables class

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

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

Bases: _abcoll.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, unit, size[, values, dtype, ...]) Add an array (initialized with zeros).
add_attribute_variable(name, unit, obj, ...) Add a variable stored as an attribute of an object.
add_auxiliary_variable(name, unit[, dtype, ...]) Add an auxiliary variable (most likely one that is added automatically to abstract code, e.g.
add_constant(name, unit, value) Add a scalar constant (e.g.
add_dynamic_array(name, unit, size[, ...]) Add a dynamic array.
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, unit, expr[, dtype, ...]) Add a named subexpression.
create_clock_variables(clock[, prefix]) Convenience function to add the t and dt 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=<type '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, 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, unit, size, 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.

unit : Unit

The unit 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_attribute_variable(name, unit, obj, attribute, dtype=None, constant=False, scalar=True)[source]

Add a variable stored as an attribute of an object.

Parameters:

name : str

The name of the variable

unit : Unit

The unit of the variable

obj : object

The object storing the attribute.

attribute : str

The name of the attribute storing the variable’s value. attribute has to be an attribute of obj.

dtype : dtype, optional

The dtype used for storing the variable. If none is given, uses the type of obj.attribute (which have to exist).

constant : bool, optional

Whether the attribute’s value is constant during a run. Defaults to False.

scalar : bool, optional

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

add_auxiliary_variable(name, unit, dtype=None, scalar=False)[source]

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

unit : Unit

The unit 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, unit, value)[source]

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

Parameters:

name : str

The name of the variable

unit : Unit

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

value: reference to the variable value :

The value of the constant.

add_dynamic_array(name, unit, size, values=None, dtype=None, constant=False, constant_size=True, 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.

unit : Unit

The unit 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.

constant_size : bool, optional

Whether the size of the variable is constant during a run. Defaults to True.

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_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 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)[source]

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)[source]
add_subexpression(name, unit, expr, dtype=None, scalar=False, index=None)[source]

Add a named subexpression.

Parameters:

name : str

The name of the subexpression.

unit : Unit

The unit 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='')[source]

Convenience function to add the t and dt attributes of a clock.

Parameters:

clock : Clock

The clock that should be used for t and dt. Note that the actual attributes referred to are t_ and dt_, i.e. the unitless values.

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.