From 320b9bfc4c1fd5c5f11cef61af6efcaa3454bb80 Mon Sep 17 00:00:00 2001 From: SamFerracin Date: Mon, 12 Aug 2024 14:28:05 -0400 Subject: [PATCH] decoding should work now --- qiskit_ibm_runtime/utils/json.py | 6 +++--- qiskit_ibm_runtime/utils/noise_learner_result.py | 4 ++-- qiskit_ibm_runtime/utils/noise_learner_result_decoder.py | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/qiskit_ibm_runtime/utils/json.py b/qiskit_ibm_runtime/utils/json.py index 49653f2e0..2ca1940a2 100644 --- a/qiskit_ibm_runtime/utils/json.py +++ b/qiskit_ibm_runtime/utils/json.py @@ -352,9 +352,9 @@ def object_hook(self, obj: Any) -> Any: circuit = _decode_and_deserialize(obj_val, load)[0] return circuit.data[0][0] if obj_type == "settings": - deserialize = obj["__module__"].startswith("qiskit.quantum_info.operators") - deserialize = deserialize or obj["__class__"] in [PauliLindbladError, LayerError] - if deserialize is True: + if obj["__module__"].startswith("qiskit.quantum_info.operators") or obj[ + "__module__" + ].startswith("qiskit_ibm_runtime.utils.noise_learner_result"): return _deserialize_from_settings( mod_name=obj["__module__"], class_name=obj["__class__"], diff --git a/qiskit_ibm_runtime/utils/noise_learner_result.py b/qiskit_ibm_runtime/utils/noise_learner_result.py index 3b2a7150f..81a41a72c 100644 --- a/qiskit_ibm_runtime/utils/noise_learner_result.py +++ b/qiskit_ibm_runtime/utils/noise_learner_result.py @@ -90,7 +90,7 @@ def num_qubits(self) -> int: The number of qubits in this :class:`~.PauliLindbladError`. """ return self.generators.num_qubits - + @property def settings(self): """Return settings.""" @@ -175,7 +175,7 @@ def num_qubits(self) -> int: The number of qubits in this :class:`~.LayerError`. """ return len(self.qubits) - + @property def settings(self): """Return settings.""" diff --git a/qiskit_ibm_runtime/utils/noise_learner_result_decoder.py b/qiskit_ibm_runtime/utils/noise_learner_result_decoder.py index 9aba80d79..4a4c13f98 100644 --- a/qiskit_ibm_runtime/utils/noise_learner_result_decoder.py +++ b/qiskit_ibm_runtime/utils/noise_learner_result_decoder.py @@ -30,12 +30,12 @@ def decode( # type: ignore # pylint: disable=arguments-differ data = [] for layer in decoded["data"]: - try: + if isinstance(layer, LayerError): + data.append(layer) + else: # supports the legacy result format error = PauliLindbladError(layer[1]["generators"], layer[1]["rates"]) datum = LayerError(layer[0]["circuit"], layer[0]["qubits"], error) data.append(datum) - except TypeError: - data.append(layer) - + return NoiseLearnerResult(data=data, metadata=decoded["metadata"])