Efficient Quantum Readout Error Mitigation for Sparse Measurement Outcomes of Near-term Quantum Devices
libs_qrem
is a Python package which executes efficient quantum readout error mitigation (QREM) written in C++/Cython.
This package mitigates the readout errors in the 65-qubit measurement result of the GHZ state from ibmq_brooklyn in a few seconds.
- Time Complexity:
$O(ns^2)$ - Space Complexity:
$O(s^2)$ ( Can be reduced into$O(ns)$ )
Quick access to the usage: demonstration.ipynb
Raw histogram | Mitigated histogram |
---|---|
![]() |
![]() |
- C++/Eigen: This can be done by downloading the Eigen package and allocating it as
eigen
folder underlibs_qrem
. - Cython
pip install git+https://github.com/BOBO1997/libs_qrem
c.f.) Reinstall via pip
pip install --upgrade --force-reinstall git+https://github.com/BOBO1997/libs_qrem
git clone https://github.com/BOBO1997/libs_qrem.git
cd libs_qrem
python setup.py install --record install_record.txt
pip uninstall libs_qrem
- build
python setup.py build_ext --inplace
- clean
rm -rf dist/ build/ libs_qrem.egg-info/ libs_qrem.cpython-38-darwin.so libs_qrem/*.cpp
There are four different classes that support four different QREM methods, respectively.
DeltaFilter
: Apply inverse matrix for the vector elements in subspace + correct the vector by adding a correction vector "delta" which is approximated through the solution of Lagrange multiplier + apply SGS algorithm.LeastNormFilter
: Apply inverse matrix for the vector elements in subspace + apply the solution of the least norm problem to compute the closest vector that meets all elements are summed up to 1 + apply the SGS algorithm.MooneyEtalFilter
: Method by Mooney, White, Hill, Hollenberg, 2021 + apply SGS algorithm.NationEtalFilter
: Method by Nation, Kang, Sundaresan, Gambetta, 2021 + apply SGS algorithm.IgnisFilter
: Apply full inverse matrix under tensor product noise model (such asTensoredFilter
in qiskit.ignis) + apply SGS algorithm.
where SGS algorithm is the algorithm proposed by Smolin, Gambetta, Smith, 2012.
Each class inherits the base class BaseFilter
, which has the following methods in order to get access to the internal information.
- Matrices
reduced_A()
: returns alist
oflist
withdouble
elementsnormalized_reduced_A()
: returns alist
oflist
withdouble
elementsreduced_inv_A()
: returns alist
oflist
withdouble
elementsexact_one_norm_of_inv_reduced_A()
: returns adouble
valueiterative_one_norm_of_inv_reduced_A()
: returns adouble
valueexact_one_norm_of_reduced_inv_A()
: returns adouble
value
- Mitigated vectors and vectors under the procedure
mitigated_hist()
: returns adict
withstr
keys anddouble
valuesx_s()
: returns alist
withdouble
elementsx_hat()
: returns alist
withdouble
elementsx_tilde()
: returns alist
withdouble
elements
- Sum of vectors
sum_of_x()
: returns adouble
valuesum_of_x_hat()
: returns adouble
valuesum_of_x_tilde()
: returns adouble
value
- Other information
indices_to_keys_vector()
: returns alist
withstr
elementstimes()
: returns adict
withstr
keys anddouble
valuesexpval()
: returns adouble
valuemitigation_stddev(norm_type = "exact")
: returns adouble
value
Each QREM filter in libs_qrem
takes the number of qubits and calibration matrices in the following way.
from libs_qrem import LeastNormFilter
meas_filter = LeastNormFilter(n, meas_fitter.cal_matrices)
Passing a dictionary typed noisy probability distribution or noisy histogram to LeastNormFilter.apply()
method, it returns a mitigated probability distribution.
mitigated_hist = meas_filter.apply(noisy_hist)
This apply
function can also take as input qiskit.result.Result
, qiskit.result.Counts
, and their lists.
A simple example code can be found in demonstration.ipynb
from qiskit.circuit import QuantumRegister
# prepare calibration circuit (same as qiskit tutorial)
num_qubits = 4
qr = QuantumRegister(num_qubits)
mit_pattern = [[0], [1], [2], [3]] ### This indicates which sets of qubits to mitigate taking the correlated error into account.
### mit_pattern = [[0], [1], [2, 3]] ### correlated error is currently not supported (bug found).
# create quantum circuits for calibrating readout errors
from libs_qrem import tensored_meas_cal
qcs_qrem, _ = tensored_meas_cal(mit_pattern=mit_pattern, qr=qr, circlabel='mcal')
# run calibration circuit (same as qiskit tutorial) using the simulated fake backend
results_qrem = simulator_noisy.run(circuits=qcs_qrem,
shots=5000).result()
from libs_qrem import TensoredMeasFitter
meas_fitter = TensoredMeasFitter(results_qrem, mit_pattern=mit_pattern)
# Create mitigator instance (corresponds to meas_fitter.filter in the tutorial code.)
# this is very similar to the usage of qiskit.ignis.mitigation modules
# meas_filter = meas_fitter.filter
from libs_qrem import LeastNormFilter
meas_filter = LeastNormFilter(num_qubits, meas_fitter.cal_matrices)
# apply mitigation
# Let `noisy_hist` be a dict variable representing a noisy histogram obtained from `.get_counts()` method in `qiskit.result.Result` instance.
# e.g. `noisy_hist = {"000": 50, "101": 20, "111": 30}`
# Then you can mitigate it as follows.
mitigated_hist = meas_filter.apply(noisy_hist)
This package is based on the paper: Efficient Quantum Readout Error Mitigation for Sparse Measurement Outcomes of Near-term Quantum Devices by Bo Yang, Rudy Raymond, and Shumpei Uno.
Demonstrations in the paper are also stored here.
- Efficient Readout Error Mitigation Heuristic for Measurement Outcomes with Few States (Bo Yang, Rudy Raymond and Shumpei Uno) AQIS2021, Poster Session B22
Please cite our paper when you use this package.
@article{PhysRevA.106.012423,
title = {Efficient quantum readout-error mitigation for sparse measurement outcomes of near-term quantum devices},
author = {Yang, Bo and Raymond, Rudy and Uno, Shumpei},
journal = {Phys. Rev. A},
volume = {106},
issue = {1},
pages = {012423},
numpages = {14},
year = {2022},
month = {Jul},
publisher = {American Physical Society},
doi = {10.1103/PhysRevA.106.012423},
url = {https://link.aps.org/doi/10.1103/PhysRevA.106.012423}
}