Skip to content

Commit

Permalink
settings
Browse files Browse the repository at this point in the history
  • Loading branch information
SamFerracin committed Aug 12, 2024
1 parent d6c3f84 commit ef37560
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 14 deletions.
23 changes: 9 additions & 14 deletions qiskit_ibm_runtime/utils/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,6 @@ def default(self, obj: Any) -> Any: # pylint: disable=arguments-differ
"fields": dict(obj.items()),
}
return {"__type__": "DataBin", "__value__": out_val}
if isinstance(obj, LayerError):
out_val = {"circuit": obj.circuit, "qubits": obj.qubits, "error": obj.error}
return {"__type__": "LayerError", "__value__": out_val}
if isinstance(obj, PauliLindbladError):
out_val = {"generators": obj.generators, "rates": obj.rates}
return {"__type__": "PauliLindbladError", "__value__": out_val}
if isinstance(obj, EstimatorPub):
return (
obj.circuit,
Expand Down Expand Up @@ -357,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 Down
38 changes: 38 additions & 0 deletions qiskit_ibm_runtime/utils/noise_learner_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
from qiskit.circuit import QuantumCircuit
from qiskit.quantum_info import PauliList

from ..utils.deprecation import issue_deprecation_msg


class PauliLindbladError:
r"""A Pauli error channel generated by a Pauli Lindblad dissipators.
Expand Down Expand Up @@ -88,6 +90,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 @@ -136,12 +143,43 @@ def error(self) -> PauliLindbladError:
"""
return self._error

@property
def generators(self) -> PauliList:
r"""
(DEPRECATED) The Pauli Lindblad generators of the error channel in this :class:`.~LayerError`.
"""
issue_deprecation_msg(
"The ``generators`` property is deprecated",
"0.27.0",
"Instead, you can access the generators through the ``error`` property.",
1,
)
return self.error.generators

@property
def rates(self) -> NDArray[np.float64]:
r"""
(DEPRECATED) The Lindblad generator rates of the error channel in this :class:`.~LayerError`.
"""
issue_deprecation_msg(
"The ``rates`` property is deprecated",
"0.27.0",
"Instead, you can access the rates through the ``error`` property.",
1,
)
return self.error.rates

@property
def num_qubits(self) -> int:
r"""
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 ef37560

Please sign in to comment.