Device class

(Shortest import: from brian2.devices import Device)

class brian2.devices.device.Device[source]

Bases: object

Base Device object.

Attributes

network_schedule The network schedule that this device supports.

Methods

activate([build_on_run]) Called when this device is set as the current device.
add_array(var) Add an array to this device.
build(**kwds) For standalone projects, called when the project is ready to be built.
code_object(owner, name, abstract_code, ...)
code_object_class([codeobj_class])
fill_with_array(var, arr) Fill an array with the values given in another array.
get_array_name(var[, access_data]) Return a globally unique name for var().
get_len(array) Return the length of the array.
init_with_arange(var, start, dtype) Initialize an array with an integer range.
init_with_zeros(var, dtype) Initialize an array with zeros.
insert_code(slot, code) Insert code directly into a given slot in the device.
insert_device_code(slot, code)
reinit() Reinitialize the device.
resize(var, new_size) Resize a DynamicArrayVariable.
resize_along_first(var, new_size)
seed([seed]) Set the seed for the random number generator.
spike_queue(source_start, source_end) Create and return a new SpikeQueue for this Device.

Details

network_schedule

The network schedule that this device supports. If the device only supports a specific, fixed schedule, it has to set this attribute to the respective schedule (see Network.schedule for details). If it supports arbitrary schedules, it should be set to None (the default).

activate(build_on_run=True, **kwargs)[source]

Called when this device is set as the current device.

add_array(var)[source]

Add an array to this device.

Parameters:

var : ArrayVariable

The array to add.

build(**kwds)[source]

For standalone projects, called when the project is ready to be built. Does nothing for runtime mode.

code_object(owner, name, abstract_code, variables, template_name, variable_indices, codeobj_class=None, template_kwds=None, override_conditional_write=None)[source]
code_object_class(codeobj_class=None)[source]
fill_with_array(var, arr)[source]

Fill an array with the values given in another array.

Parameters:

var : ArrayVariable

The array to fill.

arr : ndarray

The array values that should be copied to var().

get_array_name(var, access_data=True)[source]

Return a globally unique name for var().

Parameters:

access_data : bool, optional

For DynamicArrayVariable objects, specifying True here means the name for the underlying data is returned. If specifying False, the name of object itself is returned (e.g. to allow resizing).

Returns:

name : str

The name for var().

get_len(array)[source]

Return the length of the array.

Parameters:

array : ArrayVariable

The array for which the length is requested.

Returns:

l : int

The length of the array.

init_with_arange(var, start, dtype)[source]

Initialize an array with an integer range.

Parameters:

var : ArrayVariable

The array to fill with the integer range.

start : int

The start value for the integer range

dtype : dtype

The data type to use for the array.

init_with_zeros(var, dtype)[source]

Initialize an array with zeros.

Parameters:

var : ArrayVariable

The array to initialize with zeros.

dtype : dtype

The data type to use for the array.

insert_code(slot, code)[source]

Insert code directly into a given slot in the device. By default does nothing.

insert_device_code(slot, code)[source]
reinit()[source]

Reinitialize the device. For standalone devices, clears all the internal state of the device.

resize(var, new_size)[source]

Resize a DynamicArrayVariable.

Parameters:

var : DynamicArrayVariable

The variable that should be resized.

new_size : int

The new size of the variable

resize_along_first(var, new_size)[source]
seed(seed=None)[source]

Set the seed for the random number generator.

Parameters:

seed : int, optional

The seed value for the random number generator, or None (the default) to set a random seed.

spike_queue(source_start, source_end)[source]

Create and return a new SpikeQueue for this Device.

Parameters:

source_start : int

The start index of the source group (necessary for subgroups)

source_end : int

The end index of the source group (necessary for subgroups)