0% found this document useful (0 votes)
22 views39 pages

SY IQC Lab Manual

Uploaded by

ajaybadhe2105
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views39 pages

SY IQC Lab Manual

Uploaded by

ajaybadhe2105
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 39

G H Raisoni College of Engineering &

Management, Pune – 412 207

Department of Computer Engineering

D-19
Lab Manual (2025-2026)
Class: SY B. Tech. Computer​
Term: IV
23UQCMDP2301: Quantum Computing Lab
G H Raisoni College of Engineering and Management, Pune 412207


Department: Computer Engineering

Course Details
Course: 23UQCMDP2301: Quantum Computing Lab

Class: S Y B.Tech.​ Division: A, B, C


Internal Marks: --​ External marks: 25

Credits : 2​ Pattern: 2023

COURSE OUTCOME
Understanding the Basic Concepts of Quantum Computing and apply it on various
CO1: applications.

CO2: Understand the concept of Qubit and Mathematics related to Quantum Computing.

Elaborate the concepts of Quantum states in single and multiple systems and apply
CO3: it in quantum computing.

CO4: Discuss various types of Quantum Gates and apply it to design the circuits.
Department of Computer Engineering

Course Introduction to Quantum Computing


(23QCMDP2301)

List of Experiments

Sr. CO Software
Experiment List
No. Mapping Required
Anaconda,
1.​ Installation of Qiskit CO1
qiskit
Anaconda,
Linear Algebra, Vector Operation, Vector
2.​ CO2 qiskit
Multiplication, Tensor Product
Anaconda,
Implementation of Identity Matrix:1 Qubit, 2 Qubits,
3.​ CO2 qiskit
3 Qubits
Anaconda,
4.​ Implementation of Pauli Gates CO3 qiskit

Anaconda,
Implementation of Hadamard Gates
5.​ CO3 qiskit

Anaconda,
6.​ Implementation of 2 Qubit Gates CO4 qiskit

Anaconda,
7.​ Implementation of 3 Qubit Gates CO4 qiskit

Anaconda,
8.​ Implementation of Circuit Formation-1 CO4 qiskit

Anaconda,
9.​ Implementation of Circuit Formation-2 CO4 qiskit

10.​ Case Study: IBM Cloud related quantum computing CO4


Experiment No 1

Aim: Installation of Qiskit

Theory:

Install the Qiskit SDK and the Qiskit Runtime client


1.Install Python. Check the "Programming Language" section on the Qiskit PyPI project page to
determine which Python versions are supported by the most recent release.

It is recommended that you use Python virtual environments to separate Qiskit from other
applications.

First, navigate to your project directory and create a minimal environment with only Python
installed in it.

1.​ macOS

Linux

Windows

python -m venv .venv

Next, activate your new environment.

macOS

Linux

Windows

If using PowerShell:

.venv\Scripts\Activate.ps1

If using Git Bash:


source .venv/scripts/activate

If using command prompt:

.venv\Scripts\activate

2.​ Install pip if it's not already installed in your environment. Pip is a Python
package manager that you use to install Qiskit and other Python
packages. Use pip list to see what is in your virtual environment. In
most Python environments, pip is already installed.
3.​ Install the Qiskit SDK. If you plan to run jobs on quantum hardware, also
install Qiskit Runtime.

pip install qiskit


pip install qiskit-ibm-runtime

If you intend to use visualization functionality or Jupyter notebooks, it is


recommended to install Qiskit with the extra visualization support
('qiskit[visualization]').

Default

zsh

pip install qiskit[visualization]

1.​ If you want to run a Jupyter notebook with the Qiskit packages you just
installed, you need to install Jupyter in your environment.

pip install jupyter

Then open your notebook as follows:

jupyter notebook <path/to/notebook.ipynb>

If you are planning to work locally and use simulators built into Qiskit, then your
installation is done.
Conclusion :
The successful installation of Qiskit provides the foundation for exploring and developing quantum
computing applications. As an open-source SDK developed by IBM, Qiskit allows users to create quantum
circuits, simulate them, and run experiments on real quantum hardware. The installation process, while
straightforward, requires proper configuration of Python and related packages to ensure smooth
functionality. With Qiskit now set up, users are equipped to begin hands-on experimentation with quantum
algorithms, circuit design, and simulations, opening the door to deeper learning and innovation in the field
of quantum computing.

Question:

1)​ What is Quantum Computing?


2)​ Features of Quantum Computing
3)​ Comparison Classical Computing and Quantum Computing
4)​ Quantum Computers in development
5)​ Uses and benefits of Quantum Computing
6)​ Application of Quantum Computing
Experiment No 2

Aim: Linear Algebra, Vector Operation, Vector Multiplication, Tensor Product


Theory:

1. Linear Algebra (Overview)


Linear algebra is the branch of mathematics dealing with vectors, matrices, and linear
transformations. In quantum computing:
●​ Qubit states are vectors.
●​ Quantum gates are matrices.
●​ State evolution involves matrix-vector multiplication.

✅ 2. Vector Operations
A vector is an ordered list of numbers (real or complex), represented as:
b) Outer Product

●​ Produces a matrix.
●​ Useful in constructing density matrices and projectors.

✅ 4. Tensor Product (Kronecker Product)


The tensor product combines two vectors (or matrices) into a larger one — essential in
representing multi-qubit systems.
🔹
If
For vectors:


Program:

from qiskit.quantum_info import Statevector


from numpy import sqrt

u = Statevector([1 / sqrt(2), 1 / sqrt(2)])


v = Statevector([(1 + 2.0j) / 3, -2 / 3])
w = Statevector([1 / 3, 2 / 3])

print("State vectors u, v, and w have been defined.")

display(u.draw("latex"))
display(v.draw("text"))

Output:
Program:

from qiskit.visualization import plot_histogram


statistics = v.sample_counts(1000)
display(statistics)
plot_histogram(statistics)

Output:
Conclusion:
Linear algebra serves as the mathematical backbone of quantum computing and many
areas of science and engineering. A solid understanding of vector operations, including
addition, scalar multiplication, and inner (dot) and outer products, provides the essential
tools for manipulating quantum states and performing complex calculations. The tensor
product, in particular, plays a crucial role in quantum mechanics, allowing us to
represent composite systems and multi-qubit states.

Experiment No 3

Aim: Implementation of Identity Matrix:1 Qubit, 2 Qubits, 3 Qubits

Theory:
Identity Matrix in Quantum Computing
The identity matrix III is a matrix that, when applied to any quantum state vector
∣ψ⟩|\psi\rangle∣ψ⟩, leaves it unchanged:
I∣ψ⟩=∣ψ⟩I |\psi\rangle = |\psi\rangleI∣ψ⟩=∣ψ⟩
It is used to:
●​ Represent no operation on a qubit.
●​ Extend circuits when only some qubits are acted upon.
●​ Serve as a base for tensor products with other gates.
Program:

from qiskit import QuantumCircuit


from qiskit.quantum_info import Operator

# Function to create identity matrix for n qubits


def identity_matrix(n_qubits):
# Create a quantum circuit with n qubits
qc = QuantumCircuit(n_qubits)

# Apply the identity gate to all qubits using the `id()` method
for i in range(n_qubits):
qc.id(i)

# Convert the quantum circuit to an operator (matrix)


identity_matrix_nq = Operator(qc).data

return identity_matrix_nq

# Example: Identity matrix for 1, 2, and 3 qubits


identity_matrix_1q = identity_matrix(1)
identity_matrix_2q = identity_matrix(2)
identity_matrix_3q = identity_matrix(3)

print("Identity matrix for 1 qubit:")


print(identity_matrix_1q)

print("\nIdentity matrix for 2 qubits:")


print(identity_matrix_2q)
print("\nIdentity matrix for 3 qubits:")
print(identity_matrix_3q)

Output:
Conclusion:
The identity matrix is a fundamental component in quantum computing, representing a
no-operation (no-op) gate that leaves a qubit's state unchanged. Its implementation across
different qubit systems—1 qubit (2×2), 2 qubits (4×4), and 3 qubits (8×8)—demonstrates
how quantum systems scale exponentially with the number of qubits. Understanding and
constructing identity matrices for multi-qubit systems is crucial for circuit design,
especially in preserving qubit states or aligning gate operations in larger quantum
algorithms.

Experiment No 4

Aim: Implementation of Pauli Gates

Theory:

Pauli Gates: X, Y, Z
The Pauli gates are three fundamental single-qubit gates that correspond to quantum spin
operators. They are also unitary, Hermitian, and involutory (their own inverse).
Program:

1.​ Pauli-X Gate:


from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
from numpy import pi

qc = QuantumCircuit(1,1)
qc.x(0)
qc.measure(0, 0)

print("Circuit diagram:")
print(qc.draw())
Output:

2.​ Pauli-Y Gate:


from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
from numpy import pi

qc = QuantumCircuit(1,1)
qc.y(0)
qc.measure(0, 0)

print("Circuit diagram:")
print(qc.draw())

Output:
3.​ Pauli-Z Gate:
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
from numpy import pi

qc = QuantumCircuit(1,1)
qc.y(0)
qc.measure(0, 0)

print("Circuit diagram:")
print(qc.draw())

Output:
Conclusion:
The implementation of Pauli gates—X, Y, and Z—is essential to understanding and
building quantum circuits. These single-qubit gates form the foundation of quantum
logic, performing basic but powerful operations such as bit-flip (X), phase-flip (Z), and
combined operations (Y). Their matrix representations and effects on quantum states are
fundamental to quantum computation and quantum information theory. Through practical
implementation using simulation tools like Qiskit, we gain valuable insight into how
these gates manipulate qubit states on the Bloch sphere and how they serve as building
blocks for more complex gates and quantum algorithms.

Experiment No 5

Aim: Implementation of Hadamard Gates

Theory:

🔷
Hadamard Gate (H Gate)
Definition:
The Hadamard gate transforms a qubit from a computational basis state (like ∣0⟩|0⟩∣0⟩
or ∣1⟩|1⟩∣1⟩) into a superposition state.
Uses of Hadamard Gate
●​ Creating Superposition: Needed in almost every quantum algorithm.
●​ Quantum Interference: Works with other gates to cause constructive or
destructive interference.
●​ Basis Change: Transforms between computational and Hadamard bases.
●​ Entanglement: Used with CNOT to create entangled states like Bell states.

Program:

1.​ Hadamard Gate (H):


from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
from numpy import pi

qc = QuantumCircuit(1,1)
qc.h(0)
qc.measure(0, 0)

print("Circuit diagram:")
print(qc.draw())

Output:
Conclusion:
The Hadamard gate plays a pivotal role in quantum computing by creating superposition states from
classical basis states. Its implementation introduces the fundamental concept of quantum parallelism,
allowing a single qubit to exist in a combination of |0⟩ and |1⟩ states simultaneously.
Experiment No 6

Aim: Implementation of 2 Qubit Gates

Theory:
2-Qubit Gates in Quantum Computing
2-qubit gates operate on two qubits simultaneously. They are used to create quantum
correlations (like entanglement) and to build logic similar to classical controlled gates
(like AND, XOR).

Truth Table:

Control (C) Target (T) Output


0 0 00
0 1 01
1 0 11
1 1 10
Program:

1.​ CNOT Gate (CX):

from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit


from numpy import pi

qc = QuantumCircuit(2, 2)
qc.cx(0, 1)
qc.measure([0, 1], [0, 1])

print("Circuit diagram:")
print(qc.draw())

Output:
Program:

1.​ SWAP Gate (SWAP):

from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit


from numpy import pi

qc = QuantumCircuit(2, 2)
qc.swap(0, 1)
qc.measure([0, 1], [0, 1])

print("Circuit diagram:")
print(qc.draw())

Output:
Conclusion: The implementation of 2-qubit gates is fundamental to achieving universal quantum
computation. These gates, such as the CNOT, CZ, and SWAP, enable entanglement between qubits—an
essential feature that distinguishes quantum computing from classical systems. Through this exploration,
we have seen how 2-qubit gates can be constructed, decomposed, and simulated within various platforms,
including Qiskit.

Experiment No 7

Aim: Implementation of 3 Qubit Gates

Theory:

3-Qubit Gates in Quantum Computing


3-qubit gates operate on three qubits at once and allow for more complex control logic,
including multi-qubit controlled operations. These are essential for universal quantum
computation and reversible logic.
Truth Table:
Input (q0, q1, q2) Output
000 000
001 001
010 010
011 011
100 100
101 101
110 111


111 110

✅ Used in Grover’s algorithm, quantum error correction, and quantum arithmetic


Reversible logic gate, equivalent to a classical AND-controlled-NOT​

🔹 2. Fredkin Gate (CSWAP)


Swaps two target qubits if control qubit is |1⟩.
Action:
Control Target 1 Target 2 Output
0 a b a, b
1 a b b, a
Matrix size: 8×88 \times 88×8

🔹 3. General Controlled-Controlled-U Gates (CCU)


A generalization of Toffoli.
●​

🧠 Summary Table
If both control qubits are ∣1⟩|1⟩∣1⟩, apply a single-qubit gate UUU to the target.
●​

Gate Description Operation


Toffoli (CCX) Flip target if 2 controls = ( 1⟩)
Fredkin (CSWAP) Swap 2 targets if control = ( 1⟩)
CCU Apply any U if 2 controls = ( 1⟩)
Top of Form
Bottom of Form

Program:

2.​ TOFOLLI Gate (CCX):


from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
from numpy import pi

qc = QuantumCircuit(3, 3)
qc.ccx(0, 1, 2)
qc.measure([0, 1, 2], [0, 1, 2])

print("Circuit diagram:")
print(qc.draw())

Output:
Conclusion: The implementation of 3-qubit gates marks a significant step toward the realization of
complex quantum operations and algorithms. Gates such as the Toffoli (CCX) and Fredkin (CSWAP) are
essential for multi-qubit control logic, enabling advanced quantum error correction, decision-making
circuits, and reversible computation. In this study, we demonstrated how these gates can be constructed
using basic 1- and 2-qubit gates, and implemented them using quantum simulation tools like Qiskit.
Experiment No 8

Aim: Implementation of Circuit Formation-1


Theory:

What is a Quantum Circuit?


A quantum circuit is a sequence of quantum gates applied to a set of qubits, with
measurements at the end to extract classical outcomes.
●​ Start with qubits in a known state (usually ∣0⟩|0\rangle∣0⟩)
●​ Apply gates (H, X, CNOT, etc.) to manipulate those qubits
●​ Measure the result in the computational basis

🔹 Basic Components of a Quantum Circuit


1. Qubits
●​ Represented as wires in a circuit
●​ Initial state: ∣0⟩|0\rangle∣0⟩
2. Quantum Gates
●​ Operations that manipulate qubit states
●​ Examples:
o​ H (Hadamard) – Creates superposition
o​ X (NOT) – Flips a qubit
o​ CNOT – Entangles qubits
3. Measurement
●​ Collapses quantum state to classical bit (0 or 1)
●​ Represented with a meter symbol in circuits

🔹 Example: 1-Qubit Superposition Circuit


|0⟩ ───H───●────M

classical──┘
●​ Apply Hadamard: creates ∣+⟩=12(∣0⟩+∣1⟩)|+\rangle = \frac{1}{\sqrt{2}}(|0⟩ +
|1⟩)∣+⟩=2​1​(∣0⟩+∣1⟩)
●​ Measure the result: you'll get 0 or 1 with 50% probability each

🔹 Example: 2-Qubit Bell State Circuit


This circuit creates entanglement:
|0⟩ ──H──■─────

|0⟩ ────X─────

Measurement
Program:

1.​ Hadamard Gate on CNOT Gate (CX):

from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit


from numpy import pi

qc = QuantumCircuit(2, 2)
qc.h(0)
qc.cx(0,1)

qc.measure([0, 1], [0,1])

print("Circuit diagram:")
print(qc.draw())

Output:
2.​ CNOT Gate on Hadamard Gate (CX):

from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit


from numpy import pi

qc = QuantumCircuit(2, 2)

qc.cx(0,1)
qc.h(0)

qc.measure([0, 1], [0,1])

print("Circuit diagram:")
print(qc.draw())

Output:
Conclusion:
Circuit formation is a core aspect of quantum computing, enabling the structured implementation of
quantum operations to solve computational problems. By combining quantum gates in specific sequences,
we can manipulate qubit states, create entanglement, and execute complex algorithms. Understanding how
to construct and visualize quantum circuits—from basic single-qubit gates to multi-qubit interactions—is
essential for designing efficient and accurate quantum solutions.
Experiment No 9:

Aim: Implementation of Circuit Formation-2

Program:

1.​ 2 Pauli-X gates on CCX Gate :

from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit


from numpy import pi

qc = QuantumCircuit(3, 3)

qc.x(0)
qc.x(1)
qc.ccx(0, 1, 2)

qc.measure([0, 1, 2], [0, 1, 2])

print("Circuit diagram:")
print(qc.draw())

Output:
Conclusion:
Circuit formation is a core aspect of quantum computing, enabling the structured implementation of
quantum operations to solve computational problems. By combining quantum gates in specific sequences,
we can manipulate qubit states, create entanglement, and execute complex algorithms. Understanding how
to construct and visualize quantum circuits—from basic single-qubit gates to multi-qubit interactions—is
essential for designing efficient and accurate quantum solutions.

You might also like