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

Warnings unserializable #509

Open randomir opened 11 months ago

randomir commented 11 months ago

Description Storing sampling warnings (in SampleSet.info) renders sampleset JSON unserializable.

To Reproduce

>>> import json
>>> import dimod
>>> from dwave.system import EmbeddingComposite, DWaveSampler
>>> from dwave.system.warnings import WarningAction
>>> 
>>> bqm = dimod.BQM.from_ising({},{'ab': 1, 'bc': 1, 'ca': 1})
>>> sampler = EmbeddingComposite(DWaveSampler())
>>> 
>>> sampleset = sampler.sample(bqm, return_embedding=True, warnings=WarningAction.SAVE)
>>> 
>>> json.dumps(sampleset.to_serializable())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
...
TypeError: Object of type type is not JSON serializable

Expected behavior json.dumps(sampleset.to_serializable()) should work.