Page 1 of 1
how to delete a Point Process object
Posted: Wed Jul 23, 2014 6:29 pm
by oren
Hello,
I am trying to delete an Impedance tool in python but I can not manage to do it.
in hoc it is very easy
Code: Select all
objref zz
create soma
zz = new Impedance()
Impedance[0]
I get Impedance[0]
When I do
I get
nrniv: Object ID doesn't exist: Impedance[0]
As expected!
--------------------------------------------------------------------------
But when I try the same thing in python
Code: Select all
from neuron import h
soma = h.Section()
zz= h.Impedance()
h.Impedance[0]
I get
<hoc.HocObject at 0x1218c90>
When I try to delete the referance
I still get
<hoc.HocObject at 0x1218f60>
I also try the StringFunctions()
Code: Select all
str = h.StringFunctions()
str.references(Impedance[0])
I get
Impedance[0] has 4 references
found 0 of them
So how can I delete the Impedance tool? ( The same thing happens with IClamp VClamp ect..)
Thank You
Re: how to delete a Point Process object
Posted: Thu Jul 24, 2014 8:41 am
by ted
zz=None deletes it.
Code: Select all
>>> from neuron import h
>>> soma = h.Section()
>>> zz = h.Impedance()
>>> zz
<hoc.HocObject object at 0x9337cf0>
>>> h.allobjects("Impedance")
Impedance[0] with 1 refs
0.0
>>> zz=None
>>> h.allobjects("Impedance")
0.0
>>> h.Impedance[0]
Traceback (most recent call last):
File "stdin", line 1, in <module>
IndexError: Impedance[0] instance does not exist
By the way, the Impedance class is not a "Point Process object". Most "point process" classes are localized signal sources, like a synaptic mechanism or a current or voltage clamp--something that generates a current that is localized to a region that is very small compared to the space constants for membrane potential or ionic diffusion. One (APcount) counts the number of times the voltage at its location crosses a threshold voltage in the positive direction. Some are spike sources (generate events that can be monitured by NetCons and delivered to targets).
Re: how to delete a Point Process object
Posted: Thu Jul 24, 2014 9:01 am
by oren
Hello Ted,
Thank You,
When I run your code, I do manage to delete the Impedance,
But when I run the following code
Code: Select all
from neuron import h
soma = h.Section()
zz= h.Impedance()
h.Impedance[0]
zz = None
zz= None does not delete the Impedance,
Can you try it?
It seems that running the line
h.Impedance[0]
make a reference to this object, and then zz=None does not delete it, am I correct ?
Thank You,
Oren.
Re: how to delete a Point Process object
Posted: Thu Jul 24, 2014 10:45 am
by hines
I'll look into this. It is a puzzle because it seems to happen only as long as there is limited communication with the
hoc interpreter from python and the commands are entered from the terminal window. I presume your experience shadows the comments below
Code: Select all
from neuron import h
soma = h.Section()
zz= h.Impedance()
h.Impedance[0]
zz=None
print 'hello'
h.Impedance[0] #still exists if copy pasted to the interpreter, does not exist if executed from a file
h.allobjects()
print 'goodbye'
h.Impedance[0] #raises an error
Re: how to delete a Point Process object
Posted: Thu Jul 24, 2014 11:14 am
by hines
The issue arose from the fact that in interactive mode at least, the interpreter saves the last expression return value in the variable '_'. I.e. consider the following transcript
Code: Select all
>>> from neuron import h
>>> soma = h.Section()
>>> zz= h.Impedance()
>>> h.Impedance[0]
<hoc.HocObject object at 0x2c01ae0>
>>> zz=None
>>> _
<hoc.HocObject object at 0x2c01ae0>
>>> 1
1
>>> h.Impedance[0]
Traceback (most recent call last):
File "stdin", line 1, in <module>
IndexError: Impedance[0] instance does not exist
Re: how to delete a Point Process object
Posted: Thu Jul 24, 2014 11:32 am
by oren
Hi Michel
Thank You,
In python your code does work,
But in
ipython it does not work
Code: Select all
In [2]: soma = h.Section()
In [3]: zz= h.Impedance()
In [4]: h.Impedance[0]
Out[4]: <hoc.HocObject at 0x1a0c420>
In [5]: zz=None
In [6]: _
Out[6]: <hoc.HocObject at 0x1a0c420>
In [7]: 1
Out[7]: 1
In [8]: h.Impedance[0]
Out[8]: <hoc.HocObject at 0x1a0c588>
But now I understand where to look...
Thank You,
Oren.
Re: how to delete a Point Process object
Posted: Thu Jul 24, 2014 12:46 pm
by hines
Yes. I believe IPython saves every return value for expressions typed interactively.
Re: how to delete a Point Process object
Posted: Sun Jul 27, 2014 2:52 am
by oren
seems to fix the problem.
Re: how to delete a Point Process object
Posted: Sun Jan 27, 2019 3:52 pm
by Marin
Sorry to resurrect this old thread, but has a final solution to this problem been found? I really enjoy working with NEURON in a jupyter notebook, but I cannot seem to be able to delete a PointProcess. Here is a sample output from a notebook:
Code: Select all
from neuron import h
soma = h.Section()
soma.psection()
Code: Select all
{'point_processes': {},
'density_mechs': {},
'ions': {},
'morphology': {'L': 100.0,
'diam': [500.0],
'pts3d': [],
'parent': None,
'trueparent': None},
'nseg': 1,
'Ra': 35.4,
'cm': [1.0],
'regions': set(),
'species': set(),
'name': '__nrnsec_0x7fd9f8ad8e00',
'hoc_internal_name': '__nrnsec_0x7fd9f8ad8e00',
'cell': None}
Code: Select all
i = h.IClamp(0.5, sec=soma)
soma.psection()
Code: Select all
{'point_processes': {'IClamp': {IClamp[0]}},
'density_mechs': {},
'ions': {},
'morphology': {'L': 100.0,
'diam': [500.0],
'pts3d': [],
'parent': None,
'trueparent': None},
'nseg': 1,
'Ra': 35.4,
'cm': [1.0],
'regions': set(),
'species': set(),
'name': '__nrnsec_0x7fd9f8ad8e00',
'hoc_internal_name': '__nrnsec_0x7fd9f8ad8e00',
'cell': None}
Code: Select all
i = None
_
None
[code]soma.psection()
Code: Select all
{'point_processes': {'IClamp': {IClamp[0]}},
'density_mechs': {},
'ions': {},
'morphology': {'L': 100.0,
'diam': [500.0],
'pts3d': [],
'parent': None,
'trueparent': None},
'nseg': 1,
'Ra': 35.4,
'cm': [1.0],
'regions': set(),
'species': set(),
'name': '__nrnsec_0x7fd9f8ad8e00',
'hoc_internal_name': '__nrnsec_0x7fd9f8ad8e00',
'cell': None}
Code: Select all
Flushing output cache (5 entries)
Code: Select all
{'point_processes': {'IClamp': {IClamp[0]}},
'density_mechs': {},
'ions': {},
'morphology': {'L': 100.0,
'diam': [500.0],
'pts3d': [],
'parent': None,
'trueparent': None},
'nseg': 1,
'Ra': 35.4,
'cm': [1.0],
'regions': set(),
'species': set(),
'name': '__nrnsec_0x7fd9f8ad8e00',
'hoc_internal_name': '__nrnsec_0x7fd9f8ad8e00',
'cell': None}
Thanks!
EDIT: I should say I'm using NEURON -- VERSION 7.6.4 master (50728e66) 2018-12-14
Re: how to delete a Point Process object
Posted: Mon Jan 28, 2019 9:00 am
by hines
Something mysterious is going on with jupyter that I can't yet quite figure out.
Can you work around the problem with
print (soma.psection())
Everytime Jupyter default pretty prints the result of soma.psection(), the hoc reference count of the POINT_PROCESS is incremented
and never gets decremented even with a reset -f Out.
(note: my "jupyter console" even alphabetically sorts the pretty print) e.g.
Code: Select all
hines@hines-T7500:~$ jupyter console
Jupyter console 5.2.0
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
Type "copyright", "credits" or "license" for more information.
IPython 5.5.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: from neuron import h
In [2]: soma = h.Section()
In [3]: i = h.IClamp(soma(.5))
In [4]: print (soma.psection())
{'point_processes': {'IClamp': {IClamp[0]}}, 'density_mechs': {}, 'ions': {}, 'morphology': {'L': 100.0, 'diam': [500.0], 'pts3d': [], 'parent': None, 'trueparent': None}, 'nseg': 1, 'Ra': 35.4, 'cm': [1.0], 'regions': set(), 'species': set(), 'name': '__nrnsec_0x4d9af70', 'hoc_internal_name': '__nrnsec_0x4d9af70', 'cell': None}
In [5]: h.allobjects()
IClamp[0] with 1 refs
MechanismType[1] with 1 refs
CVode[0] with 1 refs
Out[5]: 0.0
In [6]: i=None
In [7]: h.allobjects()
MechanismType[1] with 1 refs
CVode[0] with 1 refs
Out[7]: 0.0
In [8]: i = h.IClamp(soma(.5))
In [9]: soma.psection()
Out[9]:
{'Ra': 35.4,
'cell': None,
'cm': [1.0],
'density_mechs': {},
'hoc_internal_name': '__nrnsec_0x4d9af70',
'ions': {},
'morphology': {'L': 100.0,
'diam': [500.0],
'parent': None,
'pts3d': [],
'trueparent': None},
'name': '__nrnsec_0x4d9af70',
'nseg': 1,
'point_processes': {'IClamp': {IClamp[0]}},
'regions': set(),
'species': set()}
In [10]: h.allobjects()
IClamp[0] with 2 refs
MechanismType[3] with 1 refs
CVode[0] with 1 refs
Out[10]: 0.0
In [11]: %reset -f Out
Flushing output cache (4 entries)
In [12]: h.allobjects()
IClamp[0] with 2 refs
MechanismType[3] with 1 refs
CVode[0] with 1 refs
Out[12]: 0.0
In [13]: i=None
In [14]: h.allobjects()
IClamp[0] with 1 refs
MechanismType[3] with 1 refs
CVode[0] with 1 refs
Out[14]: 0.0
In [15]: whos
Variable Type Data/Info
---------------------------------
h HocObject <TopLevelHocInterpreter>
i NoneType None
soma Section __nrnsec_0x4d9af70
In [16]:
Re: how to delete a Point Process object
Posted: Mon Jan 28, 2019 4:33 pm
by Marin
Thanks, using
seems to solve the problem. How weird.
BTW, is there a reason
uses stderr instead of stdout? In my notebook, the output from that function shows up in the terminal, and not inside a cell because of it;
Re: how to delete a Point Process object
Posted: Mon Jan 28, 2019 4:46 pm
by hines
is there a reason
I don't know the reason yet.
In my notebook, the output from that function shows up in the terminal
Today I pushed a fix in the master branch of github.com/neuronsimulator/nrn that directs the output of
h.allobjects() to stdout of Python.