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

Incorrect state variable assignment in subtrees of multicompartmental neurons #822

Closed
mstimberg opened this Issue Mar 7, 2017 · 0 comments

Comments

Projects
None yet
1 participant
@mstimberg
Member

mstimberg commented Mar 7, 2017

I just discovered a quite severe bug in the handling of state variables in subtrees of SpatialNeuron objects. It turns out that I introduced the bug in the big refactoring of the multicompartmental modeling package that I did about a year ago. Not sure, but maybe the bug is important enough to write a mail about it to the mailing list. Here's the problem: according to the documentation (and in pre-release versions of Brian 2 this worked), assigning/accessing state variables in a subtree refers to all compartments in the subtree, not only to the compartments in the specific section -- if you wanted the latter, you have to use main. However, currently this does only works correctly for the root section of the tree. A simple example:

sec1 = Cylinder(length=50*um, diameter=10*um, n=2)
sec1.sec2 = Cylinder(length=50 * um, diameter=10 * um, n=4)
sec1.sec2.sec3 = Cylinder(length=50 * um, diameter=10 * um, n=8)
neuron = SpatialNeuron(sec1, 'Im = 0*amp/meter**2 : amp/meter**2')

Now what works correctly is the root section, and setting individual sections with main:

>>> neuron.v = -70*mV  # set *all* compartments
>>> neuron.v
<spatialneuron.v: array([-70., -70., -70., -70., -70., -70., -70., -70., -70., -70., -70.,
       -70., -70., -70.]) * mvolt>
>>> neuron.main.v = -80*mV  # only first section
>>> neuron.v
<spatialneuron.v: array([-80., -80., -70., -70., -70., -70., -70., -70., -70., -70., -70.,
       -70., -70., -70.]) * mvolt>
>>> neuron.sec2.main.v = -90*mV  # only second section
>>> neuron.v
<spatialneuron.v: array([-80., -80., -90., -90., -90., -90., -70., -70., -70., -70., -70.,
       -70., -70., -70.]) * mvolt>

But setting the state variable on the subtree should set all compartments in that subtree, and this is not the case (it does the same thing as when using .main):

>>> neuron.sec2.v = -100*mV # Should set sec2 *and* sec3
>>> neuron.v
<spatialneuron.v: array([ -80.,  -80., -100., -100., -100., -100.,  -70.,  -70.,  -70.,
        -70.,  -70.,  -70.,  -70.,  -70.]) * mvolt>

Unfortunately, none of our tests, nor any of the examples used this feature... I have a fix ready, but I'm still doing some more testing. What makes this bug quite bad is that you don't get any error and you can get wrong results if you don't check that you actually set the values you wanted to set (I myself encountered this bug when I wanted to set a variable in a dendritic tree).

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