Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate qiskit.result.mitigation #13351

Merged
merged 5 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion qiskit/result/mitigation/base_readout_mitigator.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@


class BaseReadoutMitigator(ABC):
"""Base readout error mitigator class."""
"""This class is DEPRECATED. Base readout error mitigator class."""

@abstractmethod
def quasi_probabilities(
Expand Down
10 changes: 9 additions & 1 deletion qiskit/result/mitigation/correlated_readout_mitigator.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
import numpy as np

from qiskit.exceptions import QiskitError
from qiskit.utils.deprecation import deprecate_func
from ..distributions.quasi import QuasiDistribution
from ..counts import Counts
from .base_readout_mitigator import BaseReadoutMitigator
from .utils import counts_probability_vector, z_diagonal, str2diag


class CorrelatedReadoutMitigator(BaseReadoutMitigator):
"""N-qubit readout error mitigator.
"""This class is DEPRECATED. N-qubit readout error mitigator.

Mitigates :meth:`expectation_value` and :meth:`quasi_probabilities`.
The mitigation_matrix should be calibrated using qiskit experiments.
Expand All @@ -34,6 +35,13 @@ class CorrelatedReadoutMitigator(BaseReadoutMitigator):
:math:`2^N x 2^N` so the mitigation complexity is :math:`O(4^N)`.
"""

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

Expand Down
10 changes: 9 additions & 1 deletion qiskit/result/mitigation/local_readout_mitigator.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
import numpy as np

from qiskit.exceptions import QiskitError
from qiskit.utils.deprecation import deprecate_func
from ..distributions.quasi import QuasiDistribution
from ..counts import Counts
from .base_readout_mitigator import BaseReadoutMitigator
from .utils import counts_probability_vector, z_diagonal, str2diag


class LocalReadoutMitigator(BaseReadoutMitigator):
"""1-qubit tensor product readout error mitigator.
"""This class is DEPRECATED. 1-qubit tensor product readout error mitigator.

Mitigates :meth:`expectation_value` and :meth:`quasi_probabilities`.
The mitigator should either be calibrated using qiskit experiments,
Expand All @@ -37,6 +38,13 @@ class LocalReadoutMitigator(BaseReadoutMitigator):
so it is more efficient than the :class:`CorrelatedReadoutMitigator` class.
"""

@deprecate_func(
since="1.3",
package_name="Qiskit",
removal_timeline="in Qiskit 2.0",
additional_msg="The `qiskit.result.mitigation` module is deprecated in favor of "
"the https://github.com/Qiskit/qiskit-addon-mthree package.",
)
def __init__(
self,
assignment_matrices: Optional[List[np.ndarray]] = None,
Expand Down
57 changes: 57 additions & 0 deletions qiskit/result/mitigation/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,20 @@
import numpy as np

from qiskit.exceptions import QiskitError
from qiskit.utils.deprecation import deprecate_func
from ..utils import marginal_counts
from ..counts import Counts

logger = logging.getLogger(__name__)


@deprecate_func(
since="1.3",
package_name="Qiskit",
removal_timeline="in Qiskit 2.0",
additional_msg="The `qiskit.result.mitigation` module is deprecated in favor of "
"the https://github.com/Qiskit/qiskit-addon-mthree package.",
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think only the 3 classes above are actually public so these technically could just be removed. But it's good to deprecate them anyway and remove it all at once.

def z_diagonal(dim, dtype=float):
r"""Return the diagonal for the operator :math:`Z^\otimes n`"""
parity = np.zeros(dim, dtype=dtype)
Expand All @@ -33,6 +41,13 @@ def z_diagonal(dim, dtype=float):
return (-1) ** np.mod(parity, 2)


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


@deprecate_func(
since="1.3",
package_name="Qiskit",
removal_timeline="in Qiskit 2.0",
additional_msg="The `qiskit.result.mitigation` module is deprecated in favor of "
"the https://github.com/Qiskit/qiskit-addon-mthree package.",
)
def stddev(probs, shots):
"""Calculate stddev dict"""
ret = {}
Expand All @@ -69,6 +91,13 @@ def stddev(probs, shots):
return ret


@deprecate_func(
since="1.3",
package_name="Qiskit",
removal_timeline="in Qiskit 2.0",
additional_msg="The `qiskit.result.mitigation` module is deprecated in favor of "
"the https://github.com/Qiskit/qiskit-addon-mthree package.",
)
def str2diag(string):
"""Transform diagonal from a string to a numpy array"""
chars = {
Expand All @@ -85,6 +114,13 @@ def str2diag(string):
return ret


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


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


@deprecate_func(
since="1.3",
package_name="Qiskit",
removal_timeline="in Qiskit 2.0",
additional_msg="The `qiskit.result.mitigation` module is deprecated in favor of "
"the https://github.com/Qiskit/qiskit-addon-mthree package.",
)
def marganalize_counts(
counts: Counts,
qubit_index: Dict[int, int],
Expand All @@ -129,6 +179,13 @@ def marganalize_counts(
return counts


@deprecate_func(
since="1.3",
package_name="Qiskit",
removal_timeline="in Qiskit 2.0",
additional_msg="The `qiskit.result.mitigation` module is deprecated in favor of "
"the https://github.com/Qiskit/qiskit-addon-mthree package.",
)
def counts_probability_vector(
counts: Counts,
qubit_index: Dict[int, int],
Expand Down
7 changes: 7 additions & 0 deletions releasenotes/notes/deprecate-mitigation-f5f6ef3233b3d726.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
deprecations_misc:
- |
The ``qiskit.result.mitigation`` module has been deprecated and will be removed in the 2.0 release.
The deprecation includes the ``LocalReadoutMitigator`` and ``CorrelatedReadoutMitigator`` classes
Comment on lines +4 to +5
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You didn't want to use class refs for these? They seem to be in the docs: https://docs.quantum.ibm.com/api/qiskit/qiskit.result.LocalReadoutMitigator

Copy link
Contributor Author

@ElePT ElePT Oct 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't remember if we would use refs for removals, I will keep it in mind and suggest the changes in the reno copy-editing phase. This way we can get the merge queue going with this PR :)

as well as the associated utils.
Their functionality has been superseded by the mthree package, found in https://github.com/Qiskit/qiskit-addon-mthree.
Loading