[SciPy-Dev] issue pickling an interp1d object
Johann Cohen-Tanugi
johann.cohentanugi at gmail.com
Fri Sep 11 06:48:08 EDT 2015
Dear Scipy-ers,
I sent the email below to the user list yesterday, but perhaps this one
is a better medium. I forgot to mention that the problem is likely
related to the fact that I am using the interpolators within parallel
snippet of codes, using the multiprocessing module. It seems that
interp1d is not safe in the context of such usage, contrary (seemingly)
to InterpolatedUnivariateSpline. I do not know whether this is a bug or
a feature, and I have an obvious workaround, saving the arrays rather
than the interpolator
objects themselves.
best,
Johann
-------------------
Dear Scipy-ers,
I am using scipy (0.15.1) to interpolate a fairly complicate double
integral for several parameters, for later use in yet a third integral.
The pickling is thus of a dict of interpolators. When I am using
InterpolatedUnivariateSpline my code runs smoothly and dump a pickled
file. But when I use interp1d (with default protocol 0), I crash :
Traceback (most recent call last):
pickle.dump( interpolators, f )
File "/usr/lib/python2.7/pickle.py", line 1370, in dump
Pickler(file, protocol).dump(obj)
File "/usr/lib/python2.7/pickle.py", line 224, in dump
self.save(obj)
File "/usr/lib/python2.7/pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "/usr/lib/python2.7/pickle.py", line 649, in save_dict
self._batch_setitems(obj.iteritems())
File "/usr/lib/python2.7/pickle.py", line 663, in _batch_setitems
save(v)
File "/usr/lib/python2.7/pickle.py", line 306, in save
rv = reduce(self.proto)
File "/usr/lib/python2.7/copy_reg.py", line 77, in _reduce_ex
raise TypeError("a class that defines __slots__ without "
TypeError: a class that defines __slots__ without defining __getstate__
cannot be pickled
When I set the protocol to -1, I get a different crash :
pickle.dump( interpolators, f, protocol=-1 )
File "/usr/lib/python2.7/pickle.py", line 1370, in dump
Pickler(file, protocol).dump(obj)
File "/usr/lib/python2.7/pickle.py", line 224, in dump
self.save(obj)
File "/usr/lib/python2.7/pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "/usr/lib/python2.7/pickle.py", line 649, in save_dict
self._batch_setitems(obj.iteritems())
File "/usr/lib/python2.7/pickle.py", line 681, in _batch_setitems
save(v)
File "/usr/lib/python2.7/pickle.py", line 331, in save
self.save_reduce(obj=obj, *rv)
File "/usr/lib/python2.7/pickle.py", line 419, in save_reduce
save(state)
File "/usr/lib/python2.7/pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "/usr/lib/python2.7/pickle.py", line 548, in save_tuple
save(element)
File "/usr/lib/python2.7/pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "/usr/lib/python2.7/pickle.py", line 649, in save_dict
self._batch_setitems(obj.iteritems())
File "/usr/lib/python2.7/pickle.py", line 681, in _batch_setitems
save(v)
File "/usr/lib/python2.7/pickle.py", line 331, in save
self.save_reduce(obj=obj, *rv)
File "/usr/lib/python2.7/pickle.py", line 396, in save_reduce
save(cls)
File "/usr/lib/python2.7/pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "/usr/lib/python2.7/pickle.py", line 748, in save_global
(obj, module, name))
pickle.PicklingError: Can't pickle <type 'instancemethod'>: it's not
found as __builtin__.instancemethod
Does that ring a bell to anyone, before I start simplifying my code to
provide this list with a test case?
Thanks a lot in advance,
Johann
More information about the SciPy-Dev
mailing list