Save and load objects from python
Created by: gcarleo
The last main design issue to be solved for v2.0 concerns saving and loading objects from python.
Pybind11 has some pickling support.
However, the design issue to be addressed is how to serialize objects stored internally as pointers. Basically, each pickable object needs to define a GetState function, returning a python tuple of the arguments needed to construct the object.
py::tuple GetState(const Pickleable &p) {
return py::make_tuple(p.Field1(),p.Field2(),...);
}
However, if the Pickeable
stores a pointer to some abstract object (say Hilbert), then one obviously cannot do:
py::tuple GetState(const Pickleable &p) {
auto hilbert= p.GetHilbert(); //NO!
return py::make_tuple(p.Field1(),p.Field2(),hilbert);
}
Suggestions are welcome.