reset NEURON
Moderator: hines
reset NEURON
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
Kind regards, Ben
Re: reset NEURON
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()
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()
-
- Site Admin
- Posts: 6384
- Joined: Wed May 18, 2005 4:50 pm
- Location: Yale University School of Medicine
- Contact:
Re: reset NEURON
Other top level hoc objects (Vectors, Graphs etc.) will also persist unless you unref them.unref all the NetCon
unref all the cell objects
Re: reset NEURON
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
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
-
- Site Admin
- Posts: 6384
- Joined: Wed May 18, 2005 4:50 pm
- Location: Yale University School of Medicine
- Contact:
Re: reset NEURON
Then I guess your code is an example for which the statementProkopiou 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).
is true for a reason that is not helpful to you.For a single top level cell
it usually suffices to
forall delete_section()
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.
-
- Posts: 270
- Joined: Fri Nov 28, 2008 3:38 pm
- Location: Yale School of Public Health
Re: reset NEURON
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.
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...ted wrote:The workaround that always works is to create a class based on your model cell.
-
- Posts: 41
- Joined: Sun Aug 08, 2010 11:09 am
Re: reset NEURON
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.
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.
-
- Site Admin
- Posts: 6384
- Joined: Wed May 18, 2005 4:50 pm
- Location: Yale University School of Medicine
- Contact:
Re: reset NEURON
Sorry about the delay in answering your question.
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
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.
Suppose this is how you created the ParallelContext instance:ParallelContext.gid_clear()
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
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.unref all the NetCon
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.
Same strategy as getting rid of all NetCons, except the part about NetCon record obviously doesn't apply.unref all the cell objects.
-
- Posts: 41
- Joined: Sun Aug 08, 2010 11:09 am
Re: reset NEURON
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" ?
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" ?
-
- Site Admin
- Posts: 6384
- Joined: Wed May 18, 2005 4:50 pm
- Location: Yale University School of Medicine
- Contact:
Re: reset NEURON
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.
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.
Re: reset NEURON
Hi All,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
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())
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())
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())