# Synapses class¶

(Shortest import: from brian2 import Synapses)

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

Class representing synaptic connections. Creating a new Synapses object does by default not create any synapses – you either have to provide the connect() argument or 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. 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. post : {str, dict}, optional The code that will be executed after every post-synaptic spike. Same conventions as for pre, the default name for the pathway is post. connect : {str, bool}. optional Determines whether any actual synapses are created. False (the default) means not to create any synapses, True means to create synapses between all source/target pairs. Also accepts a string expression that evaluates to True for every synapse that should be created, e.g. 'i == j' for a one-to-one connectivity. See Synapses.connect() for more details. 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. 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 network 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

 _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 summed_updaters “Summed variable” mechanism – sum over all synapses of a

Methods

 before_run([run_namespace, level]) connect(pre_or_cond[, post, p, n, ...]) 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

_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

summed_updaters

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

before_run(run_namespace=None, level=0)[source]
connect(pre_or_cond, post=None, p=1.0, n=1, namespace=None, level=0)[source]

Add synapses. The first argument can be either a presynaptic index (int or array) or a condition for synapse creation in the form of a string that evaluates to a boolean value (or directly a boolean value). If it is given as an index, also post has to be present. A string condition will be evaluated for all pre-/postsynaptic indices, which can be referred to as i and j.

Parameters: pre_or_cond : {int, ndarray of int, bool, str} The presynaptic neurons (in the form of an index or an array of indices) or a boolean value or a string that evaluates to a boolean value. If it is an index, then also post has to be given. post_neurons : {int, ndarray of int), optional GroupIndices of neurons from the target group. Non-optional if one or more presynaptic indices have been given. p : float, optional The probability to create n synapses wherever the condition given as pre_or_cond evaluates to true or for the given pre/post indices. n : int, optional The number of synapses to create per pre/post connection pair. Defaults to 1. 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', pre='v+=w')
>>> S.connect('i != j') # all-to-all but no self-connections
>>> S.connect(0, 0) # connect neuron 0 to itself
>>> S.connect(np.array([1, 2]), np.array([2, 1])) # connect 1->2 and 2->1
>>> S.connect(True) # connect all-to-all
>>> S.connect('i != j', p=0.1)  # Connect neurons with 10% probability, exclude self-connections
>>> S.connect('i == j', n=2)  # Connect all neurons to themselves with 2 synapses

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.