reset NEURON

When Python is the interpreter, what is a good
design for the interface to the basic NEURON
concepts.

Moderator: hines

Post Reply
btorb
Posts: 30
Joined: Fri Oct 21, 2005 8:14 am

reset NEURON

Post by btorb »

Hi, Is there a way to "reset" NEURON? In Nest there is a ResetKernel() method. Since i experience some issues with the scope of NEURON in Python, it would be nice to see such a method. Did i overlook it until now? Or, is there a python way of completely reloading the NEURON module during execution?

Kind regards, Ben
hines
Site Admin
Posts: 1687
Joined: Wed May 18, 2005 3:32 pm

Re: reset NEURON

Post by hines »

There is no single function that "resets" the interpreter. To clear a model, it generally suffices
to use, in order,
ParallelContext.gid_clear()
unref all the NetCon
unref all the cell objects.

This assumes the usual network style of model construction. For a single top level cell
it usually suffices to
forall delete_section()
ted
Site Admin
Posts: 6299
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: reset NEURON

Post by ted »

unref all the NetCon
unref all the cell objects
Other top level hoc objects (Vectors, Graphs etc.) will also persist unless you unref them.
Prokopiou

Re: reset NEURON

Post by Prokopiou »

I am using a single top level cell and I'm having trouble clearing the hoc interpreter.

I tried executing h("forall delete_section()") but with no success (h.allsec() still returns the same sections).

I also tried looping through the sections in python's end (using for a in h.allsec()) and trying to set a = None (or del a) but still, nothing is deleted and h.allsec() still returns the same values.

This is an issue for me since every time I run my program in the same python interpreter, the hoc interpreter is not cleared and new sections are added to the previous ones.

Am I missing something?

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

Re: reset NEURON

Post by ted »

Prokopiou wrote:I am using a single top level cell and I'm having trouble clearing the hoc interpreter.

I tried executing h("forall delete_section()") but with no success (h.allsec() still returns the same sections).
Then I guess your code is an example for which the statement
For a single top level cell
it usually suffices to
forall delete_section()
is true for a reason that is not helpful to you.

The workaround that always works is to create a class based on your model cell. That will require a bit of programming effort, but it will solve the problem.
ramcdougal
Posts: 267
Joined: Fri Nov 28, 2008 3:38 pm
Location: Yale School of Public Health

Re: reset NEURON

Post by ramcdougal »

Prokopiou wrote:This is an issue for me since every time I run my program in the same python interpreter, the hoc interpreter is not cleared and new sections are added to the previous ones.
ted wrote:The workaround that always works is to create a class based on your model cell.
An alternative strategy for non-interactive programs is to only do simulations in a fresh copy of the main process made via os.fork(). Either write the output to a file or send it back to the original process via pipes for plotting, analysis, etc...
figoyouwei
Posts: 41
Joined: Sun Aug 08, 2010 11:09 am

Re: reset NEURON

Post by figoyouwei »

Hi Hines:

How exactly to do these three things in hoc and in PyNeuron ? thanks !

ParallelContext.gid_clear()
unref all the NetCon
unref all the cell objects.
ted
Site Admin
Posts: 6299
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: reset NEURON

Post by ted »

Sorry about the delay in answering your question.
ParallelContext.gid_clear()
Suppose this is how you created the ParallelContext instance:
objref pc
pc = new ParallelContext()
Then just execute
pc.gid_clear()

The Python usage would be
h.pc.gid_clear()
assuming that you did
from neuron import h
unref all the NetCon
Easiest way to do this is to keep track of each NetCon when you create it, by appending it to a List, and make sure that no objref points to any NetCon, so the only references to NetCon instances are in that list. Then you can unref that list, and poof! all of the NetCons vanish.

If you are using the NetCon record() method to capture spike times to one or more Vectors, you may also have to unref those Vectors in order to get rid of the NetCons; I'm not sure about this, so you'll have to verify for yourself.
unref all the cell objects.
Same strategy as getting rid of all NetCons, except the part about NetCon record obviously doesn't apply.
figoyouwei
Posts: 41
Joined: Sun Aug 08, 2010 11:09 am

Re: reset NEURON

Post by figoyouwei »

thanks for the syntax "pc.gid_clear()"

but what is exactly the syntax for "unref all the NetCon" ? When for example, all the NetCon objects are stored in a list call "nclist" ?
ted
Site Admin
Posts: 6299
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: reset NEURON

Post by ted »

Suppose each NetCon was created by executing a statement of the form
nclist.append(new NetCon(pre, post))
where nclist is an instance of the List class.

Then
objref nclist
will discard all references to NetCons, as long as there is no other objref that points to a NetCon.
romain.caze

Re: reset NEURON

Post by romain.caze »

Prokopiou wrote:I am using a single top level cell and I'm having trouble clearing the hoc interpreter.

I tried executing h("forall delete_section()") but with no success (h.allsec() still returns the same sections).

I also tried looping through the sections in python's end (using for a in h.allsec()) and trying to set a = None (or del a) but still, nothing is deleted and h.allsec() still returns the same values.

This is an issue for me since every time I run my program in the same python interpreter, the hoc interpreter is not cleared and new sections are added to the previous ones.

Am I missing something?

Thanks
Hi All,

To delete section from h you can use the following trick

Code: Select all

for sec in h.allsec():
    h("%s{delete_section()}"%sec.name())
This is working in the sense that if you create a section within h no prob like:

Code: Select all

from neuron import h
h("create foo")

#Return foo
for sec in h.allsec():
    print sec.name()

#Delete foo
for sec in h.allsec():
    h("%s{delete_section()}"%sec.name())

#This time return nothing
for sec in h.allsec():
    sec.name())
But if you use nrn to create a section you are gonna run into trouble (I let you the fun of discovering that (it is Friday afternoon here I do not have time to finish the post))

Code: Select all

from neuron import nrn
foo = nrn.Section(name="foo")

#Return foo
for sec in h.allsec():
    print sec.name()

#Delete foo
for sec in h.allsec():
    h("%s{delete_section()}"%sec.name())

#This time return foo?
for sec in h.allsec():
    sec.name())
Post Reply