Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: How to work around restriction of synaptic output variable or summed variable? #117

Open
jangmarker opened this issue Jul 21, 2020 · 4 comments
Assignees

Comments

@jangmarker
Copy link
Contributor

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.
@tnowotny
Copy link
Contributor

Hi - to be honest I can't think of a simple fix without further development of brian2genn. Maybe @mstimberg has better ideas though.

@tnowotny
Copy link
Contributor

tnowotny commented Jul 22, 2020

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.

@tnowotny tnowotny self-assigned this Jul 22, 2020
@mstimberg
Copy link
Member

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!

@jangmarker
Copy link
Contributor Author

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! :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants