GuyS
GuyS

Reputation: 105

Serializing Drake objects with Python

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__()

Upvotes: 1

Views: 78

Answers (1)

Eric Cousineau
Eric Cousineau

Reputation: 2004

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.

Upvotes: 0

Related Questions