NET_RECEIVE is not called when expected

NMODL and the Channel Builder.
Post Reply
lcampagn
Posts: 22
Joined: Mon Jul 07, 2014 1:12 pm

NET_RECEIVE is not called when expected

Post by lcampagn »

Greetings,

I am trying to write a simple point process that uses NET_RECEIVE, but so far I am unable to get any events delivered to the mechanism via NetCon. Here is my simplified mod file:

Code: Select all

TITLE NetCon test mechanism

NEURON {
    POINT_PROCESS NETTEST
    RANGE nRecv
}

ASSIGNED { nRecv }

INITIAL { nRecv = 0 }

NET_RECEIVE(weight) {
    nRecv = nRecv + 1
    VERBATIM
       fprintf(stderr, "  ---> Spike!");
    ENDVERBATIM
}
And here is the code I am using to test the mechanism:

Code: Select all

from neuron import h

cell = h.Section()
cell.insert('hh')
cell.insert('pas')

nt = h.NETTEST(0.5, sec=cell)
h.NetCon(cell(0.5)._ref_v, nt, -30, 0, 1.0)

ic = h.IClamp(0.5, sec=cell)
ic.delay = 20
ic.dur = 50
ic.amp = 20

vm = h.Vector()
vm.record(cell(0.5)._ref_v)

h.tstop = 100
h.run()

print "NetTest receives:", nt.nRecv
If I plot vm, I see one spike passing +30 mV, but the final print statement tells me that nt.nRecv is 0, and no "Spike!" messages were ever printed.

Anyone have a hint for me?
ted
Site Admin
Posts: 6289
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: NET_RECEIVE is not called when expected

Post by ted »

How to diagnose the problem: execute
nrngui -python nt.py
(nt.py is what I called the file that holds your Python code)
Then in the NEURON Main Menu toolbar click on Tools / Model View
Note that Model View reports "0 NetCon objects". What a handy tool.

How to interpret this finding:
h.NetCon( . . .
produces a NetCon with reference count 0, so the object is immediately destroyed.

How to fix the problem: change the statement to
nc = h.NetCon(cell( . . .

Comments: hh comes with its own passive "leak current" (read the Programmer's reference entry for hh) and doesn't need pas.
lcampagn
Posts: 22
Joined: Mon Jul 07, 2014 1:12 pm

Re: NET_RECEIVE is not called when expected

Post by lcampagn »

Thank you Ted! That was a bit surprising since some object types persist even if they are not given a reference (Section, for example).
Is there any way to do this kind of introspection from python? I'd like to be able to generate a structure similar to the output of ModelView for unit testing.
regger
Posts: 21
Joined: Sun Apr 22, 2012 9:49 pm

Re: NET_RECEIVE is not called when expected

Post by regger »

lcampagn wrote:Thank you Ted! That was a bit surprising since some object types persist even if they are not given a reference (Section, for example).
Actually, that's expected python behavior. The section is an exception, and if you don't assign it to a reference, it will be difficult to get a handle on this section at later points, unless you supply a section name and use h("...") statements...
lcampagn wrote: Is there any way to do this kind of introspection from python? I'd like to be able to generate a structure similar to the output of ModelView for unit testing.
Yes, look at dir() (built-in python function), this gives you run-time access to names of objects, although it may be a little bit tricky, since it also lists non-NEURON objects...

cheers,
Robert
lcampagn
Posts: 22
Joined: Mon Jul 07, 2014 1:12 pm

Re: NET_RECEIVE is not called when expected

Post by lcampagn »

regger wrote:
lcampagn wrote:Thank you Ted! That was a bit surprising since some object types persist even if they are not given a reference (Section, for example).
Actually, that's expected python behavior. The section is an exception, and if you don't assign it to a reference, it will be difficult to get a handle on this section at later points, unless you supply a section name and use h("...") statements...
I agree; shouldn't Sections also be removed when their references are lost?
regger wrote:
lcampagn wrote: Is there any way to do this kind of introspection from python? I'd like to be able to generate a structure similar to the output of ModelView for unit testing.
Yes, look at dir() (built-in python function), this gives you run-time access to names of objects, although it may be a little bit tricky, since it also lists non-NEURON objects...
Is there an object on which I can call dir() to list all NetCon objects, or do you mean that I should inspect the local namespace? Consider my actual task here: I am generating a simulation involving many different types of neurons, with their corresponding NEURON object definitions spread out over 30 or so files. In this situation, constructing a network of many neurons is a complex and error-prone operation. I would like to write unit tests to ensure that, after the network construction has completed, all of the underlying NEURON objects are generated as expected. There is no local namespace I can introspect to find all NetCon objects; I need to be able to ask NEURON what objects it knows about.
ted
Site Admin
Posts: 6289
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: NET_RECEIVE is not called when expected

Post by ted »

lcampagn wrote:shouldn't Sections also be removed when their references are lost?
How about this:
nrngui -python
then

Code: Select all

>>> dend = h.Section("dend")
>>> h.psection("dend")
dend.PySec_0xb72fa5d8 { nseg=1  L=100  Ra=35.4
	/*location 0 attached to cell 0*/
	/* First segment only */
	insert morphology { diam=500}
	insert capacitance { cm=1}
}
1.0
>>> h("forall psection()")
dend.PySec_0xb72fa5d8 { nseg=1  L=100  Ra=35.4
	/*location 0 attached to cell 0*/
	/* First segment only */
	insert morphology { diam=500}
	insert capacitance { cm=1}
}
1
>>> dend = 3
>>> h.psection("dend")
/usr/local/nrn/i686/bin/nrniv: Accessing a deleted section
 near line 13
 h.psection("dend")
                   ^
        psection("dend")
Traceback (most recent call last):
  File "stdin", line 1, in <module>
RuntimeError: hoc error
>>> h("forall psection()")
1
Is there an object on which I can call dir() to list all NetCon objects
Try
h.allobjects("NetCon")
Read about allobjects in the Programmer's Reference.
There is no local namespace I can introspect to find all NetCon objects
Seems like the wrong way to do it.
For each class X of which you want to keep track, append each instance to a list when you create it. These lists become the manifest of what is in the model.
lcampagn
Posts: 22
Joined: Mon Jul 07, 2014 1:12 pm

Re: NET_RECEIVE is not called when expected

Post by lcampagn »

Thanks, I see that Sections really are deleted when no more python references exist.
ted wrote:
Is there an object on which I can call dir() to list all NetCon objects
Try h.allobjects("NetCon")
Read about allobjects in the Programmer's Reference.
This is very close to what I need, but it only prints the results instead of returning them.
ted wrote:
There is no local namespace I can introspect to find all NetCon objects
Seems like the wrong way to do it.
For each class X of which you want to keep track, append each instance to a list when you create it. These lists become the manifest of what is in the model.
I disagree--I can keep a list of NEURON objects that I create, but this list will quickly become out of sync with the actual set of objects that NEURON knows about. In particular, it is likely that removing an item from the list will not result in removal from NEURON because there are likely to be extra references to these objects elsewhere in the program. Especially for large programs, leaked references can be very difficult to track and manage. So it seems that I have no way to explicitly remove objects from NEURON, and no way to programmatically ask NEURON what objects it knows about. I've tried using gc.get_objects() to search for leaked objects, but NEURON objects do not appear in this list.

The only solution I have come up with to avoid this situation is to write my own set of classes that wrap each NEURON class and that manage private references to the underlying NEURON objects. Alternatively, I can give up on allowing multiple simulation runs per process and instead spawn new processes for each run. I have been trying to avoid that, but then I came across this note:
Warning: Not very useful. No way to completely restart neuron exect to quit() and re-load.
(http://www.neuron.yale.edu/neuron/stati ... ml#initnrn)
So is starting one process per simulation really the recommended approach?
ted
Site Admin
Posts: 6289
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: NET_RECEIVE is not called when expected

Post by ted »

This discussion thread has wandered far from its original topic, and none of it has anything to do with "Adding new mechanisms and functions to NEURON" as that concept was originally conceived. I will split this thread into at least three pieces and put them where they belong:
the first 2.5 posts will go in a thread under Modeling networks
the stuff that deals with persistence & sections will go into a separate thread under NEURON + Python
the stuff about introspection of NEURON models will go into a second thread under NEURON + Python

Then there's the new issue raised in the most recent post, which may deserve a thread of its own.
lcampagn
Posts: 22
Joined: Mon Jul 07, 2014 1:12 pm

Re: NET_RECEIVE is not called when expected

Post by lcampagn »

Thanks, Ted, and sorry for the topic creep.
I will watch for these new threads.
Post Reply