Shortcuts

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.providers.fake_provider 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()
{'001011': 1.5314358724061895e-06,
 '001100': 2.790491160821504e-06,
 '011011': 1.438376561809497e-05,
 '001010': 2.749144923875241e-05,
 '011110': 4.553476237092375e-05,
 '100010': 5.65753172043281e-05,
 '010110': 5.751562675828546e-05,
 '110100': 6.072784188569222e-05,
 '110011': 6.658424106686312e-05,
 '101010': 6.747980042141165e-05,
 '110010': 7.043135524424228e-05,
 '011010': 8.5139663657328e-05,
 '010111': 0.00013213680184049443,
 '011000': 0.0001348805658826323,
 '001101': 0.00014435810861692462,
 '110001': 0.00015642012445324474,
 '100100': 0.000167259006966876,
 '001001': 0.00017004512930302636,
 '100110': 0.00018347884623769263,
 '110101': 0.00018973871107200486,
 '101001': 0.00026109708172235334,
 '101011': 0.00026870199158801763,
 '101101': 0.00036878782948060376,
 '110110': 0.0004232616543754721,
 '010000': 0.00044408578930663696,
 '111010': 0.00045109584814068365,
 '101110': 0.0005444504984505818,
 '100000': 0.0008987092272457007,
 '000100': 0.001678317755470415,
 '000001': 0.0020555468671929838,
 '110000': 0.0022090807556861785,
 '111011': 0.0024987445676576104,
 '000010': 0.0025374450386821206,
 '011111': 0.002541114780612132,
 '000110': 0.00398294918845233,
 '001111': 0.004098300786809285,
 '111001': 0.004126687990412093,
 '101111': 0.004208510902291168,
 '111101': 0.0047280741913013164,
 '110111': 0.005325722105922742,
 '111110': 0.0062090228439804695,
 '000111': 0.0064015960262806025,
 '111000': 0.007376250974320665,
 '111111': 0.4514167038080576,
 '000000': 0.48311123845168796}