From 6441c91f5cc98aafb44796708b2575d3cc6c51cc Mon Sep 17 00:00:00 2001 From: kevin-tian Date: Thu, 7 Nov 2024 15:23:01 -0500 Subject: [PATCH 1/3] Encode/decode CouplingMap --- qiskit_ibm_runtime/utils/json.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/qiskit_ibm_runtime/utils/json.py b/qiskit_ibm_runtime/utils/json.py index f0b85483c..b1d743a22 100644 --- a/qiskit_ibm_runtime/utils/json.py +++ b/qiskit_ibm_runtime/utils/json.py @@ -51,6 +51,7 @@ QuantumCircuit, QuantumRegister, ) +from qiskit.transpiler import CouplingMap from qiskit.circuit.parametertable import ParameterView from qiskit.result import Result from qiskit.version import __version__ as _terra_version_string @@ -236,6 +237,8 @@ class RuntimeEncoder(json.JSONEncoder): """JSON Encoder used by runtime service.""" def default(self, obj: Any) -> Any: # pylint: disable=arguments-differ + if isinstance(obj, CouplingMap): + return {"__type__": "CouplingMap", "__value__": list(obj)} if isinstance(obj, date): return {"__type__": "datetime", "__value__": obj.isoformat()} if isinstance(obj, complex): @@ -404,6 +407,9 @@ def object_hook(self, obj: Any) -> Any: obj_type = obj["__type__"] obj_val = obj["__value__"] + if obj_type == "CouplingMap": + print("decode coupling map") + return CouplingMap(obj_val) if obj_type == "datetime": return dateutil.parser.parse(obj_val) if obj_type == "complex": From f5d9ed7bb684b8c78f5e31aa2d8899cb02d28108 Mon Sep 17 00:00:00 2001 From: kevin-tian Date: Fri, 8 Nov 2024 11:10:32 -0500 Subject: [PATCH 2/3] Convert coupling map to list --- qiskit_ibm_runtime/utils/json.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/qiskit_ibm_runtime/utils/json.py b/qiskit_ibm_runtime/utils/json.py index b1d743a22..3a5fa9b6e 100644 --- a/qiskit_ibm_runtime/utils/json.py +++ b/qiskit_ibm_runtime/utils/json.py @@ -238,7 +238,7 @@ class RuntimeEncoder(json.JSONEncoder): def default(self, obj: Any) -> Any: # pylint: disable=arguments-differ if isinstance(obj, CouplingMap): - return {"__type__": "CouplingMap", "__value__": list(obj)} + return list(obj) if isinstance(obj, date): return {"__type__": "datetime", "__value__": obj.isoformat()} if isinstance(obj, complex): @@ -407,9 +407,6 @@ def object_hook(self, obj: Any) -> Any: obj_type = obj["__type__"] obj_val = obj["__value__"] - if obj_type == "CouplingMap": - print("decode coupling map") - return CouplingMap(obj_val) if obj_type == "datetime": return dateutil.parser.parse(obj_val) if obj_type == "complex": From 4152a09d6c9da0b329aba9c6262a2f50261c1a4a Mon Sep 17 00:00:00 2001 From: kevin-tian Date: Fri, 8 Nov 2024 14:21:09 -0500 Subject: [PATCH 3/3] Add release note --- release-notes/unreleased/2026.bug.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 release-notes/unreleased/2026.bug.rst diff --git a/release-notes/unreleased/2026.bug.rst b/release-notes/unreleased/2026.bug.rst new file mode 100644 index 000000000..51e758405 --- /dev/null +++ b/release-notes/unreleased/2026.bug.rst @@ -0,0 +1,2 @@ +``CouplingMap`` was added to :class:`~.RuntimeEncoder` so it can now be passed to +the :class:`~.NoiseLearner` program. \ No newline at end of file