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 10 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

This also fails:

metadata = {"ev_qubits": np.fromiter([[0, 1], [0, 1, 2]], dtype=object)}

chriseclectic avatar Apr 24 '24 14:04 chriseclectic

We should check if these examples still fail since it's been a while

jyu00 avatar Jul 17 '24 13:07 jyu00

We should check if these examples still fail since it's been a while

Looks like both of the examples given in this issue no longer fail

kt474 avatar Jul 19 '24 16:07 kt474