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
87 stars 61 forks source link

Time limit type checking for `numpy.int64` #475

Closed mcfarljm closed 1 year ago

mcfarljm commented 1 year ago

Description If the time limit is passed as numpy.int64, the cloud client fails with an error message that is difficult to track:

...
  File "/home/jmcfarland/venv/ocean/lib/python3.9/site-packages/dwave/cloud/solver.py", line 424, in _encode_problem_for_submission
    body_data = json.dumps(body)
  File "/usr/lib/python3.9/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "/usr/lib/python3.9/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.9/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib/python3.9/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type int64 is not JSON serializable

To Reproduce Call the HSS solver with something like time_limit=np.int64(10). In a real situation, this might happen inadvertently when, for example, using pandas to read a list of time limits from a CSV file.

Expected behavior I would expect either a more direct error message about the type error with the time limit value (which appears to be the intent of the type check in the source code), or a conversion to int: https://github.com/dwavesystems/dwave-system/blob/7bf16fcd67add4112f5afeb08c75dcc694a0cca0/dwave/system/samplers/leap_hybrid_sampler.py#L231-L232

randomir commented 1 year ago

Related to https://github.com/dwavesystems/dwave-cloud-client/issues/512.

randomir commented 1 year ago

Fixed in https://github.com/dwavesystems/dwave-cloud-client/pull/536, released in cloud-client 0.10.3, shipped with Ocean 6.0.0.