0

Is there any way to serialize and de-serialize objects (such as pydrake.trajectories.PiecewisePolynomial, Expression ...) using pickle or some other way?

It does not complain when I serialize it, but when trying to load from file it complains:

TypeError: pybind11_object.__new__(pydrake.trajectories.PiecewisePolynomial) is not safe, use object.__new__()
GuyS
  • 85
  • 6

1 Answers1

0

Is there a list of classes you would like to serialize / pickle?

I can create an issue for you, or you can create one if you have a list already in mind.


More background:

Pickling for pybind11 (which is what pydrake uses) has to be defined manually: https://pybind11.readthedocs.io/en/stable/advanced/classes.html#pickling-support

At present, we don't have a roadmap in Drake to serialize everything, so it's a per-class basis at present.

For example, for pickling RigidTransform: issue link and PR link

A simpler pickling example for CameraInfo: PR link

(FTR, if an object is easily recoverable from it's construction arguments, it should be trivial to define pickling.

Eric Cousineau
  • 1,944
  • 14
  • 23
  • Classes are PiecewisePolynomial and Expression that is composed from program indeterminates. I was wondering if there's something that could be done as-is. I'm using Ubuntu 16.04 so I wouldn't want to update Drake in any case since it is not supported anymore (for the time being). I have ways of saving just the "data" I need to re-create it after loading it back. Thanks. – GuyS Nov 26 '19 at 13:48
  • Unfortunately, I'm not aware of a general solution without updating Drake, so yeah, your manual saving of just the "data" is going to be the best way under those constraints. Thanks for the info! – Eric Cousineau Nov 26 '19 at 20:49