Advanced usage

Options for M3Mitigation class


The main mthree.M3Mitigation class accepts the iter_threshold keyword argument that determines when the automated method selector pickes the iterative method over direct LU factorization (selection also depends on free memory).

from qiskit.test.mock.backends import FakeCasablanca
import mthree

backend = FakeCasablanca()
mit = mthree.M3Mitigation(backend, iter_threshold=4321)

Options for calibration


When calibrating the mitigator, it is possible to vary the number of shots per calibration circuit:

mit = mthree.M3Mitigation(backend)
mit.cals_from_system(range(5), shots=4321)


There are three ways to do the calibration. The default balanced method executes \(2N\) circuits with varying bitstring patterns such that the \(|0\rangle\) and \(|1\rangle\) states are each prepared \(N\) times and averaged over. For example, the balanced bit-strings over four qubits are

['0101', '1010', '0011', '1100', '0001', '1110', '0000', '1111']

The independent method also sends \(2N\) circuits but measures only a single qubit at a time. As such, this is a truely uncorrelated calibration process.

Finally, a marginal calibration can also be done that sends only two circuits, \(|0\rangle^{\otimes N}\) and \(|1\rangle^{\otimes N}\), and marginalizes over the results to get the needed \(2N\) error rates. These two states are a sub-set of the balanced calibrations, and are what Qiskit uses in its readout mitigation. This method is very sensitive to state preparation errors, and should not be used in practice.

An example setting the method is

mit = mthree.M3Mitigation(backend)
mit.cals_from_system(range(5), method='independent')



Do not set this unless you know what you are doing.

The rep_delay keyword argument sets the time between calibration circuits on IBM Quantum systems. This option exists to test and reduce the presence of state prep errors. The calibration circuits in M3 all contain conditional resets at the beginning so as to minimize the need for setting this option.

mit = mthree.M3Mitigation(backend)
mit.cals_from_system(range(5), rep_delay=400e-6)



Do not set this unless you know what you are doing.

A boolean value that specifies whether reset instructions should be used at the beginning of the calibration circuits. Ideally this helps to supress any residual state prep errors that occur from imperfect reset of the qubits. Can be used in concert with, or as an alternative to rep_delay. Note that, in order for this to work, the circuits that need to be mitigated must also have reset instructions at the beginning. Otherwise you are calibrating for no state-prep errors, but the actual circuits may still suffer from these errors.

Options when applying corrections

Here we first calibrate a mitigator and generate raw counts:

from qiskit import *

qc = QuantumCircuit(6)

mit = mthree.M3Mitigation(backend)

trans_qc = transpile(qc, backend)
raw_counts =, shots=8192).result().get_counts()


There are two ways to solve the linear system of equations generated by M3. First, the direct method uses LU-factorization by constructing the reduced assignment matrix. Second the iterative method uses preconditioned iterative solvers to find the solution vector without explicit matrix construction. By default M3 uses an auto method that selects the appropriate solution method based on the number of unique bit-strings and the available free memory on the computer. To override this, one can simply set the option:

quasis = mit.apply_correction(raw_counts, range(6), method='iterative')


Optionally one may trucate the M3 assignment matrix to only those elements of the matrix that are transistions between elements less than or equal to a given Hamming distance away from each other. This does not change the dimensionality of the underlying matrix, but rather changes the sparsity pattern of the elements. This is done using the distance keyword argument. By default, M3 computes the corrections out to the full distance. In practice, including only up to distance=3 elements yields accurate answers in most cases.

quasis = mit.apply_correction(raw_counts, range(6), distance=3)


Allows one to see additional information about the solution. This changes the return of the :method:mthree.M3Mitigation.apply_correction method to a tuple of two values:

quasis, details = mit.apply_correction(raw_counts, range(6), details=True)
{'method': 'direct', 'time': 0.0002668030000450017, 'dimension': 47, 'col_norms': array([0.99943865, 0.99347646, 0.97205864, 0.98591937, 0.97825785,
       0.98604803, 0.98562676, 0.99895839, 0.97956671, 0.99924668,
       0.96998703, 0.96983422, 0.95754802, 0.9986496 , 0.97964674,
       0.97993643, 0.93041193, 0.97937017, 0.99902603, 0.95517024,
       0.95493629, 0.94237729, 0.99752003, 0.98568407, 0.9646999 ,
       0.9303736 , 0.979488  , 0.98402622, 0.95480809, 0.95505706,
       0.94270152, 0.99752054, 0.98707037, 0.97197377, 0.94816154,
       0.94920075, 0.92143313, 0.92884283, 0.99556541, 0.9986932 ,
       0.99950014, 0.94871698, 0.99756415, 0.93398557, 0.99709479,
       0.99656123, 0.99985508])}



Do not set this unless you know what you are doing.

Sets the maximum number of iterations performed by the iterative solver.

quasis = mit.apply_correction(raw_counts, range(6), method='iterative', max_iter=10)



Do not set this unless you know what you are doing.

Sets the tolerance of the iterative solver. Might need adjustments to max_iter if value is set too low.

quasis = mit.apply_correction(raw_counts, range(6), method='iterative', tol=1e-6)