SpikeQueue class

(Shortest import: from brian2.synapses.spikequeue import SpikeQueue)

class brian2.synapses.spikequeue.SpikeQueue(source_start, source_end, dtype=<type 'numpy.int32'>, precompute_offsets=True)[source]

Bases: object

Data structure saving the spikes and taking care of delays.

Parameters:

synapses : list of ndarray

A list of synapses (synapses[i]=array of synapse indices for neuron i).

delays : ndarray

An array of delays (delays[k]=delay of synapse k).

dt : Quantity

The timestep of the source group

max_delay : Quantity, optional

The maximum delay (in second) of synaptic events. At run time, the structure is resized to the maximum delay in delays, and thus the max_delay should only be specified if delays can change during the simulation (in which case offsets should not be precomputed).

precompute_offsets : bool, optional

A flag to precompute offsets. Defaults to True, i.e. offsets (an internal array derived from delays, used to insert events in the data structure, see below) are precomputed for all neurons when the object is prepared with the compress() method. This usually results in a speed up but takes memory, which is why it can be disabled.

Notes

Data structure

A spike queue is implemented as a 2D array X that is circular in the time direction (rows) and dynamic in the events direction (columns). The row index corresponding to the current timestep is currentime. Each element contains the target synapse index.

Offsets

Offsets are used to solve the problem of inserting multiple synaptic events with the same delay. This is difficult to vectorise. If there are n synaptic events with the same delay, these events are given an offset between 0 and n-1, corresponding to their relative position in the data structure. They can be either precalculated (faster), or determined at run time (saves memory). Note that if they are determined at run time, then it is possible to also vectorise over presynaptic spikes.

Attributes

_dt The dt used for storing the spikes (will be set in prepare)
_offsets precalculated offsets
_precompute_offsets Whether the offsets should be precomputed
_source_end The end of the source indices (for subgroups)
_source_start The start of the source indices (for subgroups)
_stored_spikes Storage for the store/restore mechanism
currenttime The current time (in time steps)
n number of events in each time step

Methods

advance() Advances by one timestep
peek() Returns the all the synaptic events corresponding to the current time, as an array of synapse indexes.
prepare(delays, dt, synapse_sources) Prepare the data structure and pre-compute offsets.
push(sources) Push spikes to the queue.

Details

_dt

The dt used for storing the spikes (will be set in prepare)

_offsets

precalculated offsets

_precompute_offsets

Whether the offsets should be precomputed

_source_end

The end of the source indices (for subgroups)

_source_start

The start of the source indices (for subgroups)

_stored_spikes

Storage for the store/restore mechanism

currenttime

The current time (in time steps)

n

number of events in each time step

advance()[source]

Advances by one timestep

peek()[source]

Returns the all the synaptic events corresponding to the current time, as an array of synapse indexes.

prepare(delays, dt, synapse_sources)[source]

Prepare the data structure and pre-compute offsets. This is called every time the network is run. The size of the of the data structure (number of rows) is adjusted to fit the maximum delay in delays, if necessary. Offsets are calculated, unless the option precompute_offsets is set to False. A flag is set if delays are homogeneous, in which case insertion will use a faster method implemented in insert_homogeneous.

push(sources)[source]

Push spikes to the queue.

Parameters:

sources : ndarray of int

The indices of the neurons that spiked.