You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Pele Cython classes are currently non pickable, they require a reduce method to be able to recreate a copy of the original object after being unpicked. This is because Pickle does not know anything about the nature of extension types. I came across this problem trying to parallelise some code with multiprocessing.
This is a minimal example of the approach I have taken so far:
cdef class PickableCythonClass:
cdef potential
cdef coords
cdef __cinit__(pot, x):
cdef _pele.BasePotential potential = pot
cdef np.ndarray[dtype='d'] coords = x
self.potential = potential
self.coords = x
cdef __reduce__(self):return(PickableCythonClass,(self.potential, self.coords))#note that the attributes have been passed as a tuple
if you think there's a better approach, please let me know.
The text was updated successfully, but these errors were encountered:
Pele Cython classes are currently non pickable, they require a reduce method to be able to recreate a copy of the original object after being unpicked. This is because Pickle does not know anything about the nature of extension types. I came across this problem trying to parallelise some code with multiprocessing.
Official documentation about the reduce method is available here
https://docs.python.org/2/library/pickle.html#pickling-and-unpickling-extension-types
I found it not very informative though due to lack of examples and in general not many examples are available on the web, this is a point lamented even by the cython developers.
This is a minimal example of the approach I have taken so far:
The text was updated successfully, but these errors were encountered: