Variable class

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

class brian2.core.variables.Variable(name, dimensions=Dimension(), owner=None, dtype=None, scalar=False, constant=False, read_only=False, dynamic=False, array=False)[source]

Bases: brian2.utils.caching.CacheKey

An object providing information about model variables (including implicit variables such as t or xi). This class should never be instantiated outside of testing code, use one of its subclasses instead.

Parameters

name : ‘str’

The name of the variable. Note that this refers to the original name in the owning group. The same variable may be known under other names in other groups (e.g. the variable v of a NeuronGroup is known as v_post in a Synapse connecting to the group).

dimensions : Dimension, optional

The physical dimensions of the variable.

owner : Nameable, optional

The object that “owns” this variable, e.g. the NeuronGroup or Synapses object that declares the variable in its model equations. Defaults to None (the value used for Variable objects without an owner, e.g. external Constants).

dtype : dtype, optional

The dtype used for storing the variable. Defaults to the preference core.default_scalar.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.

constant: bool, optional :

Whether the value of this variable can change during a run. Defaults to False.

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 (this is used for example for the variable N, the number of neurons in a group). Defaults to False.

array : bool, optional

Whether this variable is an array. Allows for simpler check than testing isinstance(var, ArrayVariable). Defaults to False.

Attributes

array

Whether the variable is an array

constant

Whether the variable is constant during a run

dim

The variable's dimensions.

dtype

The dtype used for storing the variable.

dtype_str

String representation of the numpy dtype

dynamic

Whether the variable is dynamically sized (only for non-scalars)

is_boolean

is_integer

name

The variable's name.

owner

The Group to which this variable belongs.

read_only

Whether the variable is read-only

scalar

Whether the variable is a scalar

unit

The Unit of this variable

Methods

get_addressable_value(name, group)

Get the value (without units) of this variable in a form that can be indexed in the context of a group.

get_addressable_value_with_unit(name, group)

Get the value (with units) of this variable in a form that can be indexed in the context of a group.

get_len()

Get the length of the value associated with the variable or 0 for a scalar variable.

get_value()

Return the value associated with the variable (without units).

get_value_with_unit()

Return the value associated with the variable (with units).

set_value(value)

Set the value associated with the variable.

Details

array

Whether the variable is an array

constant

Whether the variable is constant during a run

dim

The variable’s dimensions.

dtype

The dtype used for storing the variable.

dtype_str

String representation of the numpy dtype

dynamic

Whether the variable is dynamically sized (only for non-scalars)

is_boolean
is_integer
name

The variable’s name.

owner

The Group to which this variable belongs.

read_only

Whether the variable is read-only

scalar

Whether the variable is a scalar

unit

The Unit of this variable

get_addressable_value(name, group)[source]

Get the value (without units) of this variable in a form that can be indexed in the context of a group. For example, if a postsynaptic variable x is accessed in a synapse S as S.x_post, the synaptic indexing scheme can be used.

Parameters

name : str

The name of the variable

group : Group

The group providing the context for the indexing. Note that this group is not necessarily the same as Variable.owner: a variable owned by a NeuronGroup can be indexed in a different way if accessed via a Synapses object.

Returns

variable : object

The variable in an indexable form (without units).

get_addressable_value_with_unit(name, group)[source]

Get the value (with units) of this variable in a form that can be indexed in the context of a group. For example, if a postsynaptic variable x is accessed in a synapse S as S.x_post, the synaptic indexing scheme can be used.

Parameters

name : str

The name of the variable

group : Group

The group providing the context for the indexing. Note that this group is not necessarily the same as Variable.owner: a variable owned by a NeuronGroup can be indexed in a different way if accessed via a Synapses object.

Returns

variable : object

The variable in an indexable form (with units).

get_len()[source]

Get the length of the value associated with the variable or 0 for a scalar variable.

get_value()[source]

Return the value associated with the variable (without units). This is the way variables are accessed in generated code.

get_value_with_unit()[source]

Return the value associated with the variable (with units).

set_value(value)[source]

Set the value associated with the variable.