Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Support shots as np.int64 #744

Merged
merged 7 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 1 addition & 2 deletions qiskit_ibm_provider/utils/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,7 @@ def default(self, obj: Any) -> Any: # pylint: disable=arguments-differ
value = _serialize_and_encode(obj, np.save, allow_pickle=False)
return {"__type__": "ndarray", "__value__": value}
if isinstance(obj, np.number):
# Maybe we should encode the numpy data type here for better accuracy.
return {"__type__": type(obj.item()).__name__, "__value__": obj.item()}
return obj.item()
if isinstance(obj, set):
kt474 marked this conversation as resolved.
Show resolved Hide resolved
return {"__type__": "set", "__value__": list(obj)}
if isinstance(obj, Result):
Expand Down
8 changes: 8 additions & 0 deletions test/integration/test_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from typing import Set, Any, Dict, Optional
from unittest import SkipTest, skip
import numpy as np

import dateutil.parser
from qiskit import transpile, schedule, QuantumCircuit
Expand Down Expand Up @@ -197,6 +198,13 @@ def test_convert_complex(self):
self.assertEqual(val[0], 0.2)
self.assertEqual(val[1], 0.1)

def test_np_number(self):
"""Test using np.number"""
shots = 100
result = self.sim_backend.run(self.bell, shots=np.int64(shots)).result()
self.assertEqual(result.results[0].shots, shots)
print(result.results[0])


def _find_potential_encoded(data: Any, c_key: str, tally: set) -> None:
"""Find data that may be in JSON serialized format.
Expand Down
Loading