dwavesystems / dwave-system

An API for easily incorporating the D-Wave system as a sampler, either directly or through Leap's cloud-based hybrid samplers
https://docs.ocean.dwavesys.com/
Apache License 2.0
90 stars 64 forks source link

Make DWaveSampler picklable #88

Open pgawron opened 6 years ago

pgawron commented 6 years ago

DWaveSampler is not picklable. It should be in order to integrate for example with sklearn.

In [1]: from dwave.system.samplers import DWaveSampler

In [2]: import pickle

In [3]: annealer = DWaveSampler()

In [4]: pickle.dumps(annealer)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-4-bef1022bace0> in <module>()
----> 1 pickle.dumps(annealer)

TypeError: can't pickle _thread.lock objects
randomir commented 6 years ago

This basically translates to making dwave.cloud.Client picklable (in dwave-cloud-client package). Currently it isn't by default, because thread pools and mutexes would have to be recreated manually.

Can you show here the exact example that requires the DWaveSampler to be picklable? Thanks.