How to save a class object with a Drake plant object inside?

Viewed 29

pickle.dump(pendulum, open("obj/pendulum1.obj", "wb")) returns TypeError: cannot pickle 'pydrake.examples.pendulum.PendulumPlant' object. Here, pendulum is an object of a self-defined class with an PendulumPlant object inside.

Is it because pydrake is not natively written in python?

1 Answers

Correct. Most of the C++-backed classes in pydrake are not pickle-able

Some of the elementary pydrake classes are pickable though, such RigidTransform, RotationMatrix, etc. (See https://github.com/RobotLocomotion/drake/pull/11976.)

We could add pickling for some kinds of additional classes, but pickling a System or a Diagram is likely to be too difficult.

To save + restore a System like the pendulum, I'd say that re-creating the plant from scratch should be good -- it has no internal state so any one instance is the same as any other instance.

Related