Unable to create proper synapses connections using a loop

Hi @RRHHAAWW. This is quite a common issue, and I wonder what we could do to handle this better. When you call run, Brian looks for Brian objects in the current scope and adds them to a Network object internally (we call this the “magic” :star2: system). To avoid digging deeply into all container objects that are present (with the risk of going into infinite recursions, if two containers refer to each other, etc.), Brian will only look at objects that are directly visible. In your above code, it will find S1 and S2 which are “Brian objects”, but when it looks at S it will see a list and skip it. We mention this in the documentation here: Running a simulation — Brian 2 2.4.2 documentation
The way around this is to create a Network object manually. If the synapses list is the only container you use, you can still use the automatic system for most of the objects (NeuronGroup, etc.), and only add the container manually:

net = Network(collect())  # automatically add everything that run(...) would discover by itself
net.add(S)  # add the list of synapses manually
net.run(50*ms)

That said, in your example you could also use a single Synapses object which would be more efficient to simulate. You could use something like this to convert your data structures into “flat” arrays of values:

J_flat, W_flat = [], []
for syn in range(2):
    J_flat.extend(J[syn])
    W_flat.extend(W[syn])

And then you can use these new arrays to set up everything:

S = Synapses(G, H, model=‘w : 1’, on_pre=‘v_post += w’)
S.connect(i=0, j=J_flat)
S.w = W_flat

Hope that makes things clearer, best
Marcel