-
Notifications
You must be signed in to change notification settings - Fork 224
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
Make "summed variable" mechanism work for multiple sources #766
Comments
I was about to start working on this, but now I have second thoughts whether allowing two S = Synapses(sources, targets,'''
dg_syn/dt = -a*g_syn+b*x*(1-g_syn) : 1 (clock-driven)
g_post = g_syn : 1 (summed)''') then you say that So, this would rather argue for raising an error in the case of two I also wondered whether some of the problem is not due to our syntax. E.g. if we wrote Any thoughts/ideas? |
Looking into some old issues, I realized that this is actually a special-case of #126, i.e. if we had a general check that a variable is set twice without being read in between, than it would cover this situation. So I wonder whether we should have a special-purpose solution for summed variables before fixing #126? Also note that one of the issues I raised above also applies to #126. If we had a check for "overwrites", it would trigger in the following, legitimiate, use case: group = NeuronGroup(10, 'v : 1')
e = group[:5]
i = group[5:]
e.run_regularly('v = 1')
i.run_regularly('v = 2') From Brian's point of view, Given that we have quite a few new features and that it is time for a new release (e.g. to publish Python 3.6 packages), I wonder whether we should not downgrade this issue to "add a remark to the Known Issues section"... |
How about But I was never entirely happy with our summed syntax, so maybe if we could think of a more flexible/better one that would be even better? In the short term, adding an error message not a bad idea? |
Oh yeah, and also happy to mark this as known issue and not keep it as high priority. |
As long as we do make it raise an error in the situation where something actually wrong happens I mean! |
I don't quite understand what you mean by that, I'm afraid...
I don't see any nice solution for this now, but I think I'll implement a quick-and-dirty one (during Network preparation, go through all objects and check for multiple |
What I meant was at the moment we have |
Ah, no, you can already do that. The thing is that people want to use two type1_synapses = Synapses(sources, targets,
'''dg_syn/dt = -a*g_syn+b*x*(1-g_syn) : 1 (clock-driven)
g_post = g_syn : 1 (summed)''')
type1_synapses.connect(0.5)
type2_synapses = Synapses(sources, targets,
'''dg_syn/dt = -a*g_syn+b*x*(1-g_syn) : 1 (clock-driven)
g_post = g_syn : 1 (summed)''')
type2_synapses.connect(0.5) If two of those synapses target the same target cell, the latter assignment will overwrite the first instead of adding to it (but as I commented earlier, I'm not sure it would be semantically correct to simply add, given the use of |
Ah OK, well in that case I think we should just raise an error if people try to do this, and suggest they use an extra intermediate variable in the postsynaptic neuron group, i.e. eqs = '''
...
g1 : 1
g2: 1
g = g1+g2 : 1
'''
targets = NeuronGroup(N, eqs, ...)
type1_synapses = Synapses(sources, targets,
'''dg_syn/dt = -a*g_syn+b*x*(1-g_syn) : 1 (clock-driven)
g1_post = g_syn : 1 (summed)''')
type1_synapses.connect(0.5)
type2_synapses = Synapses(sources, targets,
'''dg_syn/dt = -a*g_syn+b*x*(1-g_syn) : 1 (clock-driven)
g2_post = g_syn : 1 (summed)''')
type2_synapses.connect(0.5) This would work, right? |
Yes, this is what I am currently doing. The problem is that there is no way to detect this from within the On the other hand, I'd like to allow: targets = NeuronGroup(N, eqs, ...)
type1_synapses = Synapses(sources, targets[:N//2],
'''dg_syn/dt = -a*g_syn+b*x*(1-g_syn) : 1 (clock-driven)
g1_post = g_syn : 1 (summed)''')
type1_synapses.connect(0.5)
type2_synapses = Synapses(sources, targets[N//2:],
'''dg_syn/dt = -a*g_syn+b*x*(1-g_syn) : 1 (clock-driven)
g2_post = g_syn : 1 (summed)''')
type2_synapses.connect(0.5) i.e., targeting non-overlapping subgroups, since there's no ambiguity in that case. |
Hmm, there's no ambiguity (I assume you wanted to write |
Sorry, copy&paste error, it was supposed to be exc = group[:N//2]
inh = group[N//2] then you think of |
I see your point but I worry that it's a bit confusing to say to users that it works in the one case and not the other. The difference is logically clear, but requires a bit of understanding of our code generation pipeline. |
Not sure, I could see it be confusing either way. If you think of |
[The |
That's a good point. OK, objection withdrawn! |
At the moment, updates of the same post-synaptic variable from two different objects using the
(summed)
mechanism will fail: since at the start of each summing, the post-synaptic variable is set to 0, only the second update will work. This is very confusing for users, since they don't even get a warning.With our current architecture of independent code objects, solving this problem is trickier than it sounds, since each
SummedVariableUpdater
is unaware of the other updaters. I guess the easiest solution is to separate the setting to zero from the summed update, and do it as a separate operation (in thebefore_start
time slot) -- this would have a specific name, so that for a second(summed)
variable we would detect that the initialization already exists and would not add another one.The text was updated successfully, but these errors were encountered: