Synapses class

(Shortest import: from brian2 import Synapses)

class brian2.synapses.synapses.Synapses(source, target=None, model=None, on_pre=None, pre=None, on_post=None, post=None, connect=None, delay=None, on_event='spike', multisynaptic_index=None, namespace=None, dtype=None, codeobj_class=None, dt=None, clock=None, order=0, method=('linear', 'euler', 'heun'), name='synapses*')[source]

Bases: brian2.groups.group.Group

Class representing synaptic connections.

Creating a new Synapses object does by default not create any synapses, you have to call the Synapses.connect() method for that.

Parameters:

source : SpikeSource

The source of spikes, e.g. a NeuronGroup.

target : Group, optional

The target of the spikes, typically a NeuronGroup. If none is given, the same as source()

model : str, Equations, optional

The model equations for the synapses.

on_pre : str, dict, optional

The code that will be executed after every pre-synaptic spike. Can be either a single (possibly multi-line) string, or a dictionary mapping pathway names to code strings. In the first case, the pathway will be called pre and made available as an attribute of the same name. In the latter case, the given names will be used as the pathway/attribute names. Each pathway has its own code and its own delays.

pre : str, dict, optional

Deprecated. Use on_pre instead.

on_post : str, dict, optional

The code that will be executed after every post-synaptic spike. Same conventions as for on_pre`, the default name for the pathway is post.

post : str, dict, optional

Deprecated. Use on_post instead.

delay : Quantity, dict, optional

The delay for the “pre” pathway (same for all synapses) or a dictionary mapping pathway names to delays. If a delay is specified in this way for a pathway, it is stored as a single scalar value. It can still be changed afterwards, but only to a single scalar value. If you want to have delays that vary across synapses, do not use the keyword argument, but instead set the delays via the attribute of the pathway, e.g. S.pre.delay = ... (or S.delay = ... as an abbreviation), S.post.delay = ..., etc.

on_event : str or dict, optional

Define the events which trigger the pre and post pathways. By default, both pathways are triggered by the 'spike' event, i.e. the event that is triggered by the threshold condition in the connected groups.

multisynaptic_index : str, optional

The name of a variable (which will be automatically created) that stores the “synapse number”. This number enumerates all synapses between the same source and target so that they can be distinguished. For models where each source-target pair has only a single connection, this number only wastes memory (it would always default to 0), it is therefore not stored by default. Defaults to None (no variable).

namespace : dict, optional

A dictionary mapping identifier names to objects. If not given, the namespace will be filled in at the time of the call of Network.run(), with either the values from the namespace argument of the Network.run() method or from the local context, if no such argument is given.

dtype : dtype, dict, optional

The numpy.dtype that will be used to store the values, or a dictionary specifying the type for variable names. If a value is not provided for a variable (or no value is provided at all), the preference setting core.default_float_dtype is used.

codeobj_class : class, optional

The CodeObject class to use to run code.

dt : Quantity, optional

The time step to be used for the update of the state variables. Cannot be combined with the clock argument.

clock : Clock, optional

The update clock to be used. If neither a clock, nor the dt argument is specified, the defaultclock will be used.

order : int, optional

The priority of of this group for operations occurring at the same time step and in the same scheduling slot. Defaults to 0.

method : str, StateUpdateMethod, optional

The numerical integration method to use. If none is given, an appropriate one is automatically determined.

name : str, optional

The name for this object. If none is given, a unique name of the form synapses, synapses_1, etc. will be automatically chosen.

Attributes

_connect_called remember whether connect was called to raise an error if an
_pathways List of all SynapticPathway objects
_registered_variables Set of Variable objects that should be resized when the
_synaptic_updaters List of names of all updaters, e.g.
events “Events” for all the pathways
namespace The group-specific namespace
state_updater Performs numerical integration step
subexpression_updater Update the “constant over a time step” subexpressions
summed_updaters “Summed variable” mechanism – sum over all synapses of a

Methods

before_run(run_namespace)
check_variable_write(variable) Checks that Synapses.connect() has been called before setting a synaptic variable.
connect(*args, **kwds) Add synapses.
register_variable(variable) Register a DynamicArray to be automatically resized when the size of the indices change.
unregister_variable(variable) Unregister a DynamicArray from the automatic resizing mechanism.

Details

_connect_called

remember whether connect was called to raise an error if an assignment to a synaptic variable is attempted without a preceding connect.

_pathways

List of all SynapticPathway objects

_registered_variables

Set of Variable objects that should be resized when the number of synapses changes

_synaptic_updaters

List of names of all updaters, e.g. [‘pre’, ‘post’]

events

“Events” for all the pathways

namespace

The group-specific namespace

state_updater

Performs numerical integration step

subexpression_updater

Update the “constant over a time step” subexpressions

summed_updaters

“Summed variable” mechanism – sum over all synapses of a pre-/postsynaptic target

before_run(run_namespace)[source]
check_variable_write(variable)[source]

Checks that Synapses.connect() has been called before setting a synaptic variable.

Parameters:

variable : Variable

The variable that the user attempts to set.

Raises

TypeError
If Synapses.connect() has not been called yet.
connect(*args, **kwds)

Add synapses.

See Synapses for details.

Parameters:

condition : str, bool, optional

A boolean or string expression that evaluates to a boolean. The expression can depend on indices i and j and on pre- and post-synaptic variables. Can be combined with arguments n, and p but not i or j.

i : int, ndarray of int, optional

The presynaptic neuron indices (in the form of an index or an array of indices). Must be combined with j argument.

j : int, ndarray of int, str, optional

The postsynaptic neuron indices. It can be an index or array of indices if combined with the i argument, or it can be a string generator expression.

p : float, str, optional

The probability to create n synapses wherever the condition evaluates to true. Cannot be used with generator syntax for j.

n : int, str, optional

The number of synapses to create per pre/post connection pair. Defaults to 1.

skip_if_invalid : bool, optional

If set to True, rather than raising an error if you try to create an invalid/out of range pair (i, j) it will just quietly skip those synapses.

namespace : dict-like, optional

A namespace that will be used in addition to the group-specific namespaces (if defined). If not specified, the locals and globals around the run function will be used.

level : int, optional

How deep to go up the stack frame to look for the locals/global (see namespace argument).

Examples

>>> from brian2 import *
>>> import numpy as np
>>> G = NeuronGroup(10, 'dv/dt = -v / tau : 1', threshold='v>1', reset='v=0')
>>> S = Synapses(G, G, 'w:1', on_pre='v+=w')
>>> S.connect(condition='i != j') # all-to-all but no self-connections
>>> S.connect(i=0, j=0) # connect neuron 0 to itself
>>> S.connect(i=np.array([1, 2]), j=np.array([2, 1])) # connect 1->2 and 2->1
>>> S.connect() # connect all-to-all
>>> S.connect(condition='i != j', p=0.1)  # Connect neurons with 10% probability, exclude self-connections
>>> S.connect(j='i', n=2)  # Connect all neurons to themselves with 2 synapses
>>> S.connect(j='k for k in range(i+1)') # Connect neuron i to all j with 0<=j<=i
>>> S.connect(j='i+(-1)**k for k in range(2) if i>0 and i<N_pre-1') # connect neuron i to its neighbours if it has both neighbours
>>> S.connect(j='k for k in sample(N_post, p=i*1.0/(N_pre-1))') # neuron i connects to j with probability i/(N-1)
register_variable(variable)[source]

Register a DynamicArray to be automatically resized when the size of the indices change. Called automatically when a SynapticArrayVariable specifier is created.

unregister_variable(variable)[source]

Unregister a DynamicArray from the automatic resizing mechanism.