Path: blob/main/notebooks/summer-school/2022/resources/lab-notebooks/lab-3.ipynb
3855 views
Lab 3: Quantum Noise
Welcome to Qiskit! Before starting with the exercises, please run the cell below by pressing 'shift' + 'return'.
III.1: Projection noise
Let us first take a look at the noise associated with sampling from a quantum state. When we measure an observable of a quantum system, we observe only the value of the observable associated with one of the eigenstates of the observable, regardless of wether the quantum system was described by a superposition of eigenstates of the observable before the measurement. In the case of superposition states, this introduces a sampling noise due to the finite number of times that we repeat the experiment.
1) First, create a uniform superposition of and , by acting with the Hadamard gate on the state and then measure it
2) Then retrieve the number of times the state or is observed
Remeber to pass the parameter specifying the number of shots to the simulator
The probability of observing , which can be taken to be the frequency with which we observed the outcome over all the trials: , can be far from the theoretical value of
3) Let's go from counts to probabilities, for different number of shots (repetitions of the experiment)
Given the definition of probability shown above, how does the probability of observing the state change with the increasing number of shots?
The frequency with which the state is observed tends to the theoretical one when the number of shots is increased
4) Given a fixed number of shots, estimate the mean and stardard deviation of the frequency of observing the state over many trials
When we consider a fixed number of shots, the number of times we observe the state out of the times we have carried out the experiment can fluctuate. Therefore, each time we calculate the probability of observing out of the we'll get different values. Let's estimate this frequency 10000 times and look how the estimate changes each time.
We can fit a Gaussian to the histogram of the counts to estimate the mean and the variance of the data. Use scipy's curve_fit function for the purpose. curve_fit will take the function for fitting, the x and y points to fit and a list of the initial guessed values for the fit. It will then return the estimate and the covariance matrix of the parameters mean and sigma of the gaussian(...) function which best fit the data. For grading purposes, append the estimated mean and the estimated standard deviation (in this order) to the mu_sigma list which will be submitted.
5) Check the standard deviation for different number of shots
By increasing the number of shots, which is the number of samples in the population, we can improve the estimate of the sample mean and its variance
Extract the values from the fit that correspond to the estimate of the standard deviation of the Gaussian distribution and check the validity of the formula .
III.2: Measurement Noise
Let's now consider the case where the measurement outcomes themselves are affected by noise. This can be thought of as mis-classification events. For example, we'll want to find out the probabilities of preparing the qubit in a certain state but then finding it in another one when measured. This type of error is often reffered to as State Preparation And Measurement (SPAM) error.
Create measurement noise model
1) First, prepare the qubit in the state and determine the probability of observing the qubit in the or
2) Then prepare the qubit in the state and determine the probability of observing the qubit in the or
3) Next build the confusion matrix from the measurements
The confusion matrix represents the linear transformation which takes the noiseless probabilities and adds the effect of mis-classification returning noisy probabilities
where
4) Finally, use confusion matrix to mitigate results of noisy experiment
Let's run a noisy experiment
And now we can mitigate the results using the estimated confusion matrix. First find the inverse of the confusion matrixa and then multiply it by the noisy probabilities
The resulting vector must be clipped and normalized to make sure that it represent valid probabilities
And compare it to the results of an ideal experiment
II.3: Coherent Noise
Coherent noise may creep in our quantum computers as a result of miscalibrations. For example, a rotation of an angle actually implement a rotation. Below we'll consider the case where the gate that implements a rotation around the axis RX() gate is affected by an over rotation of
1) Build a circuit with an RX() gate where
Don't forget to add measurement in the end.
Given the coherent noise present in the gate, a rotation around the axis won't take the state to the state exactly
l.4: Incoherent Noise
We can explore the effects of incoherent noise using Qiskit as well
1) Construct a depolarizing noise model
Now that you've seen how to create noise model for the measurement and coherent error, can you build one for a 5% depolarizing error on the idle (id) gate for qubit 0?
Let's use the noise model to see the effect of depolarizing error when the qubit is idling