Skip to content

Commit

Permalink
serialize circuit metadata correctly (Qiskit#946)
Browse files Browse the repository at this point in the history
  • Loading branch information
kt474 committed Jul 13, 2023
1 parent 99b8e62 commit af3a9ef
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion qiskit_ibm_runtime/utils/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,9 @@ def default(self, obj: Any) -> Any: # pylint: disable=arguments-differ
if isinstance(obj, QuantumCircuit):
value = _serialize_and_encode(
data=obj,
serializer=lambda buff, data: dump(data, buff), # type: ignore[no-untyped-call]
serializer=lambda buff, data: dump(
data, buff, RuntimeEncoder
), # type: ignore[no-untyped-call]
)
return {"__type__": "QuantumCircuit", "__value__": value}
if isinstance(obj, Parameter):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
fixes:
- |
Fixed an issue where circuit metadata was not being serialized correctly
resulting in a type error.
9 changes: 9 additions & 0 deletions test/unit/test_data_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,3 +302,12 @@ def test_result_decoder(self):
)
result = job.result(decoder=decoder)
self.assertIsInstance(result["serializable_class"], SerializableClass)

def test_circuit_metadata(self):
"""Test serializing circuit metadata."""

circ = QuantumCircuit(1)
circ.metadata = {"test": np.arange(0, 10)}
payload = {"circuits": [circ]}

self.assertTrue(json.dumps(payload, cls=RuntimeEncoder))

0 comments on commit af3a9ef

Please sign in to comment.