brian2genn
brian2genn copied to clipboard
Question: How to work around restriction of synaptic output variable or summed variable?
Hi! I hope it's okay to use the issue tracker for asking a question.
So I'm aware that brian2genn doesn't support summed variables and writing to a post-synaptic output variable in a Synapse's on_pre
handler. As I do need something like this, I was wondering how to work around that limitation in the following model (excerpt, an executable file is available here https://gist.github.com/jangmarker/5092a3dacd2dceb34ff2c85a150b8596):
# adapted from https://brian2.readthedocs.io/en/latest/examples/synapses.STDP.html
eqs_neurons = Equations('''
dv/dt = (ge * (Ee-v) + El - v) / taum : volt
dge/dt = -ge / taue : 1
weight_sum : 1
''')
neurons = NeuronGroup(1, eqs_neurons, threshold='v>vt', reset='v = vr', method='euler')
S = Synapses(input, neurons,
'''weight_sum_post = w : 1 (summed)
w : 1
dApre/dt = -Apre / taupre : 1 (event-driven)
dApost/dt = -Apost / taupost : 1 (event-driven)''',
on_pre='''ge += w
Apre += dApre
w = clip(w + Apost, 0, gmax)''',
on_post='''Apost += dApost
w = clip(w + Apre, 0, gmax)''',
)
S.connect()
S.w = 'rand() * gmax'
S.run_regularly("w = w*(1 + eta_scaling*(norm_target/weight_sum_post - 1))", dt=1*second, when='end')
This model needs weight_sum
to be the sum of all weights in order to normalize the weights.
This works fine in standalone
mode but brian2genn complains about the mix of summed variable and modifying a post-synaptic variable in the on_pre
handler:
NotImplementedError: brian2genn only supports a either a single synaptic output variable or a single summed variable per Synapses group.
Hi - to be honest I can't think of a simple fix without further development of brian2genn. Maybe @mstimberg has better ideas though.
Quick further update: Short of @mstimberg finding a creative workaround, recent improvements in GeNN might allow to remove some restrictions on the number of post-synaptic target variables you encountered here. Unfortunately, it is a very busy time at the moment so it will take a while before I can have a look at this possible improvement on brian2genn.
Hi. I don't see an easy workaround at first glance, maybe a hand-written C++ function that does the summing launched via a run_regularly
operation on the Synapses
object could work? But that probably requires looking at the generated code to use the correct names, etc. Also, not 100% sure whether Brian2GeNN would handle getting the values from the GPU memory correctly in that case. I'm afraid I can't look into this any further before August, I'm currently on holiday!
Thank you both for your suggestions. I will explore them the next weeks and will report back. For me this is still evaluation, so there's no urgency to all this. @mstimberg I wish you good holidays! :-)