sQUlearn / squlearn

scikit-learn interface for quantum algorithms
https://squlearn.github.io
Apache License 2.0
53 stars 18 forks source link

Serialization of models #275

Open vondrejc opened 3 weeks ago

vondrejc commented 3 weeks ago

Is your feature request related to a problem? Please describe. At the moment, there is no simple way for saving/loading of models. I have tried pickle, joblib, cloudpickle and none of them works.

Describe the solution you'd like Enable the possibility of saving/loading of models with pickle or cloudpickle.

Describe alternatives you've considered Alternatively, one could implement get_weights(), set_weights(weights: numpy.ndarray) for storing only the weights in the same way as in keras/tensorflow https://keras.io/guides/serialization_and_saving/

Additional context Another solution is welcome!

vondrejc commented 4 days ago

It is possible to store some models with dill https://pypi.org/project/dill/. There is a problem to load models with SLSQP optimizer because of package symengine (since this package is only optional in Windows, it is possible to load models there). Still, it would be nice to have a class method, which allows an official way how to store it without trying several packages.

David-Kreplin commented 15 hours ago

Yes, indeed, we probably have to find our own way of storing the models and not solely rely on Dill. I think the biggest issue is the Executor class or the Backend class used within. We probably can't avoid reinitializing the Executor.