crocoddyl icon indicating copy to clipboard operation
crocoddyl copied to clipboard

Pickling issues

Open gfadini opened this issue 4 years ago • 5 comments

Hello, can crocoddyl be pickled yet? I rember that @cmastalli said that there were issues with eigen for that, but maybe I'm mistaken and that is not the case anymore . I have a runtime error related to this using multiprocessing, it would be great if it could be fixed/was supported.

gfadini avatar Mar 04 '20 20:03 gfadini

You cannot pickle entire Crocoddyl data. However you could pickle some data, e.g. Pinocchio data, NumPy, etc.

Unfortunately I don't have time now for adding this feature.

cmastalli avatar Mar 04 '20 20:03 cmastalli

I would like to take this thread to discuss which classes / structures should be pickleable. I was thinking in this set of classes / structures:

  1. All data structures
  2. All model classes
  3. All solver classes
  4. Python list to/from std::vector
  5. Python Dict to/from std::map

What do you think? @proyan @gfadini @jcarpent @wxmerkt


This also requires a lot of work. I notice that there is a light alternative that will be faster to deploy but we need to inject a __getinitargs__ method, see details: https://www.boost.org/doc/libs/1_58_0/libs/python/doc/v2/pickle.html (picke4) is this would make sense for you guys?

cmastalli avatar Apr 02 '20 15:04 cmastalli

@cmastalli You should take inspiration from https://github.com/stack-of-tasks/pinocchio which is using the serialization for the pickling of large data structure, which is in the end much more efficient and allows to export in C++ too.

jcarpent avatar Apr 02 '20 15:04 jcarpent

The solver should not be pickable at first glance. Only data and model in the first place. By the way, for Python list, you should use the code from Pinocchio too.

jcarpent avatar Apr 02 '20 15:04 jcarpent

@cmastalli You should take inspiration from https://github.com/stack-of-tasks/pinocchio which is using the serialization for the pickling of large data structure, which is in the end much more efficient and allows to export in C++ too.

I reviewed again this code, and I have two questions.

  1. It seems to me that getinitargs assumes that there are no arguments for the object construction. So if I understand correctly, this function can be removed, right? What happens is my class needs some arguments?
  2. Does this code assume that the state of the instance is always a public member?

Ideally I would like to reuse this code for pickling action models and datas, however, it seems to me that it is not possible. I mean, I need to set some private states using set_XXX functions and pass some arguments to construct the object.

For me, the serialization mechanism is a bit obscure.

cmastalli avatar Jul 23 '20 13:07 cmastalli