0% found this document useful (0 votes)
43 views49 pages

Computer Laboratory II

The document is a lab manual for the Computer Laboratory II course focused on Quantum Artificial Intelligence at SNJB’s Late Sau. K. B. Jain College of Engineering. It includes instructions for students, a list of experiments, course objectives, outcomes, and guidelines for laboratory work and assessments. The manual emphasizes practical applications of quantum computing techniques, including a 16-qubit random number generator and various UI/UX design projects.

Uploaded by

sahilofcaiml
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)
43 views49 pages

Computer Laboratory II

The document is a lab manual for the Computer Laboratory II course focused on Quantum Artificial Intelligence at SNJB’s Late Sau. K. B. Jain College of Engineering. It includes instructions for students, a list of experiments, course objectives, outcomes, and guidelines for laboratory work and assessments. The manual emphasizes practical applications of quantum computing techniques, including a 16-qubit random number generator and various UI/UX design projects.

Uploaded by

sahilofcaiml
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/ 49

SNJB’s Late Sau. K. B.

Jain College of Engineering,


Chandwad
Department of AI & DS Engineering
2023-24

Lab Manual

Computer Laboratory II
(417526)
Quantum Artificial
Intelligence
BE-SEM-I

Prepared By: Prof. Prashant. B. koli


SNJB’s Late Sau. K. B. Jain College of Engineering, Chandwad
DEPARTMENT OF ARTIFICIAL INTELLIGENCE AND DATA SCIENCE

INSTRUCTIONS TO STUDENTS

 The student should carry Identity card issued by the college.

 Student must sign in the log book provided when attending the lab session without fail.

 Come to the laboratory in time.

 Foods, drinks are NOT allowed.

 All bags must be kept at the indicated place.

 Read the Manual carefully before coming to the laboratory.

 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

Department of Artificial Intelligence and Data Science

Experiment List
Subject: Computer Laboratory II (417526) Class: BE (2023-24)

Sr. No Name of Experiment


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
Computer Laboratory II: UI /UX Design
7 Design user persona for the users of selected product / system.
8 Design a wireframe for an online learning platform that includes course
listings, video lectures, quizzes, and progress tracking
9 Create wireframes and a prototype for a social fitness app that allows users
to track workouts, connect with friends, and share progress. Design the user
interface for logging exercises, setting goals, and incorporating social features
10 Choose a product and create a mockup of its packaging design. Use a mockup
tool that specializes in packaging design or graphic design. Design the product
packaging, including the layout, colours, logos, and product visuals. Showcase
the packaging design from different angles and perspectives.
11 Use Figma tool to Design a user interface for a recipe finder application,
allowing users to search for recipes based on ingredients, categories, and
dietary restrictions. Include features like recipe details, cooking instructions,
and saving favourites.
12 Use Figma tool for Improving the User Interface of a Fitness Tracking App:
Improve the user interface of an existing fitness tracking app by focusing on
simplicity, clarity, and motivational elements.
13 Form a design team and work on a collaborative design project using Figma.
Assign different design tasks to team members, such as wireframing, visual
design, or prototyping.
14. Develop a high-fidelity interactive prototype using any UI/UX tool.

Course Incharge HoD


SNJB’s Late Sau. K. B. Jain College of Engineering, Chandwad
DEPARTMENT OF ARTIFICIAL INTELLIGENCE AND DATA SCIENCE

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:

1. Nielsen, M. & Chuang I. “Quantum Computation and Quantum Information”, 2002


2. Biamonte, J. et al., “Quantum Machine Learning”, Nature, 2017
3. Rieffel, E. G., & Polak, W. H., “Quantum computing: A gentle introduction”, MIT Press,
2011
4. Kaye, P., Laflamme, R., & Mosca, M., “An introduction to quantum computing”, Rinton
Press, 2007
5. Farhi, E., Goldstone, J., & Gutmann, S., “A quantum approximate optimization algorithm”,
arXiv preprint arXiv:1411.4028, 2014
MOOC Courses:
● https://nptel.ac.in/courses/106106232
● https://www.coursera.org/learn/introduction-to-quantum-information
● https://www.udemy.com/topic/quantum-computing/
The CO-PO Mapping Matrix
CO/
PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12
PO
CO1 3 2 2 1 2 1 - 1 1 1 - 3

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 & Outcomes

COURSE OBJECTIVES:

On completion of the course, learner will be able to—

 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.
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)

Experiment No. 1 (Group A)

Title: Implementations of 16 Qubit Random Number Generator.

Date of Completion: __________________ Date of Submission: __________________

S.N Criteria (ACVT) Possible Obtained


. Marks Marks

5
1 Answers (25%)

Coding Efficiency (25 %) 5


2

Viva (25%) 5
3

Timely Completion (25%)


5
4

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.

Hardware Requirement: Quantum Processing Unit (QPU), Quantum Software Development


Kit (SDK), Computer or Server, Internet Connection, Account and Access

Software Requirement: Quantum Programming Environment, Python, Operating System,


Quantum Simulator, Account on Quantum Computing Platform, API Tokens or Access Keys, Text
Editor or Integrated Development Environment (IDE)

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 (Qubits):

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.

Quantum Circuit Design:

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:

The randomness of quantum measurements is a fundamental property of quantum


mechanics. It arises from the probabilistic nature of measuring qubits in superposition.
Unlike classical random number generators, which may have inherent biases or patterns,
a quantum random number generator is theoretically unbiased and produces truly
random and uncorrelated numbers.

Applications:

Quantum random numbers have applications in cryptography, where secure and


unpredictable random numbers are crucial for encryption and key generation.
They are also used in Monte Carlo simulations, scientific experiments, and games of
chance where fairness and unpredictability are required.

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?

Q3. In what practical applications can the output of a 16

qubit random number generator be utilized, and why is

quantum randomness significant in these contexts?


Program:

# Importing standard Qiskit libraries


from qiskit import QuantumCircuit, transpile
from qiskit.tools.jupyter import *
from qiskit.visualization import *
from ibm_quantum_widgets import *

# qiskit-ibmq-provider has been deprecated.


# Please see the Migration Guides in https://ibm.biz/provider_migration_guide for more detail.
from qiskit_ibm_runtime import QiskitRuntimeService, Sampler, Estimator, Session, Options

# Loading your IBM Quantum account(s)


service = QiskitRuntimeService(channel="ibm_quantum")

# Invoke a primitive. For more details see


https://qiskit.org/documentation/partners/qiskit_ibm_runtime/tutorials.html
# result = Sampler("ibmq_qasm_simulator").run(circuits).result()

#16qubit random number genertor


from qiskit import QuantumCircuit, Aer, execute
from qiskit.visualization import circuit_drawer

# Create a quantum circuit with 16 qubits


circuit = QuantumCircuit(16, 16)

# Apply Hadamard gates to put all qubits in superposition


circuit.h(range(16))

# Measure all qubits


circuit.measure(range(16), range(16))

# Visualize the circuit


print(circuit)
circuit_drawer(circuit, output='mpl')

# Simulate the quantum circuit using the QASM simulator


simulator = Aer.get_backend('qasm_simulator')
job = execute(circuit, simulator, shots=1)
result = job.result()
counts = result.get_counts(circuit)

# Extract the random number from the measurement outcome


random_number = int(list(counts.keys())[0], 2)

# Convert the random number to binary representation


binary_number = bin(random_number)[2:].zfill(16)

print("Random number (decimal):", random_number)


print("Random number (binary):", binary_number)
Output:

┌───┐┌─┐
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)

Title: Tackle Noise with Error Correction

Date of Completion: _____________ Date of Submission: ______________

S.N Criteria (ACVT) Possible Obtained


. Marks Marks

1 Answers (25%) 5

Coding Efficiency (25 %)


2 5

Viva (25%)
3 5

4 Timely Completion (25%) 5

5 Total 20

Total

Prof.P.B.Koli
(SubjectTeacher)
EXPERIMENT NO. 2 (Group A)

Aim: Tackle Noise with Error Correction

Outcome: At end of this experiment, student will be able to Tackle Noise with Error
Correction

Software Requirement: Ubuntu OS, Quskit (Cloud based)

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

from qiskit import QuantumCircuit, assemble, Aer, transpile


from qiskit.visualization import plot_histogram
from qiskit.ignis.mitigation.import CompleteMeasFitter, complete_meas_cal, tensored_meas_cal

# Define the quantum circuit


qc = QuantumCircuit(3, 3)

# Apply gates and operations to the circuit


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

# Transpile the circuit


backend = Aer.get_backend('qasm_)
transpiled_qc = transpile(qc, backend)

# Simulate the noisy circuit


qobj = assemble(transpiled_qc, shots=1000)
job = backend.run(qobj)
result = job.result()
counts = result.get_counts()

# Perform error mitigation


cal_circuits, state_labels = complete_meas_cal(qubit_list=[, 1, 2])
cal_job = backend.run(assemble(cal_
cal_results = cal_job.result()
meas_fitter = CompleteMeasFitter(cal_
mitigated_counts = meas_fitter.filter.apply(

# Print the original counts


print("Original counts:")
print(counts)

# Print the mitigated counts


print("Mitigated counts:")
print(mitigated_counts)

# Plot the histograms of the original and mitigated counts


plot_histogram([counts, mitigated_counts], legend=['Original', 'Mitigated'])

OUTPUT:
SNJB’s Late Sau. K. B. Jain College of Engineering, Chandwad.
Department of Artificial Intelligence and Data Science
Subject: Computer Laboratory (417526)

Experiment No. 3 (Group A)

Title: Implement Tarrataca’s quantum production system with the 3-puzzle

Date of Completion: __________________ Date of Submission: __________________

S.N Criteria (ACVT) Possible Obtained


. Marks Marks

1 Answers (25%) 5

2 Coding Efficiency (25 %) 5

3 Viva (25%) 5

4 Timely Completion (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:

Software Requirement: Quiskit

Theory:

Tarrataca's quantum production system is a quantum algorithm for solving


combinatorial optimization problems. It works by constructing a quantum circuit that
represents the problem space, and then applying a sequence of quantum operations to
the circuit to search for the optimal solution.

The 3-puzzle problem is a combinatorial optimization problem where the goal is to


arrange three tiles in order, given an initial state. Each tile can be moved either left or
right, and the cost of a move is equal to the distance that the tile is moved.

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.

Tarrataca's quantum production system is a powerful algorithm for solving


combinatorial optimization problems. It has the potential to solve problems that are
intractable for classical computers.

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:

from qiskit import Aer, transpile, assemble, QuantumCircuit


from qiskit.aqua import QuantumInstance
from qiskit.aqua.algorithms import QAOA
from qiskit.aqua.components.optimizers import COBYLA

# Define the objective function


def objective_function(x):
cost = 0
state = [[1, 2, 3], [4, 5, 6], [7, 8, None]]

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

# Define the QAOA solver


def solve_3puzzle_qaoa():
backend = Aer.get_backend('qasm_simulator')
optimizer = COBYLA(maxiter=100)
qaoa = QAOA(optimizer=optimizer, p=1,
quantum_instance=QuantumInstance(backend=backend))

# Generate the initial state circuit


initial_state = QuantumCircuit(9)
for i in range(3):
for j in range(3):
initial_state.h(i * 3 + j)
initial_state.barrier()

# Generate the mixer circuit


mixer = QuantumCircuit(9)
mixer.cz(0, 1)
mixer.cz(0, 3)
mixer.cz(1, 2)
mixer.cz(1, 4)
mixer.cz(2, 5)
mixer.cz(3, 4)
mixer.cz(3, 6)
mixer.cz(4, 5)
mixer.cz(4, 7)
mixer.cz(5, 8)
mixer.cz(6, 7)
mixer.cz(7, 8)

# Solve the problem using QAOA


qaoa.initial_state = initial_state
qaoa.mixer = mixer
qaoa.objective_function = objective_function

result = qaoa.compute_minimum_eigenvalue()
solution = result.x

return solution

# Solve the 3-puzzle problem using QAOA


solution = solve_3puzzle_qaoa()

# Print the solution


print("Solution found!")
for i in range(0, 9, 3):
print(solution[i:i + 3])

from qiskit import QuantumCircuit, Aer, execute


from qiskit.visualization import plot_histogram

# Define the initial state


initial_state = [2, 5, 3, 1, 8, 6, 4, 7, None]

# Define the goal state


goal_state = [1, 2, 3, 4, 5, 6, 7, 8, None]

# Define the quantum circuit


qc = QuantumCircuit(18, 18)

# Initialize the circuit with the initial state


for i, tile in enumerate(initial_state):
if tile is not None:
qc.x(i)

# Perform swaps to reach the goal state


for i, tile in enumerate(goal_state):
if tile is not None:
initial_index = initial_state.index(tile)
target_index = goal_state.index(tile)
qc.swap(i, initial_index + 9)
qc.swap(i, target_index + 9)

# Measure the final state


qc.measure(range(9), range(9))

# Simulate the circuit


backend = Aer.get_backend('qasm_simulator')
job = execute(qc, backend, shots=1024)
result = job.result()
counts = result.get_counts(qc)

# Find the most probable state (solution)


max_count = max(counts.values())
solution = [state for state, count in counts.items() if count == max_count][0]

# Print the solution


print("Solution found!")
for i in range(0, 9, 3):
print(solution[i:i + 3])

from qiskit import Aer, execute, QuantumCircuit

# Define the quantum circuit


qc = QuantumCircuit(1, 1)
qc.h(0) # Apply Hadamard gate for superposition
qc.measure(0, 0) # Measure qubit and store result in classical bit

# Use the Aer simulator


simulator = Aer.get_backend('qasm_simulator')

# Set the number of shots (measurements)


num_shots = 1000

# Execute the quantum circuit on the simulator with multiple shots


job = execute(qc, simulator, shots=num_shots)

# Get the result of the measurements


result = job.result()
counts = result.get_counts()

# Print the coin flip results


print("Coin Flip Results:")
for outcome, count in counts.items():
print(f"{outcome}: {count} ({count/num_shots*100:.2f}%)")

from qiskit import Aer, execute, QuantumCircuit

# Define the quantum circuit


qc = QuantumCircuit(1, 1)
qc.h(0) # Apply Hadamard gate for superposition
qc.measure(0, 0) # Measure qubit and store result in classical bit

# Use the Aer simulator


simulator = Aer.get_backend('qasm_simulator')

# Set the number of shots (measurements)


num_shots = 1000

# Execute the quantum circuit on the simulator with multiple shots


job = execute(qc, simulator, shots=num_shots)

# Get the result of the measurements


result = job.result()
counts = result.get_counts()

# Print the coin flip results


print("Coin Flip Results:")
for outcome, count in counts.items():
print(f"{outcome}: {count} ({count/num_shots*100:.2f}%)")

import matplotlib.pyplot as plt


from qiskit import Aer, execute, QuantumCircuit

# Define the quantum circuit


qc = QuantumCircuit(1, 1)
qc.h(0) # Apply Hadamard gate for superposition
qc.measure(0, 0) # Measure qubit and store result in classical bit

# Use the Aer simulator


simulator = Aer.get_backend('qasm_simulator')

# Set the number of shots (measurements)


num_shots = 1000

# Execute the quantum circuit on the simulatr with multiple shots


job = execute(qc, simulator, shots=num_shots)

# Get the result of the measurements


result = job.result()
counts = result.get_counts()

# Plot the coin flip results


outcomes = list(counts.keys())
counts_list = list(counts.values())

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

Title: Implement Quantum Teleportation algorithm in Python.

Date of Completion: __________________ Date of Submission: __________________

S.N. Criteria (ACVT) Possible Obtained


Marks Marks

1 Answers (25%) 5

Coding Efficiency (25 %)


2 5

3 5
Viva (25%)

4 Timely Completion (25%) 5

5 Total 20

Total

Prof. P. B. Koli
(Subject Teacher)

Department of AI & DS Engineering


EXPERIMENT NO. 4

⮚ Aim: Write a Python program to Implement Quantum Teleportation algorithm.

⮚ Outcome: At end of this experiment, student will be able to Write a Python program
to implement Quantum Teleportation algorithm in Python
⮚ Hardware Requirement:

⮚ Software Requirement: IBM Qiskit

⮚ 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 Overview:

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:

1. Create an entangled pair:

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.

2. Prepare the quantum state to be teleported:

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.

Department of AI & DS Engineering


3. Perform measurements:

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 |Ψ-⟩ .

4. Transmit measurement results classically:

Alice communicates the results of her measurements to Bob using classical


communication. These results will help Bob transform his qubit to recreate the
original quantum state |ψ⟩ .

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.

Import the required libraries:

from qiskit import QuantumCircuit, Aer, transpile, assemble, execute

from qiskit.visualization import plot_bloch_multivector

7. Create a quantum circuit:

Initialize a quantum circuit with three qubits, one for Alice, one for Bob, and one for
the entangled pair.

8. Apply gates and measurements:

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.

9. Simulate and visualize results:

Use Qiskit's simulator to simulate the quantum teleportation process and visualize
the final state of Bob's qubit.

10. Execute the circuit:

Compile and run the quantum circuit on a quantum computer or simulator.

Program:
Department of AI & DS Engineering
# Importing standard Qiskit libraries

from qiskit import QuantumCircuit, transpile

from qiskit.tools.jupyter import *

from qiskit.visualization import *

from ibm_quantum_widgets import *

# qiskit-ibmq-provider has been deprecated.

# Please see the Migration Guides in https://ibm.biz/provider_migration_guide for more detail.

from qiskit_ibm_runtime import QiskitRuntimeService, Sampler, Estimator, Session, Options

# Loading your IBM Quantum account(s)

service = QiskitRuntimeService(channel="ibm_quantum")

# Invoke a primitive. For more details see


https://qiskit.org/documentation/partners/qiskit_ibm_runtime/tutorials.html

# result = Sampler("ibmq_qasm_simulator").run(circuits).result()

from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister, execute, Aer

from qiskit.visualization import circuit_drawer

# Create the quantum circuit with 3 qubits and 3 classical bits

q = QuantumRegister(3, 'q') # Quantum register

c0 = ClassicalRegister(1, 'c0') # Classical register for Alice's qubit

c1 = ClassicalRegister(1, 'c1') # Classical register for Bob's qubit

c2 = ClassicalRegister(1, 'c2') # Classical register for the result

circuit = QuantumCircuit(q, c0, c1, c2)

# Prepare the initial state to be teleported

circuit.initialize([0, 1], q[0]) # Apply X gate to put in state |1>

circuit.barrier()

# Create an entanglement between Alice's and Bob's qubits

circuit.h(q[1])

circuit.cx(q[1], q[2])

Department of AI & DS Engineering


circuit.barrier()

# Teleportation process

circuit.cx(q[0], q[1])

circuit.h(q[0])

circuit.barrier()

# Measure Alice's qubits and send the measurement results to Bob

circuit.measure(q[0], c0[0])

circuit.measure(q[1], c1[0])

# Apply corrective operations on Bob's qubit based on the measurement results

circuit.x(q[2]).c_if(c1, 1)

circuit.z(q[2]).c_if(c0, 1)

# Measure the teleported qubit

circuit.measure(q[2], c2[0])

# Visualize the circuit

print(circuit)

circuit_drawer(circuit, output='mpl')

# Simulate the circuit using the QASM simulator

simulator = Aer.get_backend('qasm_simulator')

job = execute(circuit, simulator, shots=1)

result = job.result()

teleported_state = result.get_counts(circuit)

# Print the teleported state

print("Teleported state:", teleported_state)

Department of AI & DS Engineering


from qiskit import QuantumRegister, ClassicalRegister

from qiskit import QuantumCircuit, execute, IBMQ

from qiskit.tools.monitor import job_monitor

from qiskit.circuit.library import QFT

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.append(QFT(num_qubits=5, approximation_degree=0, do_swaps=True, inverse=False,


insert_barriers=False), q)

circuit.measure(q,c)

circuit.draw(output='mpl', filename='qft1.png')

print(circuit)

job = execute(circuit, backend, shots=1000)

Department of AI & DS Engineering


job_monitor(job)

counts = job.result().get_counts()

print("\n QFT Output")

print("-------------")

print(counts)

from qiskit import QuantumRegister, ClassicalRegister

from qiskit import QuantumCircuit, execute,IBMQ

from qiskit.tools.monitor import job_monitor

from qiskit.circuit.library import QFT

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])

Department of AI & DS Engineering


circuit.x(q[0])

circuit.append(QFT(num_qubits=5, approximation_degree=0, do_swaps=True, inverse=False,


insert_barriers=False, name='qft'), q)

circuit.measure(q,c)

circuit.draw(output='mpl', filename='qft1.png')

print(circuit)

job = execute(circuit, backend, shots=1000)

job_monitor(job)

counts = job.result().get_counts()

print("\n QFT Output")

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.append(QFT(num_qubits=5, approximation_degree=0, do_swaps=True, inverse=False,


insert_barriers=False, name='qft'), q)

circuit.measure(q,c)

circuit.draw(output='mpl',filename='qft2.png')

print(circuit)

job = execute(circuit, backend, shots=1000)

job_monitor(job)

counts = job.result().get_counts()

print("\n QFT with inverse QFT Output")

print("------------------------------ ")

print(counts)

input()

Department of AI & DS Engineering


Conclusion: -
Quantum teleportation is a fascinating concept that demonstrates the principles of
quantum entanglement and the transfer of quantum information. Implementing the
algorithm in Python using a quantum computing library like Qiskit allows for practical
experimentation and exploration of quantum teleportation. The key is to follow the steps
outlined in the algorithm while taking advantage of the powerful tools provided by the
library to work with quantum circuits and simulate quantum processes.

Department of AI & DS Engineering


Questions:

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?

Department of AI & DS Engineering


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)

Experiment No. 5

Title: The Randomized Benchmarking Protocol

Date of Completion: __________________ Date of Submission: __________________

S.N Criteria (ACVT) Possible Obtained


. Marks Marks

5
1 Answers (25%)

Coding Efficiency (25 %) 5


2

Viva (25%) 5
3

Timely Completion (25%)


5
4

Total 20
5

Total

Prof. P. B. Koli
(Subject Teacher)

Department of AI & DS Engineering 1


EXPERIMENT NO. 5 (Group A)

Aim: The Randomized Benchmarking Protocol

Outcome: At end of this experiment, student will be able The Randomized


Benchmarking Protocol.

Hardware Requirement:

Software Requirement: Ubuntu OS,Python Editor(Pyhton Interpreter)

Theory:

The Randomized Benchmarking:

The term "Randomized Benchmarking" (RB) refers to a specific


experimental technique in quantum computing used to assess the performance and
error rates of quantum gates or operations. It is a protocol designed to measure the
average fidelity or error rate of a set of quantum gates or operations, often referred
to as "Clifford gates." Randomized Benchmarking is widely used to quantify the
quality of quantum hardware and provides a benchmark for evaluating the noise
and errors in a quantum processor.

The Randomized Benchmarking Protocol:

The Randomized Benchmarking Protocol (RB) is a widely used technique in quantum


computing for assessing and quantifying the error rates in a quantum processor's
gate operations. It provides a robust and efficient method to estimate the average
error rate of a set of quantum gates. RB is designed to be relatively insensitive to the
specifics of the quantum hardware and is often used to benchmark the performance
of quantum processors. Here's an overview of the theory behind the Randomized
Benchmarking Protocol:

1. Error Rates in Quantum Gates:

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.

2. The Goal of RB:

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.

4. Randomized Benchmarking Sequence:

RB sequences are constructed by applying random sequences of Clifford gates


followed by an inverse sequence to undo the gate operations. These sequences are
designed to be "random" to ensure that errors accumulate over time.

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.

6. Decay of Quantum Coherence:

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:

By performing RB experiments with sequences of different lengths, you can estimate


the error rate by fitting the observed fidelity decay to a specific mathematical model.
This model accounts for the accumulation of errors over sequence length.

8. Robustness:

One of the strengths of RB is its robustness. RB error estimates are relatively


insensitive to the specific details of the quantum hardware and can provide a reliable
benchmark even when the hardware is noisy.

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.

10. Benchmarking Progress:

RB can be used to track the progress of quantum hardware and software


improvements over time. By regularly performing RB experiments, researchers can
monitor changes in error rates and identify areas for improvement.
In summary, the Randomized Benchmarking Protocol is a valuable tool in the field of
quantum computing for characterizing the performance of quantum gates. It provides
a practical way to estimate and track error rates, which is crucial for assessing the
reliability of quantum processors and for advancing the field of quantum error
correction.
Program :

import numpy as np
from qiskit import QuantumCircuit, transpile, Aer, execute

# Generate a random quantum circuit


def generate_random_circuit(num_qubits, depth):
circuit = QuantumCircuit(num_qubits, num_qubits)
for _ in range(depth):
for qubit in range(num_qubits):
circuit.rx(np.random.uniform(0, 2 * np.pi), qubit)
circuit.ry(np.random.uniform(0, 2 * np.pi), qubit)
circuit.rz(np.random.uniform(0, 2 * np.pi), qubit)
for qubit in range(num_qubits - 1):
circuit.cz(qubit, qubit + 1)
return circuit

# Perform randomized benchmarking


def randomized_benchmarking(num_qubits, depths, num_sequences, shots):
backend = Aer.get_backend('statevector_simulator')
results = []
for depth in depths:
success_counts = 0
for _ in range(num_sequences):
# Generate a random circuit and the corresponding inverse circuit
circuit = generate_random_circuit(num_qubits, depth)
inverse_circuit = circuit.inverse()

# Apply the circuit and obtain the final statevector


circuit_result = execute(circuit, backend=backend).result()
final_statevector = circuit_result.get_statevector()

# Apply the inverse circuit and obtain the final statevector


inverse_result = execute(inverse_circuit, backend=backend).result()
inverse_statevector = inverse_result.get_statevector()

# Calculate the success rate based on state fidelity


fidelity = np.abs(np.dot(final_statevector, inverse_statevector.conj()))
** 2
success_counts += shots * (1 - fidelity)

success_rate = success_counts / (num_sequences * shots)


results.append(success_rate)
return results

# 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 :

Result : [0.6116681128758453, 0.7011809859732847, 0.7120854233100897,


0.6813325854678913]
Conclusion: -

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?

Q3 How Can RB Be Applied to Specific Quantum Hardware or Software.


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. 6

Title: Implementing a 5 qubit Quantum Fourier Transform

Date of Completion: __________________ Date of Submission: __________________

S.N Criteria (ACVT) Possible Obtained


. Marks Marks

1 Answers (25%) 5

Coding Efficiency (25 %)


2 5

Viva (25%)
3 5

Timely Completion (25%)

4 5

5 Total 20

Total

Prof. P. B. Koli
(Subject Teacher)
EXPERIMENT NO. 6

⮚ Aim: Write a Python program to implementing a 5 qubit Quantum Fourier Transform

⮚ Outcome: At end of this experiment, student will be able to Write a Python program
to implement Quantum Teleportation algorithm in Python
⮚ Hardware Requirement:

⮚ Software Requirement: IBM Qiskit

⮚ Theory:
Introduction:

Quantum computing is a rapidly advancing field that promises to revolutionize


computation by leveraging the principles of quantum mechanics to perform complex
calculations efficiently. The Quantum Fourier Transform (QFT) is a pivotal quantum
algorithm that finds applications in various quantum algorithms, such as Shor's
algorithm for factoring large numbers and quantum phase estimation. This paper
delves into the theory and techniques for implementing a 5-qubit Quantum Fourier
Transform, an essential step toward building more advanced quantum algorithms.

Quantum Fourier Transform (QFT) Overview

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.

Implementing the 5-Qubit QFT

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.

c. Controlled Phase Shifts:

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.

Quantum Circuit Representation

A quantum circuit diagram representing the 5-qubit QFT is provided below for clarity:
Program:
from qiskit import QuantumRegister, ClassicalRegister

from qiskit import QuantumCircuit, execute,IBMQ

from qiskit.tools.monitor import job_monitor

from qiskit.circuit.library import QFT

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.append(QFT(num_qubits=5, approximation_degree=0, do_swaps=True, inverse=False,


insert_barriers=False, name='qft'), q)

circuit.measure(q,c)

circuit.draw(output='mpl', filename='qft1.png')

print(circuit)

job = execute(circuit, backend, shots=1000)

job_monitor(job)

counts = job.result().get_counts()

print("\n QFT Output")

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.append(QFT(num_qubits=5, approximation_degree=0, do_swaps=True, inverse=False,


insert_barriers=False, name='qft'), q)

circuit.measure(q,c)

circuit.draw(output='mpl',filename='qft2.png')

print(circuit)

job = execute(circuit, backend, shots=1000)

job_monitor(job)

counts = job.result().get_counts()

print("\n QFT with inverse QFT Output")

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)?

Q2. Describe the step-by-step process of implementing a 5-qubit Quantum Fourier


Transform (QFT). Discuss the quantum gates and operations involved in each step and
explain their significance. What challenges or potential sources of error might arise
during the implementation of a QFT on a quantum computer?

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?

You might also like