"Point process not located in a section" error with v7.5 but not v7.4

tclose
Posts: 27
Joined: Tue Jan 10, 2017 9:24 pm

"Point process not located in a section" error with v7.5 but not v7.4

Post by tclose »

Hi,

The following MWE apparently works fine with Neuron v7.4, but with v7.5 it gives the following error.

Code: Select all

loading membrane mechanisms from mod/x86_64/.libs/libnrnmech.so
Additional mechanisms from files
 no_section_mwe.mod
running
finitializing
running
Done testing
NEURON: NoSectionMWE[0] point process not located in a section
 near line 0
 while (t < tstop) { fadvance() }

Code: Select all

import subprocess as sp
import os.path
import shutil
import neuron

mod_dir = os.path.join(os.path.dirname(__file__), 'mod')

shutil.rmtree(os.path.join(mod_dir, 'x86_64'), ignore_errors=True)
orig_dir = os.getcwd()
os.chdir(mod_dir)
sp.check_call('nrnivmodl', shell=True)
os.chdir(orig_dir)
neuron.load_mechanisms(mod_dir)


sec = neuron.h.Section()
hoc = neuron.h.NoSectionMWE(0.5, sec=sec)
setattr(hoc, 'cm_int', 1.0)
setattr(hoc, 'R', 1.0)
setattr(hoc, 'tau', 1.0)
setattr(hoc, 'tau2', 1.0)
rec = neuron.h.NetCon(hoc, None, sec=sec)
print("running")
neuron.init()
print("finitializing")
neuron.h.finitialize()
print("running")
neuron.run(10)
print("Done testing")
where NoSectionMWE is defined as (in a 'mod' subdirectory next to the above script)

Code: Select all

NEURON {
    POINT_PROCESS NoSectionMWE
    NONSPECIFIC_CURRENT i_int

    RANGE a
    RANGE tau
    RANGE tau2
    RANGE R
    RANGE cm_int
    RANGE i_int
}


PARAMETER {
    tau = 0
    tau2 = 0
    R = 0
    cm_int = 0
}


ASSIGNED {
    i_int
    v
}

STATE {
    a
}


BREAKPOINT {
    SOLVE states METHOD derivimplicit
    i_int = -cm_int*(R*a - v)/tau
}


DERIVATIVE states {
    a' = (-a)/tau2

}


NET_RECEIVE(connection_weight_, channel) {
    
}
If I comment out the NetCon line (or all of the setattr lines) it doesn't throw an error but I don't understand why this would be. It is also strange in that it gives this error right at the end of the script instead of where the NetCon is called.

NB: I have replicated this error on OS X, Ubuntu 14.04 & 16.04
ted
Site Admin
Posts: 6286
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: "Point process not located in a section" error with v7.5 but not v7.4

Post by ted »

Before we even get started with the error message, let's look at the mod file, because it's not so clear that things were so great even under 7.4, error message or no error message. The mod file lacks all units declarations, omits initalization of its STATE variable, embeds a couple of traps for the unwary, and specifies an integration method that imposes unnecessary overhead.

What units do you want to use for the following:
tau
tau2
R
cm_int
i_int
v
a
Just asking to make sure that the equations make sense and that any necessary scale factors are included.

It is probably a good idea to specify a plausible nonzero default value for any parameter that will become the sole term in a denominator, e.g. tau and tau2. Or just set them all to 1 (in appropriate units).

If a STATE variable exists, there really should be an INITIAL block that initializes it. Otherwise if you execute a second run without first exiting neuron and then reexecuting your code, the value left over from the first run will corrupt the second run.

Code: Select all

INITIAL {
  a = 0
}
will take care of this, if you want a to start at 0 on each run.

The ODE in the DERIVATIVE block is for a simple first order decay. cnexp will be perfectly fine for this. derivimplicit is less efficient. For specific recommendations of what methods to use and why, see
Integration methods for SOLVE statements
in the Hot tips area of the Forum.

The following changes to the mod file fix the problems other than initialization (which is fixed by the INITIAL block), but I must admit that my choices for the units of a, tau, tau2, R, cm_int, i_int, and v are entirely arbitrary and may not be what you had in mind.

1. Insert this block

Code: Select all

UNITS {
  (mV) = (millivolt)
  (nA) = (nanoampere)
}
2. Change the PARAMETER, ASSIGNED, STATE, and BREAKPOINT blocks to

Code: Select all

PARAMETER {
  tau = 1 (ms)
  tau2 = 1 (ms)
  R = 1 (mV)
  cm_int = 1 (nA ms / mV)
}

ASSIGNED {
  i_int (nA)
  v (mV)
}

STATE {
  a (1)
}

BREAKPOINT {
:  SOLVE states METHOD derivimplicit
  SOLVE states METHOD cnexp
  i_int = -cm_int*(R*a - v)/tau
}
To move on to your chief complaint, we must resolve a critically important issue. This mechanism doesn't look like something that you'd want to attach to a section at all. It looks more like you ultimately want it to be some kind of artificial spiking cell, or maybe you're just trying to implement something that applies a 1st order low pass filter (leaky integrator) to a series of events. Is this inference correct?
tclose
Posts: 27
Joined: Tue Jan 10, 2017 9:24 pm

Re: "Point process not located in a section" error with v7.5 but not v7.4

Post by tclose »

Hi Ted,

Sorry I should have been more explicit, this code is just a toy example, a minimal "working" example (MWE) that reproduces the problem. The models that I have actually been working with are much more complex.

Am I right to interpret your line "To move on to your chief complaint, we must resolve a critically important issue" to mean this is a known issue that you are working on, or does the "critically important issue" refer to the fact that this model doesn't do anything useful?

Cheers,

Tom
tclose
Posts: 27
Joined: Tue Jan 10, 2017 9:24 pm

Re: "Point process not located in a section" error with v7.5 but not v7.4

Post by tclose »

FYI I also just ran into this error message when running a 7.4 version (which I had been before so I am not sure what is changed), although not with this MWE
ted
Site Admin
Posts: 6286
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: "Point process not located in a section" error with v7.5 but not v7.4

Post by ted »

we must resolve a critically important issue
The critically important issue is: what is it that you want this mechanism to do? You haven't said yet. If it's supposed to be a current source, then it must be attached to a section. If it should be an event-triggered current source, then it also needs to be the target of events from some event source. But your Python code treats it as if it is supposed to be an event source, like an artificial spiking cell. Which is correct? Regarding minimal working examples, worse than buggy code that generates error messages is buggy code that runs to completion without complaint.
tclose
Posts: 27
Joined: Tue Jan 10, 2017 9:24 pm

Re: "Point process not located in a section" error with v7.5 but not v7.4

Post by tclose »

Hi Ted,

I am working on a code-generation package so the models are somewhat arbitrary. In this case I extracted code from the izhikevich-type model below but the error also occurred for other models generated by my package. This mechanism is to be inserted into a section as a model of the total membrane current.

Code: Select all

TITLE Spiking node generated from 9ML using PyPe9 version 0.1 at 'Thu 02 Nov 17 12:12:03AM'

NEURON {
    POINT_PROCESS IzhikevichFastSpikingSimulateVersion
    NONSPECIFIC_CURRENT i___pype9
    : T
    RANGE regime_


    :StateVariables:
    RANGE U
    RANGE v

    :Parameters
    RANGE Cm
    RANGE Vb
    RANGE Vpeak
    RANGE Vr
    RANGE Vt
    RANGE a
    RANGE b
    RANGE c
    RANGE k

    : Analog receive ports

    :Aliases
    RANGE V_deriv
    RANGE i___pype9

    :Connection Parameters

}

UNITS {
    : Define symbols for base units
    (mV) = (millivolt)
    (nA) = (nanoamp)
    (nF) = (nanofarad)
    (uF) = (microfarad)
    (S)  = (siemens)
    (uS) = (microsiemens)
    (mM) = (milli/liter)
    (um) = (micrometer)
}

CONSTANT {
    : IDs for regimes, events and conditions

    : Transition flags
    INIT = -1
    ON_EVENT = 0

    : Regime ids
    SUBVB = 0
    SUBTHRESHOLD = 1

    : Event port ids

}

INITIAL {

    : Initialise the NET_RECEIVE block by sending appropriate flag to itself
    net_send(0, INIT)
}

PARAMETER {
    : True parameters
    Cm = 0 (nF)
    Vb = 0 (mV)
    Vpeak = 0 (mV)
    Vr = 0 (mV)
    Vt = 0 (mV)
    a = 0 (1/ms)
    b = 0 (uS/mV2)
    c = 0 (mV)
    k = 0 (uS/mV)

    : Constants

    : Units for connection properties


    : Unit correction for 't' used in printf in order to get modlunit to work.
    PER_MS = 1 (/ms)
}


ASSIGNED {
    : Internal flags
    regime_
    found_transition_

    : Analog receive ports

    : Aliases
    V_deriv (mV/ms)
    i___pype9 (nA)

    : State variables without explicit derivatives
    v (mV)

    :Connection Parameters
}

STATE {
    U (nA)
}


BREAKPOINT {
    SOLVE states METHOD derivimplicit
    V_deriv = (-U + k*(Vr - v)*(Vt - v))/Cm
    i___pype9 = -Cm*V_deriv
}


DERIVATIVE states {
    U' = deriv_U(U, v)
}

FUNCTION deriv_U(U (nA), v (mV)    ) (nA/ms) {
    if (regime_ == SUBVB) {
        deriv_U = -U*a

    } else if (regime_ == SUBTHRESHOLD) {
        deriv_U = -a*(U + b*((Vb - v)*(Vb - v)*(Vb - v)))
    }
}

NET_RECEIVE(connection_weight_, channel) {
    INITIAL {
      : stop channel being set to 0 by default
    }
    found_transition_ = -1
    if (flag == INIT) {
        : Set up required watch statements
        WATCH (v > Vb) 1  : Watch trigger of on-condition and send appropriate flag
        WATCH (v > Vpeak) 2  : Watch trigger of on-condition and send appropriate flag
        WATCH (v < Vb) 3  : Watch trigger of on-condition and send appropriate flag
    } else if (regime_ == SUBVB) {
        if (flag == 1) {  : Condition 'v > Vb'

            : Required aliases

            : State assignments

            : Output events

            : Regime transition
            if (found_transition_ == -1) {
                found_transition_ = flag
            } else {
                printf("WARNING!! Found multiple transitions %f and %f at time %f", found_transition_, flag, t * PER_MS)
            }
            regime_ = SUBTHRESHOLD

        }
    } else if (regime_ == SUBTHRESHOLD) {
        if (flag == 2) {  : Condition 'v > Vpeak'

            : Required aliases

            : State assignments
            v = c

            : Output events
            net_event(t)  : FIXME: Need to specify which output port this is

            : Regime transition
            if (found_transition_ == -1) {
                found_transition_ = flag
            } else {
                printf("WARNING!! Found multiple transitions %f and %f at time %f", found_transition_, flag, t * PER_MS)
            }
            regime_ = SUBTHRESHOLD

        }
        if (flag == 3) {  : Condition 'v < Vb'

            : Required aliases

            : State assignments

            : Output events

            : Regime transition
            if (found_transition_ == -1) {
                found_transition_ = flag
            } else {
                printf("WARNING!! Found multiple transitions %f and %f at time %f", found_transition_, flag, t * PER_MS)
            }
            regime_ = SUBVB

        }
    } else {
        printf("ERROR! Unrecognised regime %f", regime_)
    }
}
So my question is, what does the error message mean (i.e. what am I doing wrong in my code that is causing the error)? This should be independent of my intended use for the model, no?
ted
Site Admin
Posts: 6286
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: "Point process not located in a section" error with v7.5 but not v7.4

Post by ted »

This mechanism is to be inserted into a section as a model of the total membrane current.
Are you sure? Total membrane current includes both ionic current and capacitive current. If both are included, then the mechanism has everything it needs to calculate "membrane potential" (or what the ANN types call "activation"), so why bother with sections at all? Just make it an artificial spiking cell.
tclose
Posts: 27
Joined: Tue Jan 10, 2017 9:24 pm

Re: "Point process not located in a section" error with v7.5 but not v7.4

Post by tclose »

Hi Ted,

I think we are getting somewhat off the point, but yes in this case the Izhikevich model could be implemented as an artificial cell. The reason it isn't is that by making it a point process allows arbitrary synaptic mechanisms or clamps to be inserted into the cell along side it.

But in any case, my query isn't about which is the best model to use (as I am trying to write code that can handle arbitrary models), or design decisions I have made to achieve this (as useful as they may be). I have my package working well with Python 2.7 and don't have time for a major refactor it at this stage unless absolutely necessary.

The only problem I have remaining is that when I run my test suite on Python 3 I get this strange error. I am guessing that it is caused by some sort of buffer overrun, so I thought by including the MWE it would make it much easier to track down. I have reproduced this error on OS X and Ubuntu 14.04 & 16.04 so it seems fairly persistent but if you can't reproduce it let me know I can share with you an Ubuntu Docker image I have created if it helps to debug it.

Thanks,

Tom
ted
Site Admin
Posts: 6286
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: "Point process not located in a section" error with v7.5 but not v7.4

Post by ted »

This
by making it a point process allows arbitrary synaptic mechanisms or clamps to be inserted into the cell along side it
and the complete mod file explain a lot. You attach the mechanism to a section and let that section integrate the "current" generated by it and other mechanisms. Good. I now have only one comment about the mod file--and you may know this already, but many readers of this thread may not: since the mod file assigns a value to membrane potential of the section to which it is attached, it can only be used with fixed time step integration (after such a change, the adaptive integrators require reinitialization by a call to cvode_reinit(), which can only be done at the interpreter level). However, this isn't a serious limitation because adaptive integration generally isn't useful in network simulations.

Back to your original question. I don't have your elaborate configuration, so before running my own test I commented out everything from
import subprocess as sp
to
neuron.load_mechanisms(mod_dir)
except for
import neuron
and executed the code with VERSION 7.5 master (8ae0ca8) 2017-10-08.
This produced the error message you reported. However, the point process was indeed attached to the section, as you can see by appending
neuron.h.psection()
immediately after
print("Done testing")
Execute the revised code and you'll get

Code: Select all

__nrnsec_0x15e28c0 { nseg=1  L=100  Ra=35.4
	/*location 0 attached to cell 0*/
	/* First segment only */
	insert morphology { diam=500}
	insert capacitance { cm=1}
	insert NoSectionMWE { a0=1 tau=1 tau2=1 R=1 cm_int=1}
}
but right after that comes the error message again!

So I made these changes:

1. insert
neuron.h.load_file('stdrun.hoc')
right after
import neuron
2. change the block
neuron.init()
. . .
neuron.run(10)
to
neuron.h.tstop = 10
neuron.h.run() # initializes and runs to tstop

and tried again. This time, no error message. A bit more tinkering revealed that neuron.run() is triggering the error message, but until that is fixed you now have a workaround.
tclose
Posts: 27
Joined: Tue Jan 10, 2017 9:24 pm

Re: "Point process not located in a section" error with v7.5 but not v7.4

Post by tclose »

it can only be used with fixed time step integration (after such a change, the adaptive integrators require reinitialization by a call to cvode_reinit(), which can only be done at the interpreter level). However, this isn't a serious limitation because adaptive integration generally isn't useful in network simulations.
Thanks for the reminder, I am pretty sure I was aware of this at one point but may have forgotten about it. In any case, CVODE support isn't on my roadmap at the moment so it is not an immediate problem.

I tried your workaround with my MWE and it resolved the issue. However, the problem is that my actual code-gen package uses PyNN's simulation control methods, which uses parallel context's psolve, so it is not straightforward to apply your workaround.

What are the differences between using neuron.run and neuron.h.run() (naively I would have assumed them to be aliases of one another)? Maybe we could look into these differences in order to track down the problem)? Is there an equivalent workaround for parallel context's psolve?
tclose
Posts: 27
Joined: Tue Jan 10, 2017 9:24 pm

Re: "Point process not located in a section" error with v7.5 but not v7.4

Post by tclose »

Actually, I just checked when this error occurs in one of my "network construction" unittests and it is before the 'run' method even gets called. So it definitely looks like some kind of memory overrun issue rather than a specific problem with the neuron.run method.
ted
Site Admin
Posts: 6286
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: "Point process not located in a section" error with v7.5 but not v7.4

Post by ted »

What are the differences between using neuron.run and neuron.h.run()
Syntax is the only difference that I know of. neuron.run() expects a numerical argument that specifies the stop time; h.run() expects that h.tstop has already been assigned a numerical value that specifies the stop time. Somehow neuron.run() is revealing a bug.
my actual code-gen package uses PyNN's simulation control methods, which uses parallel context's psolve, so it is not straightforward to apply your workaround.
. . .
Is there an equivalent workaround for parallel context's psolve?
I know little about PyNN and less about how it deals with simulation control. psolve(tstop) is triggering the same error message?
tclose
Posts: 27
Joined: Tue Jan 10, 2017 9:24 pm

Re: "Point process not located in a section" error with v7.5 but not v7.4

Post by tclose »

When I looked at my unittests again, it turns out I can reproduce the error without even running the model (i.e. before it even gets to psolve). So switching the run methods looks like a bit of red herring.

I realise that buffer overflow errors are real bastards to track down but is there any chance someone could have a look at the fundamental cause of this, as otherwise I fear it will keep rearing its head up in different places?
hines
Site Admin
Posts: 1682
Joined: Wed May 18, 2005 3:32 pm

Re: "Point process not located in a section" error with v7.5 but not v7.4

Post by hines »

I could not reproduce the bug by launching nrniv -python test.py
but it did occur when launching python test.py
The bug does not occur when launching python interactively, python -i test.py
until exiting with ^D which suggests that it is a cleanup problem during exit
If one places a
del rec
just after print("Done testing") the problem goes away.
When destroying a model it is a good idea to delete NetCon, POINT_PROCESS, Section in that order.
I can force the error with
del sec # hoc become "not located in a section"
del rec
It seems that the destruction of rec requires me to check to see if the source and target are valid before before calling the method that
detaches them from the NetCon. I will investigate further and fix the problem.
hines
Site Admin
Posts: 1682
Joined: Wed May 18, 2005 3:32 pm

Re: "Point process not located in a section" error with v7.5 but not v7.4

Post by hines »

I believe this problem is now fixed in the change
https://github.com/nrnhines/nrn/commit/ ... 26a6bd179d
The log message is
Deleteing a NetCon when the source Point_process is unlocated could
cause a memory error in python due to hoc_execerror that could not be handled.
I.e That can happen on Python cleanup on exit if a section was deleted
prior to deleting a NetCon when it points to a source that was located
in the section.
Post Reply