Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quantum-kittens
GitHub Repository: quantum-kittens/platypus
Path: blob/main/notebooks/summer-school/2021/resources/lab-notebooks/lab-5.ipynb
3855 views
Kernel: Python 3

In this lab, you will see how noise affects a typical parameterized quantum circuit used in machine learning using quantum process tomography.

For grading purposes, please specify all simulator arguments (noise_model=noise_thermal, seed_simulator=3145, seed_transpiler=3145, shots=8192) in the execute function.
# General tools import numpy as np import matplotlib.pyplot as plt # Qiskit Circuit Functions from qiskit import execute,QuantumCircuit, QuantumRegister, ClassicalRegister, Aer, transpile import qiskit.quantum_info as qi # Tomography functions from qiskit.ignis.verification.tomography import process_tomography_circuits, ProcessTomographyFitter from qiskit.ignis.mitigation.measurement import complete_meas_cal, CompleteMeasFitter import warnings warnings.filterwarnings('ignore')

Question 1

  • Make this Quantum Circuit

target = QuantumCircuit(2) target = # YOUR CODE HERE target_unitary = qi.Operator(target)

Quantum Process Tomography with Only Shot Noise

Here we will now use the qasm_simulator to simulate a Quantum Process Tomography Circuit

Question 2a

  • Using the Process Tomography Circuits function built into qiskit, create the set of circuits to do quantum process tomography and simulation with a qasm simulator (with shot noise only). For this please use the execute function of the QPT Circuits with seed_simulator=3145, seed_transpiler=3145 and shots=8192.

  • Hint: The appropriate function, process_tomography_circuits, has been imported above. When complete you should have a total of 144 circuits that are given to the qasm_simulator via the execute function. You can find out the number of circuits created using len(qpt_circs).

simulator = Aer.get_backend('qasm_simulator') qpt_circs = # YOUR CODE HERE qpt_job = execute(qpt_circs,simulator,seed_simulator=3145,seed_transpiler=3145,shots=8192) qpt_result = qpt_job.result()

Question 2b

  • Using a least squares fitting method for the Process Tomography Fitter, determine the fidelity of your target unitary

  • Hint: First use the ProcessTomographyFitter function above to process the results from question 2a and use ProcessTomographyFitter.fit(method='....') to extract the "Choi Matrix", which effectively describes the measured unitary operation. From here you will use the average_gate_fidelity function from the quantum information module to extract the achieved fidelity of your results

# YOUR CODE HERE

Quantum Process Tomography with a T1/T2 Noise Model

For the sake of consistency, let's set some values to characterize the duration of our gates and T1/T2 times:

# T1 and T2 values for qubits 0-3 T1s = [15000, 19000, 22000, 14000] T2s = [30000, 25000, 18000, 28000] # Instruction times (in nanoseconds) time_u1 = 0 # virtual gate time_u2 = 50 # (single X90 pulse) time_u3 = 100 # (two X90 pulses) time_cx = 300 time_reset = 1000 # 1 microsecond time_measure = 1000 # 1 microsecond
from qiskit.providers.aer.noise import thermal_relaxation_error from qiskit.providers.aer.noise import NoiseModel

Question 3

  • Using the Thermal Relaxation Error model built into qiskit, define u1,u2,u3, cx, measure and reset errors using the values for qubits 0-3 defined above, and build a thermal noise model.

  • Hint: The Qiskit tutorial on building noise models will prove to be useful, particularly where they add quantum errors for u1,u2,u3,cx, reset, and measure errors (please include all of these).

# QuantumError objects errors_reset = [thermal_relaxation_error(t1, t2, time_reset) for t1, t2 in zip(T1s, T2s)] errors_measure = [thermal_relaxation_error(t1, t2, time_measure) for t1, t2 in zip(T1s, T2s)] errors_u1 = [thermal_relaxation_error(t1, t2, time_u1) for t1, t2 in zip(T1s, T2s)] errors_u2 = [thermal_relaxation_error(t1, t2, time_u2) for t1, t2 in zip(T1s, T2s)] errors_u3 = [thermal_relaxation_error(t1, t2, time_u3) for t1, t2 in zip(T1s, T2s)] errors_cx = [[thermal_relaxation_error(t1a, t2a, time_cx).expand( thermal_relaxation_error(t1b, t2b, time_cx)) for t1a, t2a in zip(T1s, T2s)] for t1b, t2b in zip(T1s, T2s)] # Add errors to noise model noise_thermal = NoiseModel() # YOUR CODE HERE

Question 4.

  • Get a QPT fidelity using the noise model,but without using any error mitigation techniques. Again, use seed_simulator=3145, seed_transpiler=3145 and shots=8192 for the execute function

  • Hint: The process here should be very similar to that in question 2a/b, except you will need to ensure you include the noise model from question 3 in the execute function

np.random.seed(0) # YOUR CODE HERE

Question 5.

  • Use the complete_meas_cal function built into qiskit and apply to the QPT results in the previous question. For both, use the execute function and seed_simulator=3145, seed_transpiler=3145 and shots=8192. Also include the noise model from question 3 in the execute function.

  • Hint: The Qiskit textbook has a very good chapter on readout error mitigation. Specifically, you will want to use the complete_meas_cal function to generate the desired set of circuits to create the calibration matrix with CompleteMeasureFitter function. This can then be used to generate a correction matrix meas_filter. Apply this function to the results from question 4.

np.random.seed(0) # YOUR CODE HERE

Exploratory Question 6.

  • Test how the gate fidelity depends on the CX duration by running noise models with varying cx durations (but leaving everything else fixed).

(Note: this would ideally be done using the scaling technique discussed in the previous lecture, but due to backend availability limitations we are instead demonstrating the effect by adjusting duration of the CX itself. This is not exactly how this is implemented on the hardware itself as the gates are not full CX gates.)