Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions qiskit_ibm_runtime/utils/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ def default(self, obj: Any) -> Any: # pylint: disable=arguments-differ
return {"__type__": "ndarray", "__value__": obj.tolist()}
value = _serialize_and_encode(obj, np.save, allow_pickle=False)
return {"__type__": "ndarray", "__value__": value}
if isinstance(obj, np.int64):
return obj.item()
if isinstance(obj, set):
return {"__type__": "set", "__value__": list(obj)}
if isinstance(obj, Result):
Expand Down
5 changes: 5 additions & 0 deletions releasenotes/notes/fix_np_int64-864b605a88f57419.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
fixes:
- |
Fixed a bug where ``shots`` passed in as a numpy type were not being
serialized correctly.
7 changes: 7 additions & 0 deletions test/unit/test_data_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,13 @@ def test_encoder_instruction(self):
decoded = json.loads(encoded, cls=RuntimeDecoder)
self.assertEqual(decoded, obj)

def test_encoder_np_number(self):
"""Test encoding and decoding instructions"""
encoded = json.dumps(np.int64(100), cls=RuntimeEncoder)
self.assertIsInstance(encoded, str)
decoded = json.loads(encoded, cls=RuntimeDecoder)
self.assertEqual(decoded, 100)

def test_encoder_callable(self):
"""Test encoding a callable."""
with warnings.catch_warnings(record=True) as warn_cm:
Expand Down