pycddlib icon indicating copy to clipboard operation
pycddlib copied to clipboard

cdd objects not picklable (TypeError: no default __reduce__ due to non-trivial __cinit__)

Open bobmyhill opened this issue 5 years ago • 1 comments

cdd objects are currently not picklable. The following exception is raised: TypeError: no default __reduce__ due to non-trivial __cinit__

Minimal non-working example:

import cdd import pickle

mat = cdd.Matrix([[1, 1, 0], [1, 0, 1], [1, -1, 0], [1, 0, -1]], number_type="fraction") mat.rep_type = cdd.RepType.INEQUALITY poly = cdd.Polyhedron(mat)

and then either of the following two lines:

pickle.dump( mat, open( "save.p", "wb" ) ) pickle.dump( poly, open( "save.p", "wb" ) )

I can work around this issue, but I thought I should raise it in case anyone else needs/wants to serialise their cdd objects.

bobmyhill avatar Jan 22 '21 18:01 bobmyhill

Thanks for reporting. Implementing one of these guys should do the trick:

https://docs.python.org/3/library/pickle.html#object.__reduce__ https://docs.python.org/3/library/copyreg.html#module-copyreg

Shouldn't be too hard. I'll try to get around to this, but also happy to take a patch.

mcmtroffaes avatar Jan 23 '21 14:01 mcmtroffaes

This is now supported on the develop branch, and will be included with the new 3.0.0 release (currently in beta - I've had to rework the API to properly support type hints, this also fixed some bugs along the way and paved the way to much more easily support pickling). You can find a beta release here:

https://pypi.org/project/pycddlib/3.0.0b1/#files

mcmtroffaes avatar Sep 15 '24 15:09 mcmtroffaes