Computer Laboratory II
Computer Laboratory II
Lab Manual
Computer Laboratory II
(417526)
Quantum Artificial
Intelligence
BE-SEM-I
INSTRUCTIONS TO STUDENTS
Student must sign in the log book provided when attending the lab session without fail.
Programs for the given problem statements specified in the lab manual should be logically correct with
desired output.
Write program and output after executing the code or attach printout of program and output to the file as a
part oi submission.
Do check your lab assignment on the specified submission date given by subject teacher.
SNJB’s Late Sau. KBJ College of Engineering
Chandwad
Experiment List
Subject: Computer Laboratory II (417526) Class: BE (2023-24)
Course Structure
Savitribai Phule Pune University
Fourth Year of Artificial Intelligence and Data Science (2020 Course)
417526: Computer Laboratory II: Quantum AI
Teaching Scheme: Credit Examination Scheme and Marks
PR: 04 Hours/Week 02 Term Work (TW): 50 Marks
Practical (PR): 25 Marks
Prerequisites Courses: Software Laboratory I (317523)
Companion Course: Elective III: Quantum AI (417523(A))
Course Objectives:
● To develop real-world problem-solving ability
● To enable the student to apply AI techniques in applications that involve perception,
reasoning, and planning
● To work in a team to build industry-compliant Quantum AI applications
Course Outcomes:
On completion of the course, learner will be able to–
CO1: Evaluate and apply core knowledge of Quantum AI to various real-world problems.
CO2: Illustrate and demonstrate Quantum AI tools for different dynamic applications.
Guidelines for Instructor's Manual
Lab Assignments: Following is a list of suggested laboratory assignments for reference. Laboratory
Instructors may design a suitable set of assignments for their respective courses at their level. Beyond
curriculum assignments, the mini-project is also included as a part of laboratory work. The Inclusion
of a few optional assignments that are intricate and/or beyond the scope of the curriculum will surely
be a valuable addition for the students and it will satisfy the intellectuals within the group of learners
and will add to the perspective of the learners. For each laboratory assignment, it is essential for
students to draw/write/generate flowcharts, algorithms, test cases, mathematical models, Test data
sets, and comparative/complexity analysis (as applicable).
Guidelines for Student's Laboratory Journal
Program codes with sample output of all performed assignments are to be submitted as a softcopy.
The use of DVDs or similar media containing student programs maintained by the Laboratory In-
charge is highly encouraged. For reference one or two journals may be maintained with program
prints in the Laboratory. As a conscious effort and little contribution towards Green IT and
environment awareness, attaching printed papers as part of write-ups and program listing to journals
may be avoided. Submission of journal/ term work in the form of softcopy is desirable and
appreciated.
Guidelines for Laboratory/Term Work Assessment
Term work is a continuous assessment that evaluates a student's progress throughout the semester.
Term work assessment criteria specify the standards that must be met and the evidence that will be
gathered to demonstrate the achievement of course outcomes. Categorical assessment criteria for the
term work should establish unambiguous standards of achievement for each course outcome. They
should describe what the learner is expected to perform in the laboratories or on the fields to show
that the course outcomes have been achieved. It is recommended to conduct an internal monthly
practical examination as part of continuous assessment.
Guidelines for Practical Examination
Problem statements must be decided jointly by the internal examiner and external examiner for
Elective III and Elective IV courses. Student has to perform only one practical assignment during
external evaluation either for Elective III and Elective IV courses. During practical assessment,
maximum weightage should be given to satisfactory implementation of the problem statement.
Relevant questions may be asked at the time of evaluation to test the student’s understanding of the
fundamentals, effective and efficient implementation. Adhere to these principles will consummate
our team efforts to the promising start of student's academics.
Guidelines for Laboratory Conduction
Following is a list of suggested laboratory assignments for reference. Laboratory Instructors may
design a suitable set of assignments for respective courses at their level. Beyond curriculum
assignments and mini-project may be included as a part of laboratory work. The instructor may set
multiple sets of assignments and distribute them among batches of students. It is appreciated if the
assignments are based on real-world problems/applications. The Inclusion of a few optional
assignments that are intricate and/or beyond the scope of the curriculum will surely be a value
addition for the students and it will satisfy the intellectuals within the group of learners and will add
to the perspective of the learners. For each laboratory assignment, it is essential for students to
draw/write/generate flowcharts, algorithms, test cases, mathematical models, Test data sets, and
comparative/complexity analysis (as applicable). Batch size for practical and tutorials may be as per
guidelines of authority.
Instructions:
1. Practical can be performed on suitable development platform.
2. Perform any 5 experiments.
Virtual Laboratory
1. https://learn.qiskit.org/course/quantum-hardware/introduction-to-quantum-error-
correction-via-the-repetition-code
2. https://quantumcomputinguk.org/tutorials/16-qubit-random-number-generator
3. https://quantumcomputinguk.org/tutorials/quantum-fourier-transform-in-qiskit
4. https://www.sciencedaily.com/releases/2021/02/210212094105.htm
5. https://www.medrxiv.org/content/10.1101/2020.11.07.20227306v1.full
List of Assignments
1. Implementations of 16 Qubit Random Number Generator
2. Tackle Noise with Error Correction
3. Implement Tarrataca’s quantum production system with the 3-puzzle problem
4. Implement Quantum Teleportation algorithm in Python
5. The Randomized Benchmarking Protocol
6. Implementing a 5 qubit Quantum Fourier Transform
Learning Resources
Reference Books:
CO2 2 2 1 - 3 2 1 1 3 1 2 3
SNJB’s Late Sau. K. B. Jain College of Engineering, Chandwad
DEPARTMENT OF ARTIFICIAL INTELLIGENCE AND DATA SCIENCE
COURSE OBJECTIVES:
COURSE OUTCOMES:
CO1: Evaluate and apply core knowledge of Quantum AI to various real-world problems.
CO2: Illustrate and demonstrate Quantum AI tools for different dynamic applications.
SNJB’s Late Sau. K. B. Jain College of Engineering, Chandwad.
Department of Artificial Intelligence and Data Science
Subject: Computer Laboratory II: Quantum AI (417526)
5
1 Answers (25%)
Viva (25%) 5
3
20
5 Total
Total
Prof. P. B. Koli
(Subject Teacher)
EXPERIMENT NO. 1 (Group A)
Aim: This practical manual aims to guide users in creating a 16-qubit random number
generator using quantum computing techniques for scientific, cryptographic, and practical
applications.
Outcome: Upon completing this practical, users will be able to implement a functional 16-
qubit quantum random number generator and understand its applications.
Theory:
A random number generator (RNG) is a fundamental tool in various scientific,
cryptographic, and practical applications. Quantum computing offers a unique approach to
generating random numbers using the principles of quantum mechanics. In this section,
we will explore how a 16-qubit random number generator works and what its outputs
mean.
Quantum bits, or qubits, are the fundamental building blocks of quantum computing.
Unlike classical bits (0 or 1), qubits can exist in superpositions of states, representing both
0 and 1 simultaneously.
A 16-qubit random number generator utilizes 16 qubits, allowing for an exponentially
large state space and generating highly unpredictable results.
To create a random number generator, we design a quantum circuit using quantum gates.
Quantum gates manipulate the state of qubits to perform operations.
The circuit for random number generation involves applying a series of quantum gates to
the initial qubit states to create a complex quantum superposition.
Quantum Superposition:
In quantum mechanics, qubits can exist in a superposition of states until measured. This
means that before measurement, each qubit is in a combination of 0 and 1.
The complex quantum superposition created by the circuit ensures that the outcome of a
measurement is truly random and unpredictable.
Measurement:
To obtain a random number, the quantum circuit is measured, collapsing the qubits'
superposition into a definite 0 or 1 for each qubit.
Repeating this measurement process multiple times generates a sequence of 16 binary
values, forming the random number.
Quantum Randomness:
Applications:
Conclusion: -
Questions:
Q1. How do qubits in quantum computing differ from classical bits, and why is this
difference essential for random number generation?
Q2. What role does quantum superposition play in ensuring the randomness of
quantum measurements in a 16-qubit random number generator?
┌───┐┌─┐
q_0: ┤ H ├ ┤ M├ ─────────────────────────────────────────────
├ ───┤ └╥┘┌─┐
q_1: ┤ H ├ ─╫─┤ M├ ──────────────────────────────────────────
├ ───┤ ║ └╥┘┌─┐
q_2: ┤ H ├ ─╫──╫─┤ M├ ───────────────────────────────────────
├ ───┤ ║ ║ └╥┘┌─┐
q_3: ┤ H ├ ─╫──╫──╫─┤ M├ ────────────────────────────────────
├ ───┤ ║ ║ ║ └╥┘┌─┐
q_4: ┤ H ├ ─╫──╫──╫──╫─┤ M├ ─────────────────────────────────
├ ───┤ ║ ║ ║ ║ └╥┘┌─┐
q_5: ┤ H ├ ─╫──╫──╫──╫──╫─┤ M├ ──────────────────────────────
├ ───┤ ║ ║ ║ ║ ║ └╥┘┌─┐
q_6: ┤ H ├ ─╫──╫──╫──╫──╫──╫─┤ M├ ───────────────────────────
├ ───┤ ║ ║ ║ ║ ║ ║ └╥┘┌─┐
q_7: ┤ H ├ ─╫──╫──╫──╫──╫──╫──╫─┤ M├ ────────────────────────
├ ───┤ ║ ║ ║ ║ ║ ║ ║ └╥┘┌─┐
q_8: ┤ H ├ ─╫──╫──╫──╫──╫──╫──╫──╫─┤ M├ ─────────────────────
├ ───┤ ║ ║ ║ ║ ║ ║ ║ ║ └╥┘┌─┐
q_9: ┤ H ├ ─╫──╫──╫──╫──╫──╫──╫──╫──╫─┤ M├ ──────────────────
├ ───┤ ║ ║ ║ ║ ║ ║ ║ ║ ║ └╥┘┌─┐
q_10: ┤ H ├ ─╫──╫──╫──╫──╫──╫──╫──╫──╫──╫─┤ M├ ───────────────
├ ───┤ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ └╥┘┌─┐
q_11: ┤ H ├ ─╫──╫──╫──╫──╫──╫──╫──╫──╫──╫──╫─┤ M├ ────────────
├ ───┤ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ └╥┘┌─┐
q_12: ┤ H ├ ─╫──╫──╫──╫──╫──╫──╫──╫──╫──╫──╫──╫─┤ M├ ─────────
├ ───┤ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ └╥┘┌─┐
q_13: ┤ H ├ ─╫──╫──╫──╫──╫──╫──╫──╫──╫──╫──╫──╫──╫─┤ M├ ──────
├ ───┤ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ └╥┘┌─┐
q_14: ┤ H ├ ─╫──╫──╫──╫──╫──╫──╫──╫──╫──╫──╫──╫──╫──╫─┤ M├ ───
├ ───┤ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ └╥┘┌─┐
q_15: ┤ H ├ ─╫──╫──╫──╫──╫──╫──╫──╫──╫──╫──╫──╫──╫──╫──╫─┤ M├
└───┘ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ └╥┘
c: 16/══════╩══╩══╩══╩══╩══╩══╩══╩══╩══╩══╩══╩══╩══╩══╩══╩═
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Random number (decimal): 27678
Random number (binary): 0110110000011110
SNJB’s Late Sau. K. B. Jain College of Engineering,
Chandwad.
Department of Artificial Intelligence and Data Science
Subject: Computer Laboratory II (417526)
Experiment No. 2 (Group A)
1 Answers (25%) 5
Viva (25%)
3 5
5 Total 20
Total
Prof.P.B.Koli
(SubjectTeacher)
EXPERIMENT NO. 2 (Group A)
Outcome: At end of this experiment, student will be able to Tackle Noise with Error
Correction
Theory:
Quantum error correction is theorised as essential to achieve fault tolerant quantum
computing that can reduce the effects of noise on stored quantum information, faulty quantum
gates, faulty quantum preparation, and faulty measurements. This would allow algorithms of
greater circuit depth.
Noise is a major challenge in quantum computing, as it can cause errors in quantum
computations. Quantum error correction (QEC) is a technique that can be used to tackle noise
and improve the reliability of quantum computers.
QEC works by encoding a single logical quantum bit (qubit) into multiple physical qubits. This
redundancy allows QEC to detect and correct errors that occur on the physical qubits.
There are a number of different QEC codes, each with its own strengths and weaknesses. Some
QEC codes are more efficient, while others are more robust to noise.
QEC is still under development, but it has already been demonstrated in small-scale experiments.
As QEC codes improve and become more efficient, they will be essential for building large-scale
quantum computers.
Here is an example of how QEC can be used to tackle noise in a quantum communication
system:
The sender encodes a single logical qubit into multiple physical qubits using a QEC code.
The sender transmits the physical qubits to the receiver.
The receiver uses the QEC code to detect and correct any errors that occurred during
transmission.
The receiver decodes the physical qubits to recover the logical qubit.
If a small number of errors occur during transmission, the QEC code will be able to correct them
and the receiver will be able to recover the logical qubit accurately. However, if too many errors
occur, the QEC code will not be able to correct them and the receiver will not be able to recover
the logical qubit accurately.
QEC can also be used to tackle noise in quantum computers. For example, QEC can be used to
protect the qubits in a quantum computer from noise caused by faulty quantum gates or
environmental interactions.
QEC is a powerful tool for tackling noise in quantum computing and communication. As QEC
codes improve and become more efficient, they will play an essential role in building large-scale
quantum computers and enabling reliable quantum communication.
Conclusion: -
Questions:
Q1. How can we adapt error correction codes to different types of noise?How can we
design error correction codes that are scalable to large numbers of qubits?
Q2. How can we implement error correction in a way that minimizes overhead?
Q3. How can we combine error correction with other techniques, such as quantum
feedback control, to improve the performance of quantum devices?
PROGRAM:
!pip install qiskit-ignis
OUTPUT:
SNJB’s Late Sau. K. B. Jain College of Engineering, Chandwad.
Department of Artificial Intelligence and Data Science
Subject: Computer Laboratory (417526)
1 Answers (25%) 5
3 Viva (25%) 5
5 Total 20
Total
Prof. P. B. koli
(Subject Teacher)
EXPERIMENT NO. 3 (Group A)
Aim: Implement Tarrataca’s quantum production system with the 3-puzzle problem
Outcome: At end of this experiment, student will be able to Write a Python Program
using Tarrataca’s quantum production system with the 3-puzzle problem.
Hardware Requirement:
Theory:
To implement Tarrataca's quantum production system for the 3-puzzle problem, we can
use the following steps:
Encode the problem state as a quantum state. We can use a qubit to represent each tile,
and the state of the qubit will represent the position of the tile. For example, if a tile is in
the leftmost position, we can represent it with the qubit state |0⟩ , and if it is in the
rightmost position, we can represent it with the qubit state |1⟩ .
Construct a quantum circuit that represents the problem space. The quantum circuit
will have a qubit for each tile, and the gates will represent the possible moves that can
be made. For example, we can use a CNOT gate to represent a move that exchanges the
positions of two tiles.
Apply a sequence of quantum operations to the circuit to search for the optimal
solution. We can use a variety of quantum algorithms to search for the optimal solution,
such as Grover's algorithm or amplitude amplification.
Measure the qubits to obtain the optimal solution. Once we have found the optimal
solution, we can measure the qubits to obtain the positions of the tiles.
Here is an example of a quantum circuit that can be used to solve the 3-puzzle problem:
q0: ---
q1: ---
q2: ---
CNOT q0 q1
CNOT q1 q2
H q0
H q1
H q2
Grover's algorithm
M q0
M q1
M q2
This circuit starts with the three qubits in the state |000⟩ . The first two CNOT gates
exchange the positions of the first two qubits and the second two qubits, respectively.
The three Hadamard gates put the qubits into a superposition of states.
Grover's algorithm is then used to search for the optimal solution. Grover's algorithm is
a quantum algorithm that can amplify the probability of finding a solution to a search
problem.
Finally, the three qubits are measured to obtain the optimal solution.
Conclusion: -
Questions:
1. How does Tarrataca's quantum production system encode the problem state as a quantum
state?
2. How does Tarrataca's quantum production system construct a quantum circuit that
represents the problem space?
3. What are some of the quantum algorithms that can be used to search for the optimal
solution to the 3-puzzle problem using Tarrataca's quantum production system?
4. How can we measure the qubits at the end of the quantum circuit to obtain the optimal
solution to the 3-puzzle problem?
5. What are some of the advantages and disadvantages of using Tarrataca's quantum
production system to solve the 3-puzzle problem?
Program:
for i in range(3):
for j in range(3):
if state[i][j] is not None and state[i][j] != x[i][j]:
cost += 1
return cost
result = qaoa.compute_minimum_eigenvalue()
solution = result.x
return solution
plt.bar(outcomes, counts_list)
plt.xlabel('Outcome')
plt.ylabel('Counts')
plt.title('Coin Flip Results')
plt.show()
Output :
SNJB’s Late Sau. K. B. Jain College of Engineering, Chandwad.
Department of Artificial Intelligence and Data Science
Subject: Computer Laboratory II (417526)
Experiment No. 4
1 Answers (25%) 5
3 5
Viva (25%)
5 Total 20
Total
Prof. P. B. Koli
(Subject Teacher)
⮚ Outcome: At end of this experiment, student will be able to Write a Python program
to implement Quantum Teleportation algorithm in Python
⮚ Hardware Requirement:
⮚ Theory:
Introduction:
Quantum teleportation is a fundamental concept in quantum information theory
that allows for the transfer of quantum states from one location to another using
two entangled particles and classical communication. This algorithm plays a crucial
role in quantum computing and quantum communication protocols. In this
theoretical document, we will outline the steps to implement the quantum
teleportation algorithm in Python.
Quantum teleportation consists of three main participants: Alice, Bob, and Charlie.
Alice wants to send an arbitrary quantum state (qubit) to Bob. To achieve this, they
need to share an entangled pair of qubits and perform a series of quantum
operations and classical communication. The high-level steps are as follows:
Alice and Bob need to create an entangled pair of qubits, typically using a Bell state,
such as the Bell state |Φ+⟩ = (|00⟩ + |11⟩ ) / √2. This pair is shared between Alice
and Bob.
Alice has the quantum state she wants to teleport, denoted as |ψ⟩ . She combines her
state with one of the qubits from the entangled pair using a controlled-Not (CNOT)
gate and a Hadamard gate.
Alice performs measurements on her two qubits (the one from the entangled pair
and the one representing |ψ⟩ ) in the Bell basis, which consists of the states |Φ+⟩ ,
|Φ-⟩ , |Ψ+⟩ , and |Ψ-⟩ .
5. Bob's operations:
Based on the classical information received from Alice, Bob applies a series of
quantum gates to his qubit to transform it into the desired quantum state |ψ⟩ .
6. Python Implementation:
Now, let's discuss how to implement this algorithm in Python. We'll use a quantum
computing library like Qiskit, which provides the necessary tools for quantum
programming.
Initialize a quantum circuit with three qubits, one for Alice, one for Bob, and one for
the entangled pair.
Implement the steps outlined above using quantum gates and measurements. This
involves applying CNOT and Hadamard gates, measuring Alice's qubits in the Bell
basis, and performing Bob's operations based on the measurement results.
Use Qiskit's simulator to simulate the quantum teleportation process and visualize
the final state of Bob's qubit.
Program:
Department of AI & DS Engineering
# Importing standard Qiskit libraries
service = QiskitRuntimeService(channel="ibm_quantum")
# result = Sampler("ibmq_qasm_simulator").run(circuits).result()
circuit.barrier()
circuit.h(q[1])
circuit.cx(q[1], q[2])
# Teleportation process
circuit.cx(q[0], q[1])
circuit.h(q[0])
circuit.barrier()
circuit.measure(q[0], c0[0])
circuit.measure(q[1], c1[0])
circuit.x(q[2]).c_if(c1, 1)
circuit.z(q[2]).c_if(c0, 1)
circuit.measure(q[2], c2[0])
print(circuit)
circuit_drawer(circuit, output='mpl')
simulator = Aer.get_backend('qasm_simulator')
result = job.result()
teleported_state = result.get_counts(circuit)
import numpy as np
pi = np.pi
# provider = IBMQ.get_provider(hub='ibm-q')
backend = provider.get_backend('ibmq_qasm_simulator')
q = QuantumRegister(5,'q')
c = ClassicalRegister(5,'c')
circuit = QuantumCircuit(q,c)
circuit.x(q[4])
circuit.x(q[2])
circuit.x(q[0])
circuit.measure(q,c)
circuit.draw(output='mpl', filename='qft1.png')
print(circuit)
counts = job.result().get_counts()
print("-------------")
print(counts)
import numpy as np
pi = np.pi
provider = IBMQ.get_provider(hub='ibm-q')
backend = provider.get_backend('ibmq_qasm_simulator')
q = QuantumRegister(5,'q')
c = ClassicalRegister(5,'c')
circuit = QuantumCircuit(q,c)
circuit.x(q[4])
circuit.x(q[2])
circuit.measure(q,c)
circuit.draw(output='mpl', filename='qft1.png')
print(circuit)
job_monitor(job)
counts = job.result().get_counts()
print("-------------")
print(counts)
input()
q = QuantumRegister(5,'q')
c = ClassicalRegister(5,'c')
circuit = QuantumCircuit(q,c)
circuit.x(q[4])
circuit.x(q[2])
circuit.x(q[0])
circuit.measure(q,c)
circuit.draw(output='mpl',filename='qft2.png')
print(circuit)
job_monitor(job)
counts = job.result().get_counts()
print("------------------------------ ")
print(counts)
input()
Q1. What are the fundamental principles behind quantum teleportation, and why is it a
crucial concept in quantum information theory?
Q2. In the context of quantum teleportation, what is the significance of the Bell state,
and how does it play a pivotal role in the algorithm's implementation?
Q3. Can you explain the role of classical communication in quantum teleportation and
why it is essential for the algorithm's success?
Experiment No. 5
5
1 Answers (25%)
Viva (25%) 5
3
Total 20
5
Total
Prof. P. B. Koli
(Subject Teacher)
Hardware Requirement:
Theory:
In quantum computing, gates are used to perform operations on qubits. These gates
are subject to errors due to various sources, such as decoherence, control
imperfections, and environmental noise.
The primary goal of RB is to provide a reliable way to estimate the average error rate
of a set of quantum gates, often referred to as the "Clifford gates." These gates form a
basis set that can be used to create any quantum state.
3. Clifford Group:
The Clifford group is a specific set of quantum gates known for their stability and
error-correcting properties. They include gates like the Hadamard gate, CNOT gate,
and phase gate.
5. Expected Outcome:
In the absence of errors, applying a random sequence of Clifford gates and then its
inverse should return the qubits to their initial state. However, errors cause
deviations from this ideal behavior.
As RB sequences get longer, the quantum coherence of the qubits decays due to
errors. RB quantifies this decay by measuring how the fidelity (similarity to the ideal
state) of the output state decreases as a function of sequence length.
7. Error Rate Estimation:
8. Robustness:
9. Scalability:
RB can be scaled to assess the error rates of large sets of gates and can be used to
compare the performance of different quantum processors.
import numpy as np
from qiskit import QuantumCircuit, transpile, Aer, execute
# Example usage
num_qubits = 2
depths = [1, 2, 3, 4]
num_sequences = 100
shots = 1024
results = randomized_benchmarking(num_qubits, depths, num_sequences,
shots)
print(results)
Output :
Questions:
Q1. How Does Randomized Benchmarking Differ from Other Quantum Error
Characterization Techniques?
Q2 What Mathematical Models are Used to Analyze RB Data and Extract Error Rates?
Experiment No. 6
1 Answers (25%) 5
Viva (25%)
3 5
4 5
5 Total 20
Total
Prof. P. B. Koli
(Subject Teacher)
EXPERIMENT NO. 6
⮚ Outcome: At end of this experiment, student will be able to Write a Python program
to implement Quantum Teleportation algorithm in Python
⮚ Hardware Requirement:
⮚ Theory:
Introduction:
The Quantum Fourier Transform is the quantum analogue of the classical discrete
Fourier transform (DFT). It transforms an input quantum state |x⟩ into an output
state |y⟩ , where each basis state |y⟩ corresponds to a frequency component of the
input state |x⟩ . The mathematical representation of the QFT is as follows:
Here, N represents the number of basis states (in our case, 2^5 = 32), and |k⟩ denotes
the basis states in the computational basis.
To implement the 5-qubit Quantum Fourier Transform, we will discuss the fundamental
steps involved:
1. State Preparation: Begin by initializing an initial quantum state |x⟩ , which is typically
a superposition of basis states.
2. Hadamard Transform: Apply a Hadamard gate (H) to each qubit in the superposition,
creating entanglement and preparing the input state for the Fourier transform.
3. Controlled Phase Shifts: Implement controlled-phase gates (CROT gates) to introduce
phase shifts, representing the frequency components of the QFT.
4. Bit Reversal: Perform a bit reversal operation to reorder the qubits in the correct
sequence, aligning them with the output state.
Step-by-Step Explanation
a. State Preparation:
The process begins with initializing the input state |x⟩ , which is often a superposition of
basis states. For example, to prepare the state |01101⟩ , apply X (bit-flip) gates to the
corresponding qubits.
b. Hadamard Transform:
Apply a Hadamard gate (H) to each qubit in the prepared state. The Hadamard gate
creates a superposition of basis states, which is essential for the subsequent steps of the
algorithm.
The core of the QFT involves applying controlled-phase gates (CROT gates). Each CROT
gate corresponds to a specific frequency component in the QFT. The controlled-phase
gate CROT_k multiplies the phase of |k⟩ by 2π/N when the control qubit is in state |1⟩ .
Apply these gates for k = 1 to 5 (as we are implementing a 5-qubit QFT).
d. Bit Reversal:
To ensure that the qubits are ordered correctly in the final state, perform a bit reversal
operation on the qubits. This step is necessary to align the qubits with the output state.
A quantum circuit diagram representing the 5-qubit QFT is provided below for clarity:
Program:
from qiskit import QuantumRegister, ClassicalRegister
import numpy as np
pi = np.pi
provider = IBMQ.get_provider(hub='ibm-q')
backend = provider.get_backend('ibmq_qasm_simulator')
q = QuantumRegister(5,'q')
c = ClassicalRegister(5,'c')
circuit = QuantumCircuit(q,c)
circuit.x(q[4])
circuit.x(q[2])
circuit.x(q[0])
circuit.measure(q,c)
circuit.draw(output='mpl', filename='qft1.png')
print(circuit)
job_monitor(job)
counts = job.result().get_counts()
print("-------------")
print(counts)
input()
q = QuantumRegister(5,'q')
c = ClassicalRegister(5,'c')
circuit = QuantumCircuit(q,c)
circuit.x(q[4])
circuit.x(q[2])
circuit.x(q[0])
circuit.measure(q,c)
circuit.draw(output='mpl',filename='qft2.png')
print(circuit)
job_monitor(job)
counts = job.result().get_counts()
print("------------------------------ ")
print(counts)
input()
Conclusion: -
Implementing a 5-qubit Quantum Fourier Transform is a crucial step in unlocking the
potential of quantum computing. This algorithm serves as a foundational component for
many quantum algorithms with applications in cryptography, optimization, and
quantum simulations. By comprehending the principles and techniques behind the QFT,
researchers and developers can contribute to the advancement of quantum computing
and explore its vast capabilities. The ability to efficiently perform the Quantum Fourier
Transform lays the groundwork for solving complex problems that were previously
infeasible with classical computers. As quantum computing continues to evolve, the QFT
will remain a cornerstone of quantum algorithms and computational techniques.
-------------------------------------------------------------------------------------------------------------------------
Questions:
Q1. Explain the significance of the Quantum Fourier Transform (QFT) in quantum
computing. How does it differ from its classical counterpart, the Discrete Fourier
Transform (DFT)?
Q3. Quantum computers are known to be exponentially faster than classical computers
for certain problems. How does the Quantum Fourier Transform (QFT) exemplify this
advantage, and what are the implications for cryptography and factorization problems?