Time limit type checking for `numpy.int64`
mcfarljm opened this issue · 2 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
:
dwave-system/dwave/system/samplers/leap_hybrid_sampler.py
Lines 231 to 232 in 7bf16fc
Related to dwavesystems/dwave-cloud-client#512.
Fixed in dwavesystems/dwave-cloud-client#536, released in cloud-client 0.10.3, shipped with Ocean 6.0.0.