forked from qiskit-community/qiskit-experiments
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adopt qiskit.result.mitigation into qiskit_experiments.data_processing
The readout error mitigator classes `LocalReadoutMitigator` and `CorrelatedReadoutMitigator` have been copied into `qiskit_experiments.data_processing.mitigation` from `qiskit.result.mitigation` in order to prepare for the deprecation of these classes from Qiskit. The experiments that previously used the Qiskit versions of these mitigator classes now use the Experiments versions. The manual has also been updated to use the new class locations.
- Loading branch information
Showing
14 changed files
with
1,396 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# This code is part of Qiskit. | ||
# | ||
# (C) Copyright IBM 2017, 2021. | ||
# | ||
# This code is licensed under the Apache License, Version 2.0. You may | ||
# obtain a copy of this license in the LICENSE.txt file in the root directory | ||
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. | ||
# | ||
# Any modifications or derivative works of this code must retain this | ||
# copyright notice, and modified files need to carry a notice indicating | ||
# that they have been altered from the originals. | ||
|
||
"""Readout error mitigation.""" | ||
from .base_readout_mitigator import BaseReadoutMitigator | ||
from .correlated_readout_mitigator import CorrelatedReadoutMitigator | ||
from .local_readout_mitigator import LocalReadoutMitigator | ||
from .utils import ( | ||
counts_probability_vector, | ||
expval_with_stddev, | ||
stddev, | ||
str2diag, | ||
) |
81 changes: 81 additions & 0 deletions
81
qiskit_experiments/data_processing/mitigation/base_readout_mitigator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# This code is part of Qiskit. | ||
# | ||
# (C) Copyright IBM 2021 | ||
# | ||
# This code is licensed under the Apache License, Version 2.0. You may | ||
# obtain a copy of this license in the LICENSE.txt file in the root directory | ||
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. | ||
# | ||
# Any modifications or derivative works of this code must retain this | ||
# copyright notice, and modified files need to carry a notice indicating | ||
# that they have been altered from the originals. | ||
""" | ||
Base class for readout error mitigation. | ||
""" | ||
|
||
from abc import ABC, abstractmethod | ||
from typing import Optional, List, Iterable, Tuple, Union, Callable | ||
|
||
import numpy as np | ||
|
||
from qiskit.result.counts import Counts | ||
from qiskit.result.distributions.quasi import QuasiDistribution | ||
|
||
|
||
class BaseReadoutMitigator(ABC): | ||
"""Base readout error mitigator class.""" | ||
|
||
@abstractmethod | ||
def quasi_probabilities( | ||
self, | ||
data: Counts, | ||
qubits: Iterable[int] = None, | ||
clbits: Optional[List[int]] = None, | ||
shots: Optional[int] = None, | ||
) -> QuasiDistribution: | ||
"""Convert counts to a dictionary of quasi-probabilities | ||
Args: | ||
data: Counts to be mitigated. | ||
qubits: the physical qubits measured to obtain the counts clbits. | ||
If None these are assumed to be qubits [0, ..., N-1] | ||
for N-bit counts. | ||
clbits: Optional, marginalize counts to just these bits. | ||
shots: Optional, the total number of shots, if None shots will | ||
be calculated as the sum of all counts. | ||
Returns: | ||
QuasiDistribution: A dictionary containing pairs of [output, mean] where "output" | ||
is the key in the dictionaries, | ||
which is the length-N bitstring of a measured standard basis state, | ||
and "mean" is the mean of non-zero quasi-probability estimates. | ||
""" | ||
|
||
@abstractmethod | ||
def expectation_value( | ||
self, | ||
data: Counts, | ||
diagonal: Union[Callable, dict, str, np.ndarray], | ||
qubits: Iterable[int] = None, | ||
clbits: Optional[List[int]] = None, | ||
shots: Optional[int] = None, | ||
) -> Tuple[float, float]: | ||
"""Calculate the expectation value of a diagonal Hermitian operator. | ||
Args: | ||
data: Counts object to be mitigated. | ||
diagonal: the diagonal operator. This may either be specified | ||
as a string containing I,Z,0,1 characters, or as a | ||
real valued 1D array_like object supplying the full diagonal, | ||
or as a dictionary, or as Callable. | ||
qubits: the physical qubits measured to obtain the counts clbits. | ||
If None these are assumed to be qubits [0, ..., N-1] | ||
for N-bit counts. | ||
clbits: Optional, marginalize counts to just these bits. | ||
shots: Optional, the total number of shots, if None shots will | ||
be calculated as the sum of all counts. | ||
Returns: | ||
The mean and an upper bound of the standard deviation of operator | ||
expectation value calculated from the current counts. | ||
""" |
Oops, something went wrong.