16. Lab experimenthjkjj
16. Lab experimenthjkjj
Assignment 1
(Play with Vector, Matrix, and Complex Number in Python)
Section 1
Working with Python in Colab Open your Google Account here https://colab.research.google.com
(Refer the video for additional functionalities of Colab https://www.youtube.com/watch?v=rNgswRZ2C1Y)
Students can refer to https://www.pythonpool.com/python-vector/ or any other website to learn
how to use vectors in Python.
• Import NumPy and math package.
√ √
• Create variables by considering a = 1/ 2 and b = 1/ 2
• Create a vector or One-dimensional array using variables a and b.
• Check whether the vector is normalized or not. Vector is normalized if a2 + b2 = 1 in this
particular case.
• Find the length of a vector.
Section 2
Vector in Python Create a new notebook and add the following functionalities in the Colab note-
book:
• Create a vector and read the elements of the vector from the keyboard.
• Write a function that will check whether the function is normalized or not.
• Write a function to find the dot and cross product of two vectors (A and B) using NumPy.
• Write a function to find a unit vector corresponding to vector A.
Section 3
Matrices in Python Create a new notebook and add the following functionalities in the Colab
notebook using NumPy:
• Read a matrix from the Keyboard.
• Find the transpose of a matrix.
• Find the Determinant of a matrix ( Using linalg.det in NumPy).
• Find Rank of a matrix ( Using linalg.matrixr ank in numpy).
• Find Trace of the matrix
• Find Eigenvalue and Eigenvectors of a square matrix (Use linalg.eig).
• Find the Inverse of a matrix.
1
Section 4
Complex Number in Python Refer to https://realpython.com/python-complex-numbers/using-python-
complex-numbers-as-2d-vectors or any other site to read how to use complex numbers in python.
for Create a new notebook and add the following functionalities in the Colab notebook:
Section 5
Account Creation on IBM Q Experience Create your login id https://quantum-computing.ibm.com/
• After Login, go through the interface with the following two options:
– Launch Composer: working with IBM composer (Drag and drop Options).
– Working with IBM Qiskit (refer to https://qiskit.org/textbook/content/ch-ex/)
2
Faculty Name: Dr Ajay Kumar
Quantum Computing
Assignment 2
(Working with IBM Composer and qubit normalization )
Instructions: The assignment is self explanatory. Try yourself, as these concepts will be used for
later assignments.
Section 1
Working with Quantum Composer in IBM Q Experience Go through various features available in
Quantum Composer. Refer to the material available at the following site.
https://quantum-computing.ibm.com/composer/docs/iqx/overview
Section 2
Hands-on Experience on Quantum Composer Note: If you are not aware of quantum gates, no
issue, you need to cover this section to understand the concept of working with the quantum com-
poser.
1. Create the first circuit on the composer by referring to material available at:
https://quantum-computing.ibm.com/composer/docs/iqx/first-circuit.
Section 3
Learning about Hadamard Gate Create a circuit by adding a Hadamard gate to the composer.
Observe the result for a single shot ten times. Observe any pattern.
You can refer to the following link to learn about Hadamard gate:
https://www.youtube.com/watch?v=W0qrTMdzqtgt=220s
Learning: Every time, you get 0 or 1, which is perfectly random.
Section 4
Learning about QASM Learn how to write code in OPENQASM2.0 appear in the right side of the
circuit composer.
1. In Section 3, modify the program that appears in OpenQASM2.0 for single qubits and single
classical bits.
1
Section 5
Apply Hadamard gate to four qubits. Create four quantum bits and apply Hadamard gate on all
four qubits. Run it and observe the outcome.
Section 6
Complex Number in Python
1. Refer to the material on converting the complex number into the polar form and vice versa.
Visit the site https://math.libretexts.org/ and search for the Polar Form of Complex Numbers.
2. Import cmath in python and use the cmath.polar for converting a complex number to polar
form.
2
Faculty Name: Dr Ajay Kumar
Quantum Computing
Assignment 3
(Working with QASM )
Instructions: The assignment is self explanatory. Try yourself, as these concepts will be used for
later assignments.
Section 1
Play with Bell states Write down code in QASM for Creating the following Bell states (Do not use
Drag and Drop option)
√
1. |ψ1 ⟩ = 1/ 2(|00⟩ + |11⟩)
√
2. |ψ2 ⟩ = 1/ 2(|00⟩ − |11⟩)
√
3. |ψ3 ⟩ = 1/ 2(|01⟩ + |10⟩)
√
4. |ψ4 ⟩ = 1/ 2(|01⟩ − |10⟩)
√
5. |ψ5 ⟩ = 1/ 2(|000⟩ + |111⟩)
√
6. |ψ6 ⟩ = 1/ 2(|000⟩ − |111⟩)
Run one of the above programs on actual hardware, and rest can be run on a simulator. Compare
the output of actual hardware and simulator, if any.
Section 2
Toffoli Gate Note: CCNOT(Toffoli Gate) is a third qubit gate with two controlled qubits. If both
controlled qubits are 1 then the target qubit will be flipped. Write down a QASM program where
you need to design a four qubits-controlled gate with three qubits acting as control qubits. If all
three controlled qubits are equal to one, flip the target qubit.
Hint: Use Two Taffoli gates and additional qubits if required.
Section 3
Toffoli Gate Toffoli Gate is a Universal Gate. Write QASM program to perform the followings:
Section 3
Half Adder Write down a QASM Program to create half adder.
Hint: Make use of CCNOT and CNOT
1
Faculty Name: Dr Ajay Kumar
Quantum Computing
Assignment 4
(Working with QASM and Start working with Qiskit)
Instructions: The assignment is self explanatory. Try yourself, as these concepts will be used for
later assignments.
Section 1
Fredkin (CSWAP) Gate Write down a QASM Program to show that Fredkin gate act as AND
Gate (Do not use the Drag and Drop option).
Section 2
CSWAP as NOT Write down a QASM Program to show that Fredkin gate act as NOT Gate (Do
not use the Drag and Drop option).
Section 3
CSWAP has its own inverse Section 1 and Section 2 indicate that CSWAP is a universal gate.
Now Write down a QASM Program to verify that CSWAP has its own inverse.
Section 4
Verify the Identities using QASM
1. X 2 = Y 2 = Z 2 = I
2. X = HZH
3. Z = HXH
4. S = T 2
5. −1Y = XY X
Section 5
Move towards Qiskit You can start working by selecting Quantum Lab instead of Composer. Com-
plete Section 1.3 from Qiskit Textbook https://qiskit.org/textbook/ch-states/representing-qubit-
states.html
1. Create a state vector that will give a 1/3 probability of measuring |0⟩.
2. Create a different state vector that will give the same measurement probabilities.
3. Verify that the probability of measuring |1⟩ for these two states is 2/3.
1
Faculty Name: Dr Ajay Kumar
Quantum Computing
Assignment 5
(Working with single qubit in Qiskit )
Instructions: The assignment is self-explanatory. Try yourself, as these concepts will be used for
later assignments.
√ For Section 1 to Section 6, repeat these questions for quantum state
|0⟩, |1⟩, 1/ 2(|0⟩ + |1⟩)
Section 1
X-Gate on Bloch Sphere and State Vector Create a quantum circuit with single qubit.
Section 2
Y-Gate on Bloch Sphere and State Vector Create a quantum circuit with single qubit.
Section 3
Z-Gate on Bloch Sphere and State Vector Create a quantum circuit with single qubit.
1
Section 4
Phase-Gate on Bloch Sphere and State Vector Create a quantum circuit with single qubit.
1. Apply S-Gate to the qubit.
Section 5
T-Gate on Bloch Sphere and State Vector Create a quantum circuit with single qubit.
1. Apply T-Gate to the qubit.
Section 6
S † -Gate on Bloch Sphere and State Vector Create a quantum circuit with single qubit.
1. Apply S † -Gate to the qubit.
Section 6
T † -Gate on Bloch Sphere and State Vector Create a quantum circuit with single qubit.
1. Apply T † -Gate to the qubit.
2
Section 7
U-Gate on Bloch Sphere and State Vector Universal single qubit gate is defined using U (θ, ϕ, λ) =
−eiλ sin(θ/2)
cos(θ/2)
Create a quantum circuit with a single qubit. Find the value of
eiϕ sin(θ/2) ei(λ+ϕ) cos(θ/2)
(θ, ϕ, λ) for X, Y, Z, H, S, T, S † , T † and verify it using state vector and Bloch sphere.
3
Faculty Name: Dr Ajay Kumar
Quantum Computing
Assignment 6
(Working with superdense coding, Teleportation )
Instructions: The assignment is self-explanatory. Try yourself, as these concepts will be used for
later assignments.
Section I
Superdense Coding Protocol is a procedure that allows someone to send two classical bits to an-
other party using just a single qubit of communication. Implement the superdense coding protocol
in Qiskit. Refer https://qiskit.org/textbook/ch-algorithms/superdense-coding.html
Section 2
Teleportation Protocol is a procedure by which the state of qubit (|ψ⟩) can be transmitted from one
location to another using two bits of classical communication and a Bell pair. Implement the tele-
portation protocol in Qiskit. Refer https://qiskit.org/textbook/ch-algorithms/teleportation.html
Section 3
Phase Kickback
1. Explain the procedure of reverse CNOT using the concept of Phase Kickback. You can
implement the reverse CNOT operation in Qiskit.
1
Instructions: The assignment is self-explanatory. Try yourself, as these concepts will be used for later
assignments.
Section I
Write Qiskit code to play the Quantum Coin Game. Compare the efficiency of the quantum coin game
over classical coin toss game.
Refer: https://qiskit.org/textbook/ch-demos/coin-game.html
Section 2
Write Qiskit code for Estimating Pi Using Quantum Phase Estimation Algorithm.
Refer: https://qiskit.org/textbook/ch-demos/piday-code.html
Section 3
Implement the Deutsch-Jozsa Algorithm.
Refer: https://qiskit.org/textbook/ch-algorithms/deutsch-jozsa.html