qiskit-ibm-runtime icon indicating copy to clipboard operation
qiskit-ibm-runtime copied to clipboard

Add support for object array encoding/decoding

Open ihincks opened this issue 4 months ago • 1 comments

What is the expected feature or enhancement?

NumPy object arrays require special care when encoding/decoding. For example, the following fails:

import json
import numpy as np
from qiskit_ibm_runtime import RuntimeEncoder, RuntimeDecoder

metadata = {"ev_qubits": np.array([np.arange(2), np.arange(3)], dtype=object)}

js = json.dumps(metadata, cls=RuntimeEncoder)
json.loads(js, cls=RuntimeDecoder)

It successfully encodes, but then fails to decode because it can't figured out the raggedness.

cc @chriseclectic

Acceptance criteria

The above snippet succeeds, where the input to np.array can also include other json-serializable Python builtins.

ihincks avatar Apr 24 '24 13:04 ihincks