• Docs >
  • Converting to probabilites
Shortcuts

Converting to probabilitesΒΆ

M3 natively works with qusi-probability distributions; distributions that contain negative values but none the less sum to one. This is useful for mitigaing expectation values, but there could be situations where a true probability distribution is useful / needed. To tbis 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.test.mock.backends import FakeCasablanca
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 = FakeCasablanca()
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()
{'010100': 7.86416193809551e-06,
 '011110': 1.7264709349716125e-05,
 '100001': 5.245884221890583e-05,
 '100010': 5.9133663797287825e-05,
 '010110': 5.9941433782020355e-05,
 '011100': 7.685330466423471e-05,
 '110110': 8.455495925798043e-05,
 '010011': 8.951568790109829e-05,
 '001011': 9.517840748574353e-05,
 '001101': 9.922752512907738e-05,
 '010111': 9.981590787297124e-05,
 '001100': 0.00010028077823071194,
 '101011': 0.0001529526095849419,
 '010001': 0.0001604809087679131,
 '011000': 0.00016474476196841665,
 '110011': 0.0001915675815910445,
 '011101': 0.00019705932252688893,
 '101000': 0.00022434871522253558,
 '110001': 0.00027543583901692146,
 '101110': 0.000284648111930869,
 '100000': 0.0003081824549177937,
 '011001': 0.00035899876430458394,
 '101111': 0.0014682939977470756,
 '110000': 0.0018246981958328677,
 '010000': 0.002097972201650074,
 '000010': 0.0021863109106002236,
 '000001': 0.0026892313743837794,
 '000100': 0.0027316644422791317,
 '111101': 0.0028080843312297205,
 '110111': 0.0029527650430604805,
 '011111': 0.0031335524043227016,
 '000110': 0.003173943540097509,
 '111110': 0.0032315848750988987,
 '111011': 0.0033478012995028284,
 '111000': 0.0038172432017601903,
 '111001': 0.0045253618152957375,
 '001111': 0.005300808700910417,
 '000111': 0.006084128806187508,
 '111111': 0.45660260060144137,
 '000000': 0.4888634458071396}