Skip to content

Commit 33ed182

Browse files
ElePTmtreinish
andauthored
Deprecate qiskit.result.mitigation (#13351)
* Deprecate qiskit.result.mitigation * Replace runtime suggestion with mthree * Add reno * Update base_readout_mitigator.py to be consistent with other docstrings --------- Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
1 parent 047e078 commit 33ed182

File tree

6 files changed

+189
-87
lines changed

6 files changed

+189
-87
lines changed

qiskit/result/mitigation/base_readout_mitigator.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222

2323
class BaseReadoutMitigator(ABC):
24-
"""Base readout error mitigator class."""
24+
"""This class is DEPRECATED. Base readout error mitigator class."""
2525

2626
@abstractmethod
2727
def quasi_probabilities(

qiskit/result/mitigation/correlated_readout_mitigator.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@
1818
import numpy as np
1919

2020
from qiskit.exceptions import QiskitError
21+
from qiskit.utils.deprecation import deprecate_func
2122
from ..distributions.quasi import QuasiDistribution
2223
from ..counts import Counts
2324
from .base_readout_mitigator import BaseReadoutMitigator
2425
from .utils import counts_probability_vector, z_diagonal, str2diag
2526

2627

2728
class CorrelatedReadoutMitigator(BaseReadoutMitigator):
28-
"""N-qubit readout error mitigator.
29+
"""This class is DEPRECATED. N-qubit readout error mitigator.
2930
3031
Mitigates :meth:`expectation_value` and :meth:`quasi_probabilities`.
3132
The mitigation_matrix should be calibrated using qiskit experiments.
@@ -34,6 +35,13 @@ class CorrelatedReadoutMitigator(BaseReadoutMitigator):
3435
:math:`2^N x 2^N` so the mitigation complexity is :math:`O(4^N)`.
3536
"""
3637

38+
@deprecate_func(
39+
since="1.3",
40+
package_name="Qiskit",
41+
removal_timeline="in Qiskit 2.0",
42+
additional_msg="The `qiskit.result.mitigation` module is deprecated in favor of "
43+
"the https://github.com/Qiskit/qiskit-addon-mthree package.",
44+
)
3745
def __init__(self, assignment_matrix: np.ndarray, qubits: Optional[Iterable[int]] = None):
3846
"""Initialize a CorrelatedReadoutMitigator
3947

qiskit/result/mitigation/local_readout_mitigator.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@
1919
import numpy as np
2020

2121
from qiskit.exceptions import QiskitError
22+
from qiskit.utils.deprecation import deprecate_func
2223
from ..distributions.quasi import QuasiDistribution
2324
from ..counts import Counts
2425
from .base_readout_mitigator import BaseReadoutMitigator
2526
from .utils import counts_probability_vector, z_diagonal, str2diag
2627

2728

2829
class LocalReadoutMitigator(BaseReadoutMitigator):
29-
"""1-qubit tensor product readout error mitigator.
30+
"""This class is DEPRECATED. 1-qubit tensor product readout error mitigator.
3031
3132
Mitigates :meth:`expectation_value` and :meth:`quasi_probabilities`.
3233
The mitigator should either be calibrated using qiskit experiments,
@@ -37,6 +38,13 @@ class LocalReadoutMitigator(BaseReadoutMitigator):
3738
so it is more efficient than the :class:`CorrelatedReadoutMitigator` class.
3839
"""
3940

41+
@deprecate_func(
42+
since="1.3",
43+
package_name="Qiskit",
44+
removal_timeline="in Qiskit 2.0",
45+
additional_msg="The `qiskit.result.mitigation` module is deprecated in favor of "
46+
"the https://github.com/Qiskit/qiskit-addon-mthree package.",
47+
)
4048
def __init__(
4149
self,
4250
assignment_matrices: Optional[List[np.ndarray]] = None,

qiskit/result/mitigation/utils.py

+57
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,20 @@
1919
import numpy as np
2020

2121
from qiskit.exceptions import QiskitError
22+
from qiskit.utils.deprecation import deprecate_func
2223
from ..utils import marginal_counts
2324
from ..counts import Counts
2425

2526
logger = logging.getLogger(__name__)
2627

2728

29+
@deprecate_func(
30+
since="1.3",
31+
package_name="Qiskit",
32+
removal_timeline="in Qiskit 2.0",
33+
additional_msg="The `qiskit.result.mitigation` module is deprecated in favor of "
34+
"the https://github.com/Qiskit/qiskit-addon-mthree package.",
35+
)
2836
def z_diagonal(dim, dtype=float):
2937
r"""Return the diagonal for the operator :math:`Z^\otimes n`"""
3038
parity = np.zeros(dim, dtype=dtype)
@@ -33,6 +41,13 @@ def z_diagonal(dim, dtype=float):
3341
return (-1) ** np.mod(parity, 2)
3442

3543

44+
@deprecate_func(
45+
since="1.3",
46+
package_name="Qiskit",
47+
removal_timeline="in Qiskit 2.0",
48+
additional_msg="The `qiskit.result.mitigation` module is deprecated in favor of "
49+
"the https://github.com/Qiskit/qiskit-addon-mthree package.",
50+
)
3651
def expval_with_stddev(coeffs: np.ndarray, probs: np.ndarray, shots: int) -> Tuple[float, float]:
3752
"""Compute expectation value and standard deviation.
3853
Args:
@@ -60,6 +75,13 @@ def expval_with_stddev(coeffs: np.ndarray, probs: np.ndarray, shots: int) -> Tup
6075
return [expval, calc_stddev]
6176

6277

78+
@deprecate_func(
79+
since="1.3",
80+
package_name="Qiskit",
81+
removal_timeline="in Qiskit 2.0",
82+
additional_msg="The `qiskit.result.mitigation` module is deprecated in favor of "
83+
"the https://github.com/Qiskit/qiskit-addon-mthree package.",
84+
)
6385
def stddev(probs, shots):
6486
"""Calculate stddev dict"""
6587
ret = {}
@@ -69,6 +91,13 @@ def stddev(probs, shots):
6991
return ret
7092

7193

94+
@deprecate_func(
95+
since="1.3",
96+
package_name="Qiskit",
97+
removal_timeline="in Qiskit 2.0",
98+
additional_msg="The `qiskit.result.mitigation` module is deprecated in favor of "
99+
"the https://github.com/Qiskit/qiskit-addon-mthree package.",
100+
)
72101
def str2diag(string):
73102
"""Transform diagonal from a string to a numpy array"""
74103
chars = {
@@ -85,6 +114,13 @@ def str2diag(string):
85114
return ret
86115

87116

117+
@deprecate_func(
118+
since="1.3",
119+
package_name="Qiskit",
120+
removal_timeline="in Qiskit 2.0",
121+
additional_msg="The `qiskit.result.mitigation` module is deprecated in favor of "
122+
"the https://github.com/Qiskit/qiskit-addon-mthree package.",
123+
)
88124
def counts_to_vector(counts: Counts, num_qubits: int) -> Tuple[np.ndarray, int]:
89125
"""Transforms Counts to a probability vector"""
90126
vec = np.zeros(2**num_qubits, dtype=float)
@@ -96,6 +132,13 @@ def counts_to_vector(counts: Counts, num_qubits: int) -> Tuple[np.ndarray, int]:
96132
return vec, shots
97133

98134

135+
@deprecate_func(
136+
since="1.3",
137+
package_name="Qiskit",
138+
removal_timeline="in Qiskit 2.0",
139+
additional_msg="The `qiskit.result.mitigation` module is deprecated in favor of "
140+
"the https://github.com/Qiskit/qiskit-addon-mthree package.",
141+
)
99142
def remap_qubits(
100143
vec: np.ndarray, num_qubits: int, qubits: Optional[List[int]] = None
101144
) -> np.ndarray:
@@ -108,6 +151,13 @@ def remap_qubits(
108151
return vec
109152

110153

154+
@deprecate_func(
155+
since="1.3",
156+
package_name="Qiskit",
157+
removal_timeline="in Qiskit 2.0",
158+
additional_msg="The `qiskit.result.mitigation` module is deprecated in favor of "
159+
"the https://github.com/Qiskit/qiskit-addon-mthree package.",
160+
)
111161
def marganalize_counts(
112162
counts: Counts,
113163
qubit_index: Dict[int, int],
@@ -129,6 +179,13 @@ def marganalize_counts(
129179
return counts
130180

131181

182+
@deprecate_func(
183+
since="1.3",
184+
package_name="Qiskit",
185+
removal_timeline="in Qiskit 2.0",
186+
additional_msg="The `qiskit.result.mitigation` module is deprecated in favor of "
187+
"the https://github.com/Qiskit/qiskit-addon-mthree package.",
188+
)
132189
def counts_probability_vector(
133190
counts: Counts,
134191
qubit_index: Dict[int, int],
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
deprecations_misc:
3+
- |
4+
The ``qiskit.result.mitigation`` module has been deprecated and will be removed in the 2.0 release.
5+
The deprecation includes the ``LocalReadoutMitigator`` and ``CorrelatedReadoutMitigator`` classes
6+
as well as the associated utils.
7+
Their functionality has been superseded by the mthree package, found in https://github.com/Qiskit/qiskit-addon-mthree.

0 commit comments

Comments
 (0)