Converting to probabilites¶
M3 natively works with quasi-probability distributions; distributions that contain negative values
but nonetheless sum to one. This is useful for mitigating expectation values, but there could
be situations where a true probability distribution is useful / needed. To this end, it is
possible to find the closest probability distribution to a quasi-probability distribution in
terms of \(L2\)-norm using:
mthree.classes.QuasiDistribution.nearest_probability_distribution()
. This conversion is
done in linear time.
from qiskit import *
from qiskit_ibm_runtime.fake_provider import FakeCasablancaV2
import mthree
qc = QuantumCircuit(6)
qc.reset(range(6))
qc.h(3)
qc.cx(3,1)
qc.cx(3,5)
qc.cx(1,0)
qc.cx(5,4)
qc.cx(1,2)
qc.measure_all()
backend = FakeCasablancaV2()
mit = mthree.M3Mitigation(backend)
mit.cals_from_system(range(6))
trans_qc = transpile(qc, backend)
raw_counts = backend.run(trans_qc, shots=8192).result().get_counts()
quasis = mit.apply_correction(raw_counts, range(6))
# Here is where the conversion happens
quasis.nearest_probability_distribution()
{'011001': np.float32(4.707797e-05),
'110100': np.float32(5.650698e-05),
'101100': np.float32(6.83671e-05),
'011100': np.float32(7.7837496e-05),
'110001': np.float32(0.00010499917),
'010100': np.float32(0.000108673004),
'000101': np.float32(0.00012767228),
'011011': np.float32(0.00019099959),
'101101': np.float32(0.00026913657),
'100111': np.float32(0.0003418473),
'001110': np.float32(0.00037118915),
'001000': np.float32(0.0010693646),
'111101': np.float32(0.0013000557),
'100000': np.float32(0.0015309765),
'110000': np.float32(0.002023466),
'011111': np.float32(0.0021256532),
'000010': np.float32(0.0021290563),
'010000': np.float32(0.002521949),
'000110': np.float32(0.0030104595),
'000001': np.float32(0.0032607021),
'101111': np.float32(0.0033600668),
'111110': np.float32(0.003680723),
'000100': np.float32(0.004295373),
'110111': np.float32(0.0047780294),
'111011': np.float32(0.005021414),
'001111': np.float32(0.005311705),
'111001': np.float32(0.005769953),
'000111': np.float32(0.005814682),
'111000': np.float32(0.006640652),
'111111': np.float32(0.46323493),
'000000': np.float32(0.4713565)}