Detailed description |
|
It appears that Quantity objects can be pickled without a problem, unpickling causes an error that the recursion limit has been exceeded. The demo code demonstrates this issue on my system (Python 2.6.4, numpy 1.4.0), though the error message thrown is not very illuminating.
I originally discovered this problem in my efforts to use Parallel Python to parallelize some pyopenmm code. (Note that I'm not transporting any Swig objects over the network that shouldn't be pickleable.) When my (complex) Parallel Python code fails, I get a aomewhat more illuminating error message suggesting a problem with the delegation of __getattr__ by Quantity:
File "/Users/jchodera/local/python/lib/python2.6/site-packages/simtk/unit/quantity.py",
line 163, in __getattr__
ret_val = getattr(self._value, attribute)
Simple demo code follows.
----
import simtk.unit
import numpy
x = numpy.zeros([10], numpy.float64)
quantity = simtk.unit.Quantity(x, simtk.unit.amu)
import pickle
outfile = open('pickle_test.pkl', 'wb')
pickle.dump(quantity, outfile)
outfile.close()
infile = open('pickle_test.pkl', 'rb')
new_quantity = pickle.load(infile)
infile.close() |
|