I have a simple 2 qubit circuit which I am trying to protect from errors using the measurement error mitigation technique laid out here: https://qiskit.org/textbook/ch-quantum-hardware/measurement-error-mitigation.html. My circuit is

circuit2 = QuantumCircuit();

noise_model = NoiseModel()
noise_model.add_all_qubit_readout_error([[1 - Er0,Er0], [Er1, 1 - Er1]])
result = execute(circuit2,backend=Aer.get_backend('qasm_simulator'),shots=maxShot,noise_model=noise_model).result()
counts = result.get_counts(0)

I then get the counts for each outcome and store it in a vector


As is laid out in the tutorial I obtain the calibration matrix and filter

aer_sim = Aer.get_backend('aer_simulator')
qr2q = QuantumRegister(2)
meas_calibs2q, state_labels2q = complete_meas_cal(qr=qr2q, circlabel='mcal2q')
t_qc = transpile(meas_calibs2q, aer_sim)
qobj = assemble(t_qc, shots=10000)
noise_model = NoiseModel()
noise_model.add_all_qubit_readout_error([[1 - Er0,Er0], [Er1, 1 - Er1]])    
cal_results2q = aer_sim.run(qobj, shots=10000,noise_model=noise_model).result()
meas_fitter2q = CompleteMeasFitter(cal_results2q, state_labels2q, circlabel='mcal2q')
meas_filter2q = meas_fitter2q.filter
import scipy.linalg as la
calmatinv2q = la.inv(calmat2q)

I then apply this to the earlier results to account for the noise

mitigated_results2q = meas_filter2q.apply(res2q[1])
mitigated_counts2q = mitigated_results2q.get_counts()

This works sensibly. However I thought that this is equivalent to applying the inverse of the calibration matrix to the vector of results that I have:


However sometimes this returns a negative counts. Obviously this isn't sensible so I assume that the measurement filter takes care of this somehow. Does anyone know how this is done? I wish to be able to do this manually because ideally I will run multiple two qubit circuits in parallel on the same quantum computer. So rather than running $2^n$ calibration circuits I will run 4 calibration circuits for each pair of qubits in isolation.


Unfortunately, the Qiskit textbook does not cover this topic correctly. In general you do get negative values when inverting the calibration matrix. These are called quasiprobabilities. You can use these directly for computing expectation values. Alternatively you can use a bounded least squares method to get the maximum likelihood estimate for the nearest probability distribution. In your case Qiskit is doing the latter.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.