# Mitigating the noise in a quantum circuit

I'm using Qiskit and I have a Quantum Circuit (say, circuit) that gives reasonable results when using the simulator, namely

sim_backend = provider.get_backend('qasm_simulator')
job = execute(circuit, sim_backend, shots=shots)


However, when switching to the true machine, namely

sim_backend = provider.get_backend('ibmq_16_melbourne')


I'm experiencing very noisy, meaningless results.

From my understanding, this is normal and, in these cases, error mitigation is performed by measuring the noise of the quantum circuit and then operating with this knowledge.

Could someone tell me which Qiskit routine I could use to mitigate noise and how?

EDIT

Following the comment by Davit Khachatryan and the answer by Martin Vesely, I have prepared the code below.

# --- Standard imports

%matplotlib inline
# Importing standard Qiskit libraries and configuring account
from qiskit import QuantumCircuit, execute, Aer, IBMQ
from qiskit.compiler import transpile, assemble
from qiskit.tools.jupyter import *
from qiskit.visualization import *

# --- Imports
from qiskit import QuantumCircuit, execute, BasicAer
from qiskit.tools.monitor import job_monitor

import math
from numpy import linalg as LA
import numpy as np
#%config jupy = 'svg' # Makes the images look nice

import time

import matplotlib.pyplot as plt

nBits    = 2

shots    = 8192

# --- Computation of the calibration matrix

from qiskit.ignis.mitigation.measurement import (complete_meas_cal,CompleteMeasFitter)
from qiskit import *

qr = QuantumRegister(2)
meas_calibs, state_labels = complete_meas_cal(qr=qr, circlabel='mcal')
backend = provider.get_backend('ibmq_16_melbourne')
job = execute(meas_calibs, backend=backend, shots=1000)
job_monitor(job, interval = 3)
cal_results = job.result()

meas_fitter = CompleteMeasFitter(cal_results, state_labels, circlabel='mcal')
print(meas_fitter.cal_matrix)

# --- Execution of the noisy quantum circuit

qc = QuantumCircuit(nBits, nBits)
qc.x(1)

qc.measure(qc.qregs[0], qc.cregs[0])
job = execute(qc, provider.get_backend('ibmq_16_melbourne'), shots = shots)
#job = execute(qc, BasicAer.get_backend('qasm_simulator'), shots = shots)
job_monitor(job, interval = 3)
result = job.result()
print(result.get_counts())

# --- Error correction

# Get the filter object
meas_filter = meas_fitter.filter

# Results with mitigation
mitigated_results = meas_filter.apply(result)
mitigated_counts = mitigated_results.get_counts(0)

print(mitigated_counts)


The noisy quantum circuit returns:

{'00': 661, '11': 34, '10': 7494, '01': 3}


The error mitigated noise circuit returns:

{'00': 132.05699755089069, '11': 29.711709316932044, '01': 0.4405790117450936, '10': 8029.790714120432}


Is that what I should expect?

• Hi, @JackOLantern :). Qiskit textbook has a nice tutorial about measurement error mitigation qiskit.org/textbook/ch-quantum-hardware/…. Mar 10 '20 at 17:36
• @DavitKhachatryan Following your comment and the answer by Martin Vesely, I have prepared the code in the question edit. Is the achieved result what I should expect in practice? Mar 13 '20 at 12:22
• I think you obtained good improvements. If you want to know more about error mitigation (EM) techniques I recommend these two papers: 10.1103/PhysRevLett.119.180509 and doi.org/10.1038/s41586-019-1040-7, where you can find two EM techniques that don't need additional qubit/gate resources like other error correction techniques. Also, notice, that these techniques are limited, so after some gate number (depth) these techniques are starting to fail to fight the noise. Mar 13 '20 at 14:13
• @DavitKhachatryan Thank you so much for your comment. Would you transform it as an answer? I would upvote. Mar 13 '20 at 16:43

I will provide some general comments concerning noise in quantum computers.

Noise in quantum systems is normal phenomena as these systems are probabilistic by nature. Under current state of development, quantum computers unfortunately does not allow to build complex deep circuits.

You can of course use additional qubits to introduce error correction which can be almost perfect with sufficient number of qubits (so-called threshold theorem). But adding qubits and gates introduces another source of noise, so again depth of circuits is constrained.

When quantum computers are in higher state of development, error correction will also be able to mitigate noise more effectively than nowadays.

Concerning the backend you use - Melbourne. My experience is that this processor is very noisy in comparison with others provided in IBM Q. It seems that this is caused by higher number of qubits, so qubits influence each other increasing noise level.

• Following your answer and the comment by @DavitKhachatryan, I have prepared the code in the question edit. Is the achieved result what I should expect in practice? Mar 13 '20 at 12:23
• If I understood it correctly, you put $X$ on qubit $q_1$. If there is no noise, the result should be $10$ always. Accroding to results you posted, it seems that after error correction probability of measuring $10$ increased. Probability of measuring $00$ which is result of spontaneus relaxation from state $10$ decreased significantly. So you are on good way to correct for noise. Of course, you are not able to eliminate noise completely but this is OK as quantum systems are probabilistic. Mar 13 '20 at 13:28
• Thank you so much. I accepted your answer :-) Mar 13 '20 at 13:46

As Martin Vesley has mentioned in his answer, there are some error correction techniques that require additional qubits and gates resources, and how we know the resources of nowadays QCs are limited, and that's why those techniques are not so useful today. But in 2017 new error correction techniques were proposed that don't require additional gates/qubits. As stated in the abstract of S. Endo et al [1] paper: two quantum error mitigation (QEM) techniques have been introduced recently, namely, error extrapolation (proposed by Y. Li and S. C. Benjamin [2] and K. Temme et al [3]) and quasiprobability decomposition (proposed by K. Temme et al [3]). How I understand, this Qiskit tutorial is an implementation of the second technique. The tutorial is written very nicely and intuitively, so I highly recommend it.

Here I will try to explain the first technique: error extrapolation. We want to estimate something from our circuit, let's call it $$E^*$$ (can be the expectation value of Hamiltonian or something else). Because of noise we always obtain a different value than $$E^*$$. Suppose we have a $$\lambda$$ parameter (in this experimental paper [4] they used pulse duration as a parameter: the gates are implemented via microwave pulses) that we can change and run different experiments with given values of $$\lambda$$. This give us different values for $$E(\lambda)$$ from which we will be able to construct the following system of equations:

$$\begin{cases} E(\lambda_1) = E^* + Noise(\lambda_1) \\ E(\lambda_2) = E^* + Noise(\lambda_2) \\ E(\lambda_3) = E^* + Noise(\lambda_3) \\ ... \end{cases}$$

By expressing the $$Noise(\lambda)$$ with some suitable function (e.g. a polynomial function) one can solve the system of equation and find the desired $$E^*$$ value "without" noise. In some cases, it works XD. I mean there should be the satisfaction of some conditions (e.g good fitting of chosen function to the actual noise).

These techniques are increasing the circuit depth that can be used, but that increment, of course, is not limitless (more insights can be gained from the Fig.2 from the [4] paper).

• Hi Davit. How about if we don't just want an expectation value like $E^* = \langle \psi| H| \psi\rangle$, but we want $|\psi \rangle$. For example the Deutsch algorithm says that if we get $|\psi \rangle = |0\rangle$ then the function is constant and if we get $|1\rangle$ then it's balanced. Can the methods of Endo, Li, Benjamin, and Temme et al. assist us in getting a better estimate of $|\psi\rangle$ ? Jul 12 '20 at 3:21
• Hi @user1271772. Let me recall the experimental results obtained in A. Kandala et al paper. They saw improvements in the estimation of the expectation value of the ground-state projector for identity-equivalent single-qubit Clifford sequences (Fig. 2) by using error extrapolation technique. The expectation value of the ground-state projector gives exactly what I think you want (an estimate if we have predicted $|0\rangle$ state), so I guess the answer is yes, although maybe I didn't understand the question right. Jul 12 '20 at 8:59
• If I remember right in the experiment described in Fig. 2 the mentioned ground state coincides with the $|0\rangle$ state. Jul 12 '20 at 9:12