brian-team / brian2

Brian is a free, open source simulator for spiking neural networks.
http://briansimulator.org
Other
906 stars 217 forks source link

Synapse.connect returns created synapse indices #263

Open victorbenichoux opened 10 years ago

victorbenichoux commented 10 years ago

Hi guys,

For now, calling Synapses.connect only creates the connections -- which does not sound so bad -- but does not return anything.

I think that it would be very convenient to have this method return the array of indices of the synapses that were just created. This would make setting other attributes very easy.

An example is when I want to sequentially add Synapses within a loop that calls S.connect:

S = Synapses(..., 'w:1')

for k in some_iterable:
    indices = S.connect(something(k), something(k))
    S.w[indices] = some_weights(k)
    S.delays[indices] = some_delays(k)

What do you think?

mstimberg commented 10 years ago

Sounds reasonable indeed. I think in general we don't want users to think in terms of synapse numbers, so if there's only one synapse per source-target combination, the standard way to write your code would be:

for k in some_iterable:
    indices = S.connect(something(k), something(k))
    S.w[something(k), something(k)] = some_weights(k)
    S.delays[something(k), something(k)] = some_delays(k)

but this is obviously slower than your proposed solution since we have to calculate the indices first.

thesamovar commented 10 years ago

I agree that we want more efficient ways of being able to create synapses in runtime mode. I'm wondering though: can this be made to work with standalone too?

mstimberg commented 10 years ago

This is not really about synapse creation but about assigning to synaptic state variables. In principle I could imagine that we return not a simple numpy array with the indices but some kind of lazily-evaluated array that standalone knows about, stores in a variable and later uses for the state variable assignment. Could be useful, but I wouldn't assign it very high priority for now.