dwave-system icon indicating copy to clipboard operation
dwave-system copied to clipboard

Time limit type checking for `numpy.int64`

Open mcfarljm opened this issue 3 years ago • 1 comments

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

mcfarljm avatar Oct 26 '22 16:10 mcfarljm

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

randomir avatar Oct 26 '22 17:10 randomir

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

randomir avatar Oct 31 '22 22:10 randomir