dwave-cloud-client icon indicating copy to clipboard operation
dwave-cloud-client copied to clipboard

`DWaveSampler().sample` can't parse numpy integers for `num_reads`

Open kevinchern opened this issue 3 years ago • 2 comments

Description DWaveSampler().sample(bqm, num_reads=np.int8(123)) gives an error. Why np.int8(123)? Occurs in scenarios such as np.linspace(2, 6, 10, dtype=np.int8)[0]

To Reproduce this will fail with the following error: TypeError: Object of type int8 is not JSON serializable

    from dwave.system import DWaveSampler
    import numpy as np
    sampler_dw = DWaveSampler(name='BAY8_P16_X_INTERNAL')
    sampler_dw.sample_ising(h={30: 0}, J={}, num_reads=np.int8(1))

this will work:

    from neal import SimulatedAnnealingSampler
    sampler_sa = SimulatedAnnealingSampler()
    sampler_sa.sample_ising(h={30: 0}, J={}, num_reads=np.int8(1))

Environment:

  • OS: Ubuntu 18.04.6 LTS
  • Python version: 3.9.7
  • Ocean SDK: 4.3.0
  • dimod: 0.10.10
  • numpy: 1.22.0
  • neal: 0.5.9

kevinchern avatar Feb 03 '22 16:02 kevinchern

@randomir IMO we should migrate this issue to the cloud-client. Unless you think the DWaveSampler should be handling this case?

arcondello avatar Feb 03 '22 16:02 arcondello

@arcondello, I agree. Sampling params are just passed down to the QPU solver, and we can handle conversion there.

randomir avatar Feb 15 '22 14:02 randomir