VariableOwner class

(Shortest import: from brian2 import VariableOwner)

class brian2.groups.group.VariableOwner(*args, **kw)[source]

Bases: Nameable

Mix-in class for accessing arrays by attribute.

# TODO: Overwrite the __dir__ method to return the state variables # (should make autocompletion work)

Methods

add_attribute(name)

Add a new attribute to this group.

check_variable_write(variable)

Function that can be overwritten to raise an error if writing to a variable should not be allowed.

get_states([vars, units, format, ...])

Return a copy of the current state variable values.

set_states(values[, units, format, level])

Set the state variables.

state(name[, use_units, level])

Return the state variable in a way that properly supports indexing in the context of this group

Details

add_attribute(name)[source]

Add a new attribute to this group. Using this method instead of simply assigning to the new attribute name is necessary because Brian will raise an error in that case, to avoid bugs passing unnoticed (misspelled state variable name, un-declared state variable, …).

check_variable_write(variable)[source]

Function that can be overwritten to raise an error if writing to a variable should not be allowed. Note that this does not deal with incorrect writes that are general to all kind of variables (incorrect units, writing to a read-only variable, etc.). This function is only used for type-specific rules, e.g. for raising an error in Synapses when writing to a synaptic variable before any connect call.

By default this function does nothing.

get_states(vars=None, units=True, format='dict', subexpressions=False, read_only_variables=True, level=0)[source]

Return a copy of the current state variable values. The returned arrays are copies of the actual arrays that store the state variable values, therefore changing the values in the returned dictionary will not affect the state variables.

set_states(values, units=True, format='dict', level=0)[source]

Set the state variables.

state(name, use_units=True, level=0)[source]

Return the state variable in a way that properly supports indexing in the context of this group