Skip to content

Commit

Permalink
done
Browse files Browse the repository at this point in the history
  • Loading branch information
SamFerracin committed Aug 12, 2024
1 parent e86fb92 commit 6a787ae
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
22 changes: 14 additions & 8 deletions qiskit_ibm_runtime/utils/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
PrimitiveResult,
)
from qiskit_ibm_runtime.options.zne_options import ExtrapolatorType
from qiskit_ibm_runtime.utils.noise_learner_result import LayerError, PauliLindbladError

_TERRA_VERSION = tuple(
int(x) for x in re.match(r"\d+\.\d+\.\d", _terra_version_string).group(0).split(".")[:3]
Expand Down Expand Up @@ -350,14 +351,15 @@ def object_hook(self, obj: Any) -> Any:
# to deserialize load qpy circuit and return first instruction object in that circuit.
circuit = _decode_and_deserialize(obj_val, load)[0]
return circuit.data[0][0]
if obj_type == "settings" and obj["__module__"].startswith(
"qiskit.quantum_info.operators"
):
return _deserialize_from_settings(
mod_name=obj["__module__"],
class_name=obj["__class__"],
settings=_cast_strings_keys_to_int(obj_val),
)
if obj_type == "settings":
deserialize = obj["__module__"].startswith("qiskit.quantum_info.operators")
deserialize = deserialize or obj["__class__"] in [PauliLindbladError, LayerError]
if deserialize is True:
return _deserialize_from_settings(
mod_name=obj["__module__"],
class_name=obj["__class__"],
settings=_cast_strings_keys_to_int(obj_val),
)
if obj_type == "Result":
return Result.from_dict(obj_val)
if obj_type == "spmatrix":
Expand All @@ -384,6 +386,10 @@ def object_hook(self, obj: Any) -> Any:
if shape is not None and isinstance(shape, list):
shape = tuple(shape)
return DataBin(shape=shape, **obj_val["fields"])
if obj_type == "LayerError":
return LayerError(**obj_val)
if obj_type == "PauliLindbladError":
return PauliLindbladError(**obj_val)
if obj_type == "SamplerPubResult":
return SamplerPubResult(**obj_val)
if obj_type == "PubResult":
Expand Down
22 changes: 21 additions & 1 deletion qiskit_ibm_runtime/utils/noise_learner_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,17 @@
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

"""NoiseLearner result class"""
"""
==================================================================================
NoiseLearner result classes (:mod:`qiskit_ibm_runtime.utils.noise_learner_result`)
==================================================================================
.. autosummary::
:toctree: ../stubs/
PauliLindbladError
LayerError
"""

from __future__ import annotations

Expand Down Expand Up @@ -90,6 +100,11 @@ def num_qubits(self) -> int:
The number of qubits in this :class:`~.PauliLindbladError`.
"""
return self.generators.num_qubits

@property
def settings(self):
"""Return settings."""
return {"generators": self.generators, "rates": self.rates}

def __repr__(self) -> str:
return f"PauliLindbladError(generators={self.generators}, rates={self.rates.tolist()})"
Expand Down Expand Up @@ -170,6 +185,11 @@ def num_qubits(self) -> int:
The number of qubits in this :class:`~.LayerError`.
"""
return len(self.qubits)

@property
def settings(self):
"""Return settings."""
return {"circuit": self.circuit, "qubits": self.qubits, "error": self.error}

def __repr__(self) -> str:
ret = f"circuit={repr(self.circuit)}, qubits={self.qubits}, error={self.error})"
Expand Down

0 comments on commit 6a787ae

Please sign in to comment.