• Docs >
• Converting to probabilites
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.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()

{'001011': 8.60828898275366e-06,
'101110': 1.4562884520840687e-05,
'101101': 2.494835831407863e-05,
'101000': 3.715769323245027e-05,
'111010': 4.680923015887535e-05,
'110100': 5.532618421586178e-05,
'100010': 5.9059086823900464e-05,
'001100': 7.517230796699085e-05,
'010110': 8.021455375404522e-05,
'101100': 9.646006228515503e-05,
'110101': 0.00010500286183992412,
'110110': 0.00013203390655915998,
'110001': 0.00024274756766435056,
'011001': 0.00030729949513068106,
'010100': 0.0003126829080481585,
'001110': 0.00033995440302308615,
'000010': 0.0004463507979273928,
'011011': 0.0004599613900048058,
'000100': 0.0007293479877807038,
'010000': 0.0007802256727837155,
'011111': 0.001116219083519195,
'100000': 0.0016540639233347174,
'000001': 0.0020947616416491927,
'110111': 0.002216687514973851,
'110000': 0.0026400375649761627,
'111101': 0.0027123005828100454,
'001000': 0.0027258570294482667,
'000110': 0.003225351049871777,
'001111': 0.0033475266795865975,
'101111': 0.0035771419987687624,
'111011': 0.0036730418077369977,
'111110': 0.004665861758681473,
'111000': 0.004745599268696854,
'111001': 0.006001991723276553,
'000111': 0.0071996542937124266,
'111111': 0.45182416399194203,
'000000': 0.4922258144459982}