CCS359 - Quantum Computing Manual (WOL)
CCS359 - Quantum Computing Manual (WOL)
1
BONAFIDE CERTIFICATE
Name : …………………………………………………………
Degree : …………………………………………………………
Branch : …………………………………………………………
Certified that this is the bonafide record of the work done by the above student in
…………………………………………………………………………………………………
2
LAB MANNERS
• Students must be present in proper dress code and wear the ID card.
• Students should enter the log-in and log-out time in the log register without fail.
• Students are not allowed to download pictures, music, videos or files without
thepermission of respective lab in-charge.
• Students should wear their own lab coats and bring observation note books to
thelaboratory classes regularly.
• Record of experiments done in a particular class should be submitted in the nextlab
class.
• Students who do not submit the record note book in time will not be allowed to
dothe next experiment and will not be given attendance for that laboratory class.
• Students will not be allowed to leave the laboratory until they complete the
experiment.
• Students are advised to switch-off the Monitors and CPU when they leave the lab.
• Students are advised to arrange the chairs properly when they leave the lab.
3
S.No Date Name of the Experiment Page Marks Staff Remarks
No. Awarded Signatu re
Single Qubit Gate Simulation -
1. Quantum Composer
Implementation of Shor's
5. Algorithm
6. Implementation of Grover's
Algorithm
7. Implementation of Deutsch's
Algorithm
8. Implementation of
Deutsch-Jozsa Algorithm
11
Dhirajlal Gandhi College of Technology
AIM
ALGORITHM
PROGRAM
qc.z(0)
OUTPUT
Quantum Circuit:
┌───┐┌───┐┌───┐
q_0 : ┤ X ├┤ Z ├┤ H ├
└───┘└───┘└───┘
2
Dhirajlal Gandhi College of Technology
RESULT
The single qubit gates were successfully simulated using the quantum composer (Qiskit), and the final
state was observed.
3
Dhirajlal Gandhi College of Technology
AIM
To simulate multi-qubit gate operations such as CNOT and Toffoli using a quantum composer.
ALGORITHM
PROGRAM
print("Measurement Results:")
print(counts)
plot_histogram(counts)
OUTPUT
Quantum Circuit:
┌───┐
q_0: ┤ H ├──■──
└───┘ ┌─┴─┐
q_1: ─────┤ X ├
└───┘
q_0: ─ |M| ──────
q_1: ─ |M| ──────
Measurement Results:
Histogram:
| 00 | ██████████ 50%
| 11 | ██████████ 50%
RESULT
The multiple qubit gates (CNOT) were simulated successfully, and the entangled state was
observed.
5
Dhirajlal Gandhi College of Technology
AIM
To compose a simple quantum circuit using quantum gates and measure the output into classical bits.
ALGORITHM
1. Initialize a quantum circuit with one qubit and one classical bit.
2. Apply a series of gates (X, H, Z, etc.) to manipulate the quantum state.
3. Measure the quantum state and store the result in a classical bit.
4. Execute the circuit and observe the results.
PROGRAM:
OUTPUT:
Quantum Circuit:
┌───┐┌───┐┌───┐ ┌─┐
q_0: ┤ H ├┤ Z ├┤ X ├┤M├
└───┘└───┘└───┘ └─┘
c_0: ═════════════════════
Measurement Results:
{'0': 512, '1': 512}
Histogram:
| 0 | ██████████ 50%
| 1 | ██████████ 50%
RESULT
The quantum circuit was successfully composed using multiple gates, and the output was
measured into classical bits.
7
Dhirajlal Gandhi College of Technology
AIM
To understand the IBM Qiskit platform and implement a basic quantum circuit using Qiskit.
ALGORITHM
PROGRAM
# Apply an H gate
qc.h(0)
plot_bloch_multivector(state)
OUTPUT
Quantum Circuit:
┌───┐
q_0: ┤ H ├
└───┘
Quantum State:
[ 0.70710678+0.j 0.70710678+0.j]
RESULT
The IBM Qiskit platform was introduced, and a basic quantum circuit was successfully
implemented and visualized.
9
Dhirajlal Gandhi College of Technology
AIM
To implement Shor’s algorithm for integer factorization using quantum circuits.
ALGORITHM
1. Choose a composite number NNN (e.g., N=15N = 15N=15).
2. Randomly select a number aaa such that 1<a<N1 < a < N1<a<N.
3. Check if gcd(a,N)≠1\text{gcd}(a, N) \neq 1gcd(a,N) =1:
o If true, gcd(a,N)\text{gcd}(a, N)gcd(a,N) is a factor of NNN.
4. Apply quantum operations to determine the period rrr of axmod Na^x \mod NaxmodN.
5. Compute the factors using gcd(ar/2±1,N)\text{gcd}(a^{r/2} \pm 1, N)gcd(ar/2±1,N).
6. Verify the factors.
PROGRAM
10
Dhirajlal Gandhi College of Technology
OUTPUT
RESULT
Shor’s algorithm was successfully implemented to factorize a composite number NNN using Qiskit.
11
Dhirajlal Gandhi College of Technology
AIM
To implement Grover's search algorithm for finding a marked item in an unsorted database.
ALGORITHM
1. Define a quantum circuit with nnn qubits for 2n2^n2n database elements.
2. Initialize the qubits into an equal superposition state using Hadamard gates.
3. Apply the oracle to mark the desired element.
4. Apply the Grover diffusion operator to amplify the marked element's probability.
5. Repeat steps 3-4 for N\sqrt{N}N iterations.
6. Measure the qubits to identify the marked element.
PROGRAM
44
Dhirajlal Gandhi College of Technology
OUTPUT
Quantum Circuit:
┌───┐ ┌─────────┐ ┌───┐ ┌─┐
q_0: ┤ H ├───┤ Oracle ├───┤ H ├┤ M ├
└───┘ └─────────┘ └───┘ └─┘
c_0: ═══════════════════════════════════════
c_1: ═══════════════════════════════════════
Measurement Results:
RESULT
Grover’s search algorithm was successfully implemented, demonstrating its ability to locate a
marked item in an unsorted database efficiently.
45
Dhirajlal Gandhi College of Technology
AIM
To implement Deutsch's algorithm to determine whether a given quantum function is constant or balanced
using a single evaluation.
ALGORITHM
PROGRAM
50
Dhirajlal Gandhi College of Technology
OUTPUT
Quantum Circuit:
c_0: ═══════════════════════════════════════
Measurement Results:
• If the oracle is constant, the outcome of the first qubit after applying the Hadamard gate will be 0
Then the Measurement Results:
{'0': 1024}
• If the oracle is balanced, the first qubit will likely collapse to 1 after applying the Hadamard gate
Then the Measurement Results:
{'1': 1024}
RESULT
Deutsch's algorithm was successfully implemented to determine whether a given quantum function is
constant or balanced.
51
Dhirajlal Gandhi College of Technology
AIM
To implement the Deutsch-Jozsa algorithm to determine if a given function is constant or balanced using a
quantum circuit.
ALGORITHM
1) Create a quantum circuit with n+1n+1n+1 qubits and nnn classical bits.
2) Initialize nnn qubits to ∣0⟩|0\rangle∣0⟩ and the last qubit to ∣1⟩|1\rangle∣1⟩.
3) Apply Hadamard gates to all qubits.
4) Apply the oracle representing the function f(x)f(x)f(x).
5) Apply Hadamard gates to the nnn input qubits.
6) Measure the nnn input qubits:
• Output 0...00...00...0: Function is constant.
• Any other result: Function is balanced.
PROGRAM
# Define the Deutsch-Jozsa oracle for a balanced function (e.g., f(x) = x1 XOR x2)
def balanced_oracle(n):
oracle = QuantumCircuit(n + 1)
for qubit in range(n):
oracle.cx(qubit, n)
return oracle.to_gate()
53
Dhirajlal Gandhi College of Technology
OUTPUT
Quantum Circuit:
┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐┌─┐
q_0: ┤ H ├───┤ H ├───┤ X ├┤ H ├───┤M├
├───┤ ├───┤ └───┘ └───┘└─┘
c_0: ═══════════════════════════════════════
c_1: ═══════════════════════════════════════
Measurement Results:
• If the oracle is constant (i.e., f(x) = 0 for all inputs), the output will be 0 for all measurements.
Then the Measurement Results:
{'00': 1024}
• If the oracle is balanced (i.e., f(x) = x1 XOR x2 ), the output will be 00 with certainty
Then the Measurement Results:
{'00': 1024}
RESULT
The Deutsch-Jozsa algorithm was successfully implemented, demonstrating its ability to classify
functions as constant or balanced with a single evaluation.
54
51