NEURON 7.2 + Python + cPickle on Fedora 17- hoc module error

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

Moderator: hines

Post Reply
phendric
Posts: 18
Joined: Tue Apr 21, 2009 12:57 am

NEURON 7.2 + Python + cPickle on Fedora 17- hoc module error

Post by phendric » Fri Feb 08, 2013 8:08 pm

Guys,

I'm trying to do something that may seem a little odd - I want to serialize a NEURON cell and write it to disk so that I can move it to another computer (and easily load the cell again).

The cell is implemented using a combination of HOC and Python code, and I'm using the cPickle module to try to dump the cell to disk. When I do so, I get the following error:

Code: Select all

PicklingError                             Traceback (most recent call last)
/usr/lib/python2.7/site-packages/IPython/utils/py3compat.pyc in execfile(fname, *where)
    173             else:
    174                 filename = fname
--> 175             __builtin__.execfile(filename, *where)

[removed]/pickleCellClass.py in <module>()
     22 
     23 f = open("cPickle_Test",'w')
---> 24 cPickle.dump(GC,f,protocol=2)
     25 f.close()
     26 

PicklingError: Can't pickle <type 'hoc.HocObject'>: import of module hoc failed

In [1]: hoc
Out[1]: <module 'neuron.hoc' from '/usr/lib64/python2.7/site-packages/neuron/hoc.so'>

In [2]: 
where the major error is the following:

PicklingError: Can't pickle <type 'hoc.HocObject'>: import of module hoc failed

I got to this by calling

ipython -i <filename>

If I get to it by calling

nrniv -python <filename>

then I can successfully write the cell to disk. However, when I read it back in again, I get the following ("original" is the original cell, "new" is the cell read in from disk):

Code: Select all

>>> original.c.all
<hoc.HocObject object at 0x1aa8b28>
>>> new.c.all
Traceback (most recent call last):
  File "stdin", line 1, in <module>
AttributeError: 'hoc.HocObject' object has no attribute 'all'
So it looks like, in this case as well, though the write-to-disk appeared to occur successfully, it actually didn't, as the hoc object isn't right when it gets read back in...

Any ideas about what's going on here?

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

Re: NEURON 7.2 + Python + cPickle on Fedora 17- hoc module e

Post by ted » Sun Feb 10, 2013 10:47 am

phendric wrote:I want to serialize a NEURON cell and write it to disk so that I can move it to another computer (and easily load the cell again).
The way to "move" a model implementation from one machine to another is to make a copy of its source code (hoc, ses, mod, py, and whatever data files may be required) and put them on the destination machine.

phendric
Posts: 18
Joined: Tue Apr 21, 2009 12:57 am

Re: NEURON 7.2 + Python + cPickle on Fedora 17- hoc module e

Post by phendric » Tue Feb 12, 2013 2:07 pm

Ted, well, it's not quite as simple as you make it out to be - when what you want to "move" is a small part of a much larger model implementation (ie, only a few cells of a much larger network), you can't just copy and paste the source code and data files.

That's the route I ended up going...but it still doesn't answer my question. Why does the serialization process not work? It should, since I compiled NEURON as a Python module...

hines
Site Admin
Posts: 1575
Joined: Wed May 18, 2005 3:32 pm

Re: NEURON 7.2 + Python + cPickle on Fedora 17- hoc module e

Post by hines » Wed Feb 13, 2013 9:14 am

I'm afraid that nothing in the hoc world is pickleable. That is, I have no implementation for it. I'm definitely going to give h.Vector a pickle interface because pickle is used
to transfer data between processes with the ParallelContext bulletin board and hoc Vectors are often used in that context (presently one would have to convert to a numpy array,
transfer that, and convert back again ), but I
have no plans for anything else in that regard.

The supported strategy for setting up parallel network simulations is detailed in
http://www.neuron.yale.edu/neuron/stati ... nm2008.pdf

Post Reply