From 24256f88874196d24c9ca9fc092319b4f8d8b957 Mon Sep 17 00:00:00 2001 From: kevin-tian Date: Wed, 15 May 2024 14:44:20 -0400 Subject: [PATCH 1/3] Fix 0-d zne options encoding bug --- qiskit_ibm_runtime/utils/json.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/qiskit_ibm_runtime/utils/json.py b/qiskit_ibm_runtime/utils/json.py index 7bee75f61..3efa15574 100644 --- a/qiskit_ibm_runtime/utils/json.py +++ b/qiskit_ibm_runtime/utils/json.py @@ -214,6 +214,8 @@ def default(self, obj: Any) -> Any: # pylint: disable=arguments-differ if isinstance(obj, np.ndarray): if obj.dtype == object: return {"__type__": "ndarray", "__value__": obj.tolist()} + elif obj.size == 0: + return obj.tolist() value = _serialize_and_encode(obj, np.save, allow_pickle=False) return {"__type__": "ndarray", "__value__": value} if isinstance(obj, np.int64): From 6797f7c992841a4031f92184f4f55411be4480c9 Mon Sep 17 00:00:00 2001 From: kevin-tian Date: Thu, 16 May 2024 14:11:30 -0400 Subject: [PATCH 2/3] Add check to decoder --- qiskit_ibm_runtime/utils/json.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/qiskit_ibm_runtime/utils/json.py b/qiskit_ibm_runtime/utils/json.py index 3efa15574..6918d2a11 100644 --- a/qiskit_ibm_runtime/utils/json.py +++ b/qiskit_ibm_runtime/utils/json.py @@ -25,7 +25,7 @@ import warnings import zlib from datetime import date -from typing import Any, Callable, Dict, List, Union, Tuple +from typing import Any, Callable, Dict, List, Union, Tuple, get_args import dateutil.parser import numpy as np @@ -74,6 +74,7 @@ PubResult, PrimitiveResult, ) +from qiskit_ibm_runtime.options.zne_options import ExtrapolatorType _TERRA_VERSION = tuple( int(x) for x in re.match(r"\d+\.\d+\.\d", _terra_version_string).group(0).split(".")[:3] @@ -214,8 +215,6 @@ def default(self, obj: Any) -> Any: # pylint: disable=arguments-differ if isinstance(obj, np.ndarray): if obj.dtype == object: return {"__type__": "ndarray", "__value__": obj.tolist()} - elif obj.size == 0: - return obj.tolist() value = _serialize_and_encode(obj, np.save, allow_pickle=False) return {"__type__": "ndarray", "__value__": value} if isinstance(obj, np.int64): @@ -349,6 +348,8 @@ def object_hook(self, obj: Any) -> Any: if obj_type == "complex": return obj_val[0] + 1j * obj_val[1] if obj_type == "ndarray": + if obj_val in get_args(ExtrapolatorType): + return obj_val if isinstance(obj_val, list): return np.array(obj_val) return _decode_and_deserialize(obj_val, np.load) From 385ad9315f9a027f7e7d2ec3b088fa941c201c30 Mon Sep 17 00:00:00 2001 From: kevin-tian Date: Mon, 20 May 2024 14:09:18 -0400 Subject: [PATCH 3/3] Add release note --- release-notes/unreleased/1682.bug.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 release-notes/unreleased/1682.bug.rst diff --git a/release-notes/unreleased/1682.bug.rst b/release-notes/unreleased/1682.bug.rst new file mode 100644 index 000000000..ac2414d97 --- /dev/null +++ b/release-notes/unreleased/1682.bug.rst @@ -0,0 +1 @@ +Fixed a serialization issue where decoding job metadata resulted in an error. \ No newline at end of file