Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
77 views97 pages

Quantum Computing Book

This document is a handbook for the COMP 458/558 course on Quantum Computing Algorithms at Rice University, covering foundational concepts, quantum circuits, and advanced algorithms. It includes structured notes from lectures, discussions, and readings, emphasizing mathematical principles and various quantum algorithms. The content is designed to serve as a comprehensive reference for students and enthusiasts as quantum computing evolves.

Uploaded by

w2213548
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)
77 views97 pages

Quantum Computing Book

This document is a handbook for the COMP 458/558 course on Quantum Computing Algorithms at Rice University, covering foundational concepts, quantum circuits, and advanced algorithms. It includes structured notes from lectures, discussions, and readings, emphasizing mathematical principles and various quantum algorithms. The content is designed to serve as a comprehensive reference for students and enthusiasts as quantum computing evolves.

Uploaded by

w2213548
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/ 97

COMP 458/558

Quantum Computing Algorithms

Micah Kepe
Preface

Quantum computing is an emerging field poised to revolutionize multiple disciplines, including cryptography,
optimization, machine learning, and scientific simulations. This handbook serves as a structured compilation of
notes from COMP 458/558: Quantum Computing Algorithms, offered at Rice University during Spring 2025.
The content is derived from lectures, discussions, and supplementary readings throughout the semester, aiming
to reinforce core concepts and provide a comprehensive reference for students and enthusiasts alike.

The notes begin with foundational mathematical principles, including linear algebra and probability theory.
Subsequent sections explore quantum circuits, essential quantum gates, multi-qubit systems, and fundamental
quantum algorithms such as Grover’s search and Shor’s factoring algorithm. The latter phases of the hand-
book introduce advanced topics, including variational quantum algorithms, quantum simulation techniques, and
emerging paradigms in quantum machine learning and optimization.

I would like to extend my deepest gratitude to Professor Tirthak Patel, whose guidance and expertise have
been instrumental in shaping my understanding of quantum computing. I am also grateful to my peers for the
collaborative discussions that enriched my learning experience.

As quantum computing continues to evolve, these notes will remain a living document, subject to refinement
and expansion. I welcome feedback, corrections, and contributions from readers to ensure the accuracy and
completeness of this resource.

Micah Kepe
Rice University
Spring 2025
Table of Contents

Chapter 1 Phase I: Introduction and Background Page 1


1.1 Lecture 1: Overview of Quantum Computing Concepts 1
1.2 Lecture 2: Review of Linear Algebra Concepts 2
1.3 Lecture 3: Quantum Bits and Quantum States 6
1.4 Lecture 4: Quantum Gates and Transformations 9
1.5 Lecture 5: Other Quantum Gates, Measurement, Multi-Qubit Systems 13
1.6 Lecture 6: Multi-Qubit Gates and Circuit Construction 16
1.7 Lecture 7: More Multi-Qubit Gates, Reversibility Property, No-Cloning Theorem 18

Chapter 2 Phase II: Fundamentals of Quantum Algorithms Page 25


2.1 Lecture 8: Entanglement, Bell State, and Intro to Cirq 25
2.2 Lecture 9: Grover’s Search Algorithm 31
2.3 Lecture 10: Quantum Logic Gates, Applying Grover’s Search Algorithm to SAT 34
2.4 Lecture 11: Quantum Circuit Optimizations 38

Chapter 3 Phase III: Advanced Quantum Algorithms Page 41


3.1 Lecture 12: Introduction to Variational Quantum Algorithms 41
3.2 Lecture 13: Introduction to Quantum Approximate Optimization Algorithms (QAOA) 44
3.3 Lecture 14: More on QAOA: Cost and Mixer Hamiltonians, Full Circuit 49
3.4 Lecture 15: Wrapping Up QAOA: Intro to Coding in PennyLane, QUBO 55

Chapter 4 Phase IV: Special Topics in Quantum Computing Page 63


4.1 Lecture 16: Quantum Compiler Optimizations 63
4.2 Lecture 17: More on Quantum Compiler Optimizations, Quantum Computer Architectures 65
4.3 Lecture 18: Quantum Circuits as DAGs, Qubit Topologies, Logical to Physical Mapping 67
4.4 Lecture 19: More on Logical to Physical Mapping 69
4.5 Lecture 20: Quantum Error Correction– Bit Flip Errors 71
4.6 Lecture 21: Quantum Error Correction– Phase Flip Errors 74

Chapter 5 Phase V: Concluding Lectures Page 78


5.1 Lecture 22: Quantum Annealers, Trapped Ion Quantum Computers 78
5.2 Lecture 23: Neutral Atom Quantum Computers, Photonic Quantum Computers 82
4

Chapter 6 Quantum Computing Quick Reference Page 87


6.1 Cheatsheet 87

Chapter Appendix Page 91


Chapter 1

Phase I: Introduction and Background

1.1 Lecture 1: Overview of Quantum Computing Concepts


Definition 1.1.1: Quantum Computing

Quantum computing is a computational paradigm leveraging quantum mechanical principles such as


superposition, entanglement, and interference to perform computations that can surpass the capabilities
of classical systems for specific tasks.a
a Superposition allows quantum bits (qubits) to exist in multiple states simultaneously, and entanglement enables correla-

tions between qubits even at a distance.

Historical Development of Quantum Computing


• 1980s-1990s: Conception of quantum computing, with foundational ideas like the quantum Turing machine
and quantum gates.
• 1990s-2000s: Demonstration of key building blocks, such as quantum algorithms (e.g., Shor’s and Grover’s
algorithms).

• 2016: Emergence of quantum computing clouds, enabling access to quantum hardware via the internet.
• 2019: First claims of quantum advantage, showcasing tasks where quantum computers outperform
classical counterparts.
• 2024: Increasing qubit counts and improvements in quantum error correction techniques.

Applications of Quantum Computing


Quantum computing offers speedup in areas such as:

1. Quantum Simulation: Applications in chemistry, physics, and materials science, such as simulating
molecular energy levels and drug discovery.
2. Security and Encryption: Developing quantum-safe cryptographic protocols and random number gen-
eration.
3. Search and Optimization: Enhancing solutions for weather forecasting, financial modeling, traffic plan-
ning, and resource allocation.

Example 1.1.1 (Example: Quantum Speedup in Drug Discovery)


Drug discovery benefits from quantum simulation by enabling more accurate modeling of molecular inter-
actions, which classical computers struggle to achieve efficiently.
1. Phase I: Introduction and Background 2

Classical vs. Quantum Computing Paradigms


• Classical Computing: Utilizes traditional processing units (CPU, GPU, FPGA) and executes determin-
istic computations.
• Quantum Computing: Employs quantum processing units (QPU) with probabilistic computation based
on quantum states.

Note:-
Note: Classical computing paradigms still dominate in tasks that require precision and deterministic results.
Quantum computing excels in probabilistic or exponentially large state-space problems.

1.2 Lecture 2: Review of Linear Algebra Concepts


Linear algebra provides the foundation for manipulating quantum states, which are represented using vectors and
matrices in a complex vector space.
Definition 1.2.1: Vectors: Row and Column Vectors

A vector is an ordered list of numbers, which can be represented as either a row or column vector. The
components of vectors in quantum computing belong to the field of complex numbers (ℂ).

Column Vectors
A column vector is a vertical arrangement of numbers:

 𝑣1 
 𝑣2 
 
v =  .  , 𝑣 𝑖 ∈ ℂ.
 .. 
𝑣 
 𝑛

Row Vectors
A row vector is the complex conjugate transpose vector of a column vector:

v† = 𝑣 1 𝑣2 ... 𝑣𝑛 .
 

The adjoint of a column vector is a row vector, and vice versa. We represent the adjoint of a vector using
the dagger symbol (†).

Dirac Notation
In quantum computing, vectors are represented using Dirac notation (bra-ket notation):

• Ket |𝑣⟩: Represents a column vector.


• Bra ⟨𝑣|: Represents the adjoint (conjugate transpose) of the ket.

1+𝑖
 
• Example: |𝑣⟩ = , ⟨𝑣| = 1 − 𝑖
 
2 .
2

Definition 1.2.2: Euler’s Formula

Euler’s formula relates complex exponentials to trigonometric functions:

𝑒 𝑖𝜔 = cos(𝜔) + 𝑖 sin(𝜔)

This is fundamental in representing quantum states and transformations.


1. Phase I: Introduction and Background 3

Definition 1.2.3: Inner Product

The inner product of two vectors v, w ∈ ℂ𝑛 is defined as:


𝑛
Õ
⟨v, w⟩ = v† w = 𝑣𝑖 𝑤𝑖
𝑖=1

which measures the overlap between two quantum states.

Example 1.2.1 (Inner Product Example)


Given two vectors:    
1 2
v= , w=
𝑖 1
The inner product is:  
 2
=2−𝑖

⟨v, w⟩ = 1 −𝑖
1

We also have the following property that the inner product of a vector and itself is equivalent to the square
of the Euclidean norm of a vector:
⟨v, v⟩ = ∥v∥2

Definition 1.2.4: Outer Product

The outer product of two vectors v ∈ ℂ𝑚 and w ∈ ℂ𝑛 produces an 𝑚 × 𝑛 matrix:

 𝑣1 
 𝑣2  
 
vw =  .  𝑤 1

𝑤2 ... 𝑤𝑛

 .. 
𝑣 
 𝑚
This operation is useful for constructing quantum operators.

Definition 1.2.5: Tensor Product

The tensor product (or Kronecker product) allows us to describe multi-qubit systems. Given two vectors:

𝑣 𝑤1
   
v= 1 , w=
𝑣2 𝑤2
Their tensor product is:
𝑣 1 𝑤 1 
𝑣 𝑤 
 
v ⊗ w =  1 2
𝑣 2 𝑤 1 
𝑣 𝑤 
 2 2
The tensor product expands the state space, allowing representation of entangled states.

Orthagonality
Two vectors 𝑣, 𝑤 ∈ ℂ𝑛 are orthogonal if their inner product is zero:

⟨v, w⟩ = 0

Orthogonal vectors are linearly independent and span a subspace of the vector space. As you might
remember from linear algebra, a set of orthogonal vectors can be used to construct an orthonormal basis, and
any vector can be expressed as a linear combination of the basis vectors.
1. Phase I: Introduction and Background 4

This will be useful when we cover the quantum bases in section 1.3.

Definition 1.2.6: Adjoint of a Matrix

The adjoint (or Hermitian conjugate) of a matrix 𝐴 is obtained by taking the transpose and complex
conjugate of each entry:
𝐴† = 𝐴𝑇
If 𝐴 is:
𝑖
 
1
𝐴=
2 3
Then its adjoint is:  
1 2
𝐴† =
−𝑖 3

Definition 1.2.7: Unitary Matrix

A square matrix 𝑈 is called unitary if its adjoint is equal to its inverse:

𝑈 †𝑈 = 𝐼

where 𝐼 is the identity matrix. Unitary matrices preserve the norm of quantum states and represent
reversible quantum operations. Example:
 
1 1 1
𝑈=√ , 𝑈 †𝑈 = 𝐼
2 1 −1

Definition 1.2.8: Hermitian Matrix

A square matrix 𝐻 is called Hermitian if it is equal to its adjoint:

𝐻 = 𝐻†

Hermitian matrices represent observable quantities in quantum mechanics and have real eigenvalues. Ex-
ample:
2 𝑖
 
𝐻=
−𝑖 2

Since 𝐻 † = 𝐻, it is Hermitian.
Note:-
Hermitian matrices can’t have complex numbers in their diagonal General case illustration:

𝑎 + 𝑖𝑏 𝑐 + 𝑖𝑑 𝑎 − 𝑖𝑏 𝑒 −𝑖𝑓
   

𝑀= ⇒ 𝑀 = ⇒ 𝑀 ≠ 𝑀†
𝑒 +𝑖𝑓 𝑔 + 𝑖ℎ 𝑐 − 𝑖𝑑 𝑔 − 𝑖ℎ

∴ Hermitian matrices have real diagonal elements.


Additionally, the general matrix 𝑀 shown above is Hermitian iff. 𝑐 = 𝑒 , 𝑑 = − 𝑓

Hermitian matrices are not necessarily unitary, and unitary matrices are not necessarily Hermitian. A
matrix can be both, but these properties are distinct:
𝐻 = 𝐻† (Hermitian), 𝑈𝑈 † = 𝐼 (unitary)
In quantum computing, gates that are both Hermitian and unitary (e.g., Pauli gates) satisfy 𝑈 = 𝑈 † and
𝑈 = 𝐼, making them their own inverses—they cancel out when applied twice in succession. However, not all
2
1. Phase I: Introduction and Background 5

unitary gates are Hermitian (e.g., the phase gate, which is unitary but not Hermitian):
   
0 1 † 1 0
Pauli 𝑋 = , 𝑋=𝑋 , 𝑋 = 𝐼;
2
Phase 𝑆 = , 𝑆𝑆† = 𝐼, 𝑆 ≠ 𝑆†
1 0 0 𝑖

Definition 1.2.9: Eigenvalues and Eigenvectors

For a square matrix 𝐴 ∈ ℂ𝑛×𝑛 , a vector v ≠ 0 is an eigenvector if:

𝐴v = 𝜆v

where 𝜆 ∈ ℂ is the eigenvalue. Eigenvalues provide insight into the structure of linear transformations.
In Braket notation, the eigenvalue equation is:

𝐴|v⟩ = 𝜆|v⟩

Example 1.2.2 (Example: Eigenvalues)


For the matrix
𝑖
 
1
𝐴=
−𝑖 1
The characteristic equation is:
det(𝐴 − 𝜆𝐼) = (1 − 𝜆)2 + 1 = 0
Solving gives eigenvalues 𝜆 = 1 ± 𝑖.

Definition 1.2.10: Quantum Bits/ Qubits

A qubit can be defined mathematically as follows:

𝛼
 
𝜓 = 1 ∈ ℂ2
𝛼2

where:
𝛼1 , 𝛼2 ∈ ℂ and |𝛼1 |2 + |𝛼 2 |2 = 1

The first property ensures that the qubit is normalized, while the second property ensures that the qubit
is in a superposition of the basis states.

The first universal basis that we will look at is the computational basis, which consists of the states |0⟩
and |1⟩:    
1 0
Zero state = |0⟩ = One state = |1⟩ =
0 1

A quantum state vector 𝜓 can be expressed as a linear combination of the basis states:

𝜓 = 𝛼1 |0⟩ + 𝛼 2 |1⟩

Note:-
Properties of the computational basis:

• The computational basis states are orthogonal:


 
 0
⟨0|1⟩ = |0⟩ † |1⟩ = 1

0 =0
1
1. Phase I: Introduction and Background 6

• The computational basis states are normalized:


 

  1
⟨0|0⟩ = |0⟩ |0⟩ = 1 0 =1
0

Question 1

Show that any unitary matrix preserves the inner product of two vectors.

Solution: Since a unitary matrix satisfies 𝑈 †𝑈 = 𝐼, we have:

⟨𝑈v, 𝑈w⟩ = v† (𝑈 †𝑈)w = v† w

Thus, inner products are preserved.

1.3 Lecture 3: Quantum Bits and Quantum States


Definition 1.3.1: Qubit

A qubit is the fundamental unit of quantum information. Unlike a classical bit, which is either 0 or 1, a
qubit can exist in a superposition of states:

|𝜓⟩ = 𝛼|0⟩ + 𝛽|1⟩, where 𝛼, 𝛽 ∈ ℂ and ∥𝛼∥2 + ∥𝛽∥2 = 1

Key features of qubits include:

• Superposition: A qubit can exist simultaneously in multiple basis states.


• Complex Amplitudes: Coefficients 𝛼 and 𝛽 are complex numbers carrying magnitude and phase infor-
mation.
• Interference: Quantum states can interfere constructively or destructively.
• Entanglement: Qubits can be correlated in ways that classical bits cannot.

Classical Computing Paradigms


Quantum computing introduces a fundamentally different computational model. Here are some key paradigms
in classical computing that quantum computing challenges:

• Deterministic Computing: Uses discrete states (0 or 1) with predictable transitions.


• Analog Computing: Uses continuous values susceptible to noise accumulation.
• Probabilistic Computing: Represents probabilistic mixtures of states.

In contrast, for quantum computing:

• Quantum Computing: Allows coherent superposition with complex amplitudes and quantum interfer-
ence.
1. Phase I: Introduction and Background 7

Definition 1.3.2: Dirac Notation

Quantum states are represented using Dirac notation (bra-ket notation):


• Ket: |0⟩, |1⟩ represent computational basis states

• Computational basis vectors:    


1 0
|0⟩ = , |1⟩ =
0 1

• General state: |𝜓⟩ = 𝛼|0⟩ + 𝛽|1⟩

Definition 1.3.3: Basis States

Common qubit bases include:

• Computational Basis: |0⟩, |1⟩


• Hadamard Basis:  √ 
1 1/√2
|+⟩ = √ (|0⟩ + |1⟩) =
2 1/ 2
 √ 
1 1/ √2
|−⟩ = √ (|0⟩ − |1⟩) =
2 −1/ 2

• Phase/ Circular Polarization Basis:


1
|𝐿⟩ = |+𝑖⟩ = √ (|0⟩ + 𝑖|1⟩)
2
1
|𝑅⟩ = |−𝑖⟩ = √ (|0⟩ − 𝑖|1⟩)
2

Bloch Sphere Representation


Definition 1.3.4: Bloch Sphere

A geometric representation of a single qubit state:

𝜃 𝜃
     
|𝜓⟩ = cos |0⟩ + 𝑒 𝑖𝜙 sin |1⟩ 𝑒 𝑖𝛾
2 2

Where:
• 𝜃 ∈ [0, 𝜋] is the polar angle
• 𝜙 ∈ [0, 2𝜋) is the azimuthal angle

• 𝛾 is a global phase, often omitted since it cannot be represented on the Bloch sphere directly

Aside
Bloch Sphere Conversion to Cartesian Coordinates:

𝑥 = sin 𝜃 cos 𝜙, 𝑦 = sin 𝜃 sin 𝜙, 𝑧 = cos 𝜃


1. Phase I: Introduction and Background 8

Rearranging the Bloch sphere formula, we obtain that 𝜃 and 𝜙 can be expressed as:
!
𝛼2
𝜃 = 2 arccos(𝛼 1 ), 𝜙 = −𝑖 ln 𝜃

sin 2

Example 1.3.1 (Example Bloch Sphere Representation)


𝜋
For the state 𝜃 = 2,𝜙 = 0:

𝑧 |0⟩

𝑦
|𝜓⟩
𝑥
|1⟩

Example 1.3.2 (Factoring Out the Global Phase)


Let’s say that we have the following quantum state vector 𝜓 :

1
𝜓 = √ (𝑖 |0⟩ + |1⟩)
2
𝑖 1
= √ |0⟩ + √ |1⟩
2 2
 
1 1
= 𝑖 √ |0⟩ + √ |1⟩
|{z} 2 2
global phase

Quantum Measurement
When a qubit is measured:

• The quantum state collapses to an eigenstate


• Measurement probability depends on squared amplitude
• Computational basis measurement probabilities:

𝑃(0) = |𝛼|2 , 𝑃(1) = |𝛽|2

• Post-measurement state:
|𝑏⟩⟨𝑏|𝜓⟩
|𝜓new ⟩ = p
𝑃(𝑏)

Example 1.3.3 (Measurement Example)


q
For the state |𝜓⟩ = √1 |0⟩ + 2
3 3 |1⟩:
1. Phase I: Introduction and Background 9

• Probability of measuring |0⟩: 𝑃(0) = 1


3

• Probability of measuring |1⟩: 𝑃(1) = 2


3

Question 2: Orthonormality Check

Verify the inner products of basis states:

⟨0|1⟩ = 0
⟨0|0⟩ = 1
⟨+|+⟩ = 1
⟨+|−⟩ = 0

Solution: These relations hold due to the orthonormal nature of quantum basis states.
Note:-
Quantum Bases and Their 𝜃 and 𝜙 Values:

• Computational Basis: |0⟩ → 𝜃 = 0, 𝜙 = 0, |1⟩ → 𝜃 = 𝜋, 𝜙 = 0


𝜋 𝜋
• Hadamard Basis: |+⟩ → 𝜃 = 2,𝜙 = 0, |−⟩ → 𝜃 = 2,𝜙 =𝜋
𝜋 𝜋 𝜋
• Phase Basis: |𝐿⟩ = |+𝑖⟩ → 𝜃 = 2,𝜙 = 2, |𝑅⟩ = |−𝑖⟩ → 𝜃 = 2,𝜙 = − 𝜋2

1.4 Lecture 4: Quantum Gates and Transformations


Quantum gates manipulate qubits through unitary transformations, preserving quantum information and enabling
quantum computation. This section explores key quantum operations, their mathematical properties, and circuit
representations.
Definition 1.4.1: Qubit Superposition and Hilbert Space

A qubit exists in a complex vector space called a Hilbert space. The state of a qubit is given by:

|𝜓⟩ = 𝛼|0⟩ + 𝛽|1⟩, where 𝛼, 𝛽 ∈ ℂ and |𝛼|2 + |𝛽|2 = 1.

Measurement and Superposition Collapse


When a qubit is measured in the computational basis {|0⟩, |1⟩}, it collapses to one of the basis states with
probability:
𝑃(0) = ∥𝛼 1 ∥2 , 𝑃(1) = ∥𝛼2 ∥2 .
The post-measurement state is:
|𝑏⟩⟨𝑏|𝜓⟩
|𝜓measurement ⟩ = p
𝑃(𝑏)

where 𝑏 ∈ {0, 1}. This formula captures the quantum measurement postulate and ensures proper normalization
of the post-measurement state.

In the computational basis, the probability of measuring |𝑏⟩ is:

2
𝑃(𝑏) = ⟨𝑏|𝜓⟩
1. Phase I: Introduction and Background 10

Note:-
Probability Properties of Measurement:
𝑃(0) = 1 − 𝑃(1)
𝑃(+) = 1 − 𝑃(−)
𝑃(+𝑖) = 1 − 𝑃(−𝑖)

Quantum Gates and Operations


Quantum gates are unitary matrices that transform qubits. A general qubit transformation is given by:

|𝜓final ⟩ = 𝑈|𝜓initial ⟩

where 𝑈 is a unitary matrix satisfying 𝑈 †𝑈 = 𝐼. Key properties of quantum gates include:

• Reversibility: All quantum operations are reversible due to unitarity


• Preservation of Norm: The normalization condition |𝛼|2 + |𝛽|2 = 1 is preserved

• Linearity: Gates act linearly on superposition states

Definition 1.4.2: Rotation Gates

Rotation gates rotate a qubit state around the Bloch sphere:


• Rotation about X-axis:
cos 𝜔2 −𝑖 sin 𝜔2
 
𝑅 𝑋 (𝜔) =
−𝑖 sin 𝜔2 cos 𝜔2

Effect: Rotates state by angle 𝜔 around X-axis


• Rotation about Y-axis:
cos 𝜔2 − sin 𝜔2
 
𝑅𝑌 (𝜔) =
sin 𝜔2 cos 𝜔2

Effect: Rotates state by angle 𝜔 around Y-axis

• Rotation about Z-axis:


𝑒 −𝑖𝜔/2
 
0
𝑅 𝑍 (𝜔) =
0 𝑒 𝑖𝜔/2

Effect: Adds a relative phase between |0⟩ and |1⟩ components


1. Phase I: Introduction and Background 11

Definition 1.4.3: Pauli Matrices and Gates

The Pauli matrices define fundamental quantum operations:

• Pauli-X (NOT Gate, Bit-Flip):


 
0 1
𝑋=
1 0

Effect: 𝑋|0⟩ = |1⟩, 𝑋|1⟩ = |0⟩


• Pauli-Y (Combination of X and Z with phase):
 
0 −𝑖
𝑌=
𝑖 0

Effect: 𝑌|0⟩ = 𝑖|1⟩, 𝑌|1⟩ = −𝑖|0⟩


• Pauli-Z (Phase-Flip Gate):
 
1 0
𝑍=
0 −1

Effect: 𝑍|0⟩ = |0⟩, 𝑍|1⟩ = −|1⟩

Aside

Each of these matrices is both Hermitian (𝐴 = 𝐴† ) and unitary (𝐴† 𝐴 = 𝐼).

Important relationships:
• 𝑋 2 = 𝑌2 = 𝑍2 = 𝐼

• 𝑋𝑌 = 𝑖𝑍, 𝑌𝑍 = 𝑖𝑋, 𝑍𝑋 = 𝑖𝑌
• 𝑌𝑋 = −𝑖𝑍, 𝑍𝑌 = −𝑖𝑋, 𝑋𝑍 = −𝑖𝑌

Circuit Notation
Quantum circuits visually represent quantum operations. Each qubit is represented as a horizontal line, and gates
are applied sequentially from left to right. Important circuit elements include:1
• Single-qubit gates: Represented as boxes with gate symbols
• Measurements: Depicted with a meter symbol
• Time flow: Left to right in circuits (opposite of matrix multiplication order )2

Example 1.4.1 (Example: Complex Circuit Analysis)


Consider the circuit applying the sequence 𝐻𝑍𝐻 to |0⟩:
1
|𝜓1 ⟩ = 𝐻|0⟩ = √ (|0⟩ + |1⟩)
2
1
|𝜓2 ⟩ = 𝑍|𝜓1 ⟩ = √ (|0⟩ − |1⟩)
2
|𝜓3 ⟩ = 𝐻|𝜓2 ⟩ = |1⟩

1 For rendering quantum circuits, consider using the quantikz package in LATEX: https://ctan.org/pkg/quantikz
2 For example, the circuit 𝑈1 𝑈2 corresponds to the matrix product 𝑈2 𝑈1 .
1. Phase I: Introduction and Background 12

This sequence performs a NOT operation on |0⟩ using only Hadamard and Phase-flip gates.

|0⟩ 𝐻 𝑍 𝐻 |1⟩

Example 1.4.2 (Another Circuit Example)


  
0 −𝑖 1
𝑋𝑌 |0⟩ = 𝑋
𝑖 0 0
  
0 1 0
=
1 0 𝑖
𝑖
 
= = 𝑖 |1⟩
0

|0⟩ 𝑌 𝑋 𝑖 |0⟩

Question 3: Exercise 1

Apply the sequence 𝑆𝑋𝐻 to |0⟩ and calculate:

• The final state vector


• The probabilities of measuring |0⟩ and |1⟩
• The possible post-measurement states

Solution:
1
𝐻|0⟩ = √ (|0⟩ + |1⟩)
2
1 1
𝑋𝐻|0⟩ = √ (|1⟩ + |0⟩) = √ (|0⟩ + |1⟩)
2 2
1
𝑆𝑋𝐻|0⟩ = √ (|0⟩ + 𝑖|1⟩)
2
Therefore:

• Final state: |𝜓⟩ = √1 (|0⟩ + 𝑖|1⟩)


2

• Measurement probabilities: 𝑃(0) = 𝑃(1) = 1


2

• Post-measurement states: Either |0⟩ or |1⟩ with equal probability

Question 4: Exercise 2

Show that the Hadamard gate is its own inverse by calculating 𝐻 2 .

Solution: " #" #


√1 √1 √1 √1
 
1 0
𝐻 =
2
√1
2 2 2 2
= =𝐼
− √1 √1 − √1 0 1
2 2 2 2
1. Phase I: Introduction and Background 13

Question 5: Exercise 3

Calculate the effect of applying 𝑅 𝑍 (𝜋/2) to the state |+⟩.

Solution:  " √1 # " #


√1
𝑒 −𝑖𝜋/4

0
𝑅 𝑍 (𝜋/2)|+⟩ = 2
= 2
= | + 𝑖⟩
0 𝑒 𝑖𝜋/4 √1 √𝑖
2 2

1.5 Lecture 5: Other Quantum Gates, Measurement, Multi-Qubit


Systems
Definition 1.5.1: Single-Qubit Gates

Quantum gates manipulate individual qubits. Single-qubit gates are represented by unitary matrices that
operate on a single qubit.

The following are common single-qubit gates:

• Hadamard Gate (H):


 
1 1 1
𝐻=√
2 1 −1

Creates superposition: 𝐻 |0⟩ = |+⟩ , 𝐻 |1⟩ = |−⟩

Properties:

– Self-inverse: 𝐻 2 = 𝐼
– Maps computational basis to |±⟩ basis:
1
|+⟩ = √ (|0⟩ + |1⟩)
2
1
|−⟩ = √ (|0⟩ − |1⟩)
2

Note:-
𝐻 |0⟩ = |+⟩ , 𝐻 |1⟩ = |−⟩ , 𝐻 |+⟩ = |0⟩ , 𝐻 |−⟩ = |1⟩

• Phase Gate (S):


 
1 0
𝑆=
0 𝑖

Adds a 𝜋/2 phase to |1⟩, so it is also referred to as the ”𝜋/4 gate” due to 𝜃/2 term in the Bloch sphere
equation.

Properties:

– Unitary but not Hermitian


– 𝑆2 = 𝑍
1
– Effect on |+⟩ : 𝑆 |+⟩ = √ (|0⟩ + 𝑖 |1⟩)
2
1. Phase I: Introduction and Background 14

• T Gate:  
1 0
𝑇=
0 𝑒 𝑖𝜋/4

Adds a 𝜋/4 phase to |1⟩, so it is also known as the ”𝜋/8 gate”.

Properties:

– 𝑇2 = 𝑆
– 𝑇4 = 𝑍
– Often used in quantum error correction

• General Phase Gate 𝑃(𝜃):  


1 0
𝑃(𝜃) =
0 𝑒 𝑖𝜃

Generalizes S and T gates: 𝑆 = 𝑃(𝜋/2), 𝑇 = 𝑃(𝜋/4)

Example 1.5.1 (Example of Applying the Hadamard Gate)

  
1 1 1 1
𝐻 |0⟩ = √
2 1 −1 0
 
1 1
√ = |+⟩
2 1

Note:-
The following properties arise from applying the Hadamard gate:

𝑍 = 𝐻𝑋𝐻
𝑋 = 𝐻𝑍𝐻

Proof.       
1 1 1 0 1 1 1 1 1 0
𝐻𝑋𝐻 = √ √ = =𝑍
2 1 −1 1 0 2 1 −1 0 −1

Back to Measurement
Measurement collapses quantum states to basis states with probabilities determined by amplitudes.

• Z-basis: Standard computational basis (|0⟩, |1⟩)

* For state 𝜓 = 𝛼 |0⟩ + 𝛽 |1⟩:

𝑃(0) = ||𝛼||2
𝑃(1) = ||𝛽||2

• X-basis: Hadamard basis (|+⟩, |−⟩)

* Measure in Z-basis after applying H gate


* 𝑃(+) = | ⟨+| 𝜓⟩|2
* 𝑃(−) = | ⟨−| 𝜓⟩|2
1. Phase I: Introduction and Background 15

• Y-basis: Eigenstates of Y

* |+𝑖⟩ = √1 (|0⟩ + 𝑖 |1⟩)


2

* |−𝑖⟩ = √1 (|0⟩ − 𝑖 |1⟩)


2

Multi-Qubit Systems
States for multiple qubits are represented as tensor products:

2𝑛 −1
𝑘=Õ Õ
𝜓 = 𝛼 𝑘 |𝑘⟩ , ||𝛼 𝑘 ||2 = 1
𝑘=0

Properties of tensor products:

• Not commutative: (|0⟩ ⊗ |1⟩ ≠ |1⟩ ⊗ |0⟩)


• Associative: ((|𝑎⟩ ⊗ |𝑏⟩) ⊗ |𝑐⟩ = |𝑎⟩ ⊗ (|𝑏⟩ ⊗ |𝑐⟩))
• Distributive: ((𝛼 |𝑎⟩ + 𝛽 |𝑏⟩) ⊗ |𝑐⟩ = 𝛼(|𝑎⟩ ⊗ |𝑐⟩) + 𝛽(|𝑏⟩ ⊗ |𝑐⟩))

Question 6: Exercise 1

Prove that the Hadamard gate is unitary and Hermitian.

Solution: To prove H is unitary and Hermitian:

 
†1 1 1
𝐻 =√ =𝐻
2 1 −1
    
1 1 1 1 1 1 0
𝐻𝐻 = = =𝐼
2 1 −1 1 −1 0 1

Thus, H is both unitary (𝐻𝐻 † = 𝐼) and Hermitian (𝐻 = 𝐻 † ).

Question 7: Exercise 2

For 𝜓 = √1 (|00⟩ + |11⟩), find measurement probabilities for |00⟩ and |11⟩.
2

Solution: For 𝜓 = √1 (|00⟩ + |11⟩):


2

2
1 1
𝑃(00) = | ⟨00| 𝜓⟩|2 = √ =
2 2
2
1 1
𝑃(11) = | ⟨11| 𝜓⟩|2 = √ =
2 2

Question 8: Exercise 3

1 𝑖
 
Determine if 𝑈 = √1 is unitary.
2 𝑖 1
1. Phase I: Introduction and Background 16

Solution: To verify unitarity, compute 𝑈𝑈 † :

 
† 1 1 −𝑖
𝑈 =√
2 −𝑖 1
1 1 𝑖
     
1 −𝑖 1 0
𝑈𝑈 † = =
2 𝑖 1 −𝑖 1 0 1

∴ U is unitary.

Question 9: Exercise 4

If we apply H ⊗ H to |00⟩, what state do we get?

Solution:

(𝐻 ⊗ 𝐻) |00⟩ = (𝐻 |0⟩) ⊗ (𝐻 |0⟩)


1 1
= √ (|0⟩ + |1⟩) ⊗ √ (|0⟩ + |1⟩)
2 2
1
= (|00⟩ + |01⟩ + |10⟩ + |11⟩)
2
This creates an equal superposition of all two-qubit basis states.

1.6 Lecture 6: Multi-Qubit Gates and Circuit Construction


𝑛-qubit gates are unitary transformations that operate on 𝑛 qubits. This section explores key multi-qubit gates,
their properties, and how to construct quantum circuits using these gates.

Controlled Gates
Definition 1.6.1: Controlled X Gate

(CNOT) is a two-qubit gate that flips the target qubit if the control qubit is in state |1⟩, and does nothing
if the control qubit is in state |0⟩. The matrix representation of CNOT is given by:

1 0 0 0
­ 0 1 0 0®
© ª
𝐶𝑁 𝑂𝑇 = 𝐶𝑋 = ­
­ 0 0 0 1®
®

« 0 0 1 0¬
Representing the gate in a circuit diagram:

|𝑐⟩

|𝑡⟩ 𝑋

The control qubit is denoted by |𝑐⟩ and the target qubit is denoted by |𝑡⟩.

Applying the CNOT gate to a two-qubit state 𝜓 = 𝛼 |00⟩ + 𝛽 |01⟩ + 𝛾 |10⟩ + 𝛿 |11⟩:
1. Phase I: Introduction and Background 17

1 0 0 0 1 1
0 1 0 0 0 0
     
𝐶𝑋 |00⟩ = 0 = = |00⟩
0 0 1
 0 0
    
0 0 1 0 0 0
    
1 0 0 0 0 0
0 1 0 0 1 1
     
𝐶𝑋 |01⟩ = 0 = = |01⟩
0 0 1
 0 0
    
0 0 1 0 0 0
    
1 0 0 0 0 0
0 1 0 0 0 0
     
𝐶𝑋 |10⟩ = 0 = = |11⟩
0 0 1
 1 0
    
0 0 1 0 0 1
    
1 0 0 0 0 0
0 1 0 0 0 0
     
𝐶𝑋 |11⟩ = 0 = = |10⟩
0 0 1
 0 1
    
0 0 1 0 1 0
    

Controlled-Z Gate
Definition 1.6.2: Controlled-Z Gate

(CZ) applies a phase flip if both qubits are in state |1⟩:

1 0 0 0
­0 1 0 0 ®
© ª
𝐶𝑍 = ­
­0 0 1 0 ®
®

«0 0 0 −1¬

Applying the CZ gate to a 2-qubit system, we obtain:

𝐶𝑍 |00⟩ = |00⟩ , 𝐶𝑍 |01⟩ = |01⟩ , 𝐶𝑍 |10⟩ = |10⟩ , 𝐶𝑍 |11⟩ = − |11⟩

Unlike the CNOT gate, which flips the target qubit, the CZ gate only introduces a phase change to |11⟩.

Circuit Representations
The standard circuit representations for these multi-qubit gates are:

CNOT:

CZ:

Tensor Product Ordering and Circuit Representations


When converting quantum circuits to mathematical expressions, it’s important to understand that tensor prod-
ucts are not commutative: 𝐴 ⊗ 𝐵 ≠ 𝐵 ⊗ 𝐴 in general. However, we can modify the ordering of tensor products
1. Phase I: Introduction and Background 18

in our mathematical representation as long as we maintain the dependencies established by the circuit diagram.
This leads to multiple valid mathematical representations of the same quantum circuit.
Definition 1.6.3: Bit Ordering Convention

Due to the non-commutativity of tensor products, we adopt the convention of representing qubits from
most significant to least significant in our mathematical expressions. For an 𝑛-qubit system:

𝑞 𝑛−1 𝑞 𝑛−2 ...𝑞1 𝑞 0 = 𝑞 𝑛−1 ⊗ 𝑞 𝑛−2 ⊗ ... ⊗ 𝑞1 ⊗ 𝑞 0

where 𝑞 0 is the least significant qubit.

For example, consider a circuit with two Hadamard gates applied to different qubits:

𝑞1 𝐻

𝑞0 𝐻

This circuit can be represented mathematically in equivalent ways:


(𝐻 ⊗ 𝐻) 𝑞 1 𝑞 0 = (𝐻 𝑞1 ) ⊗ (𝐻 𝑞0 ) = 𝐻 𝑞1 ⊗ 𝐻 𝑞0
When gates have dependencies (like controlled operations), the ordering must respect these dependencies. For
the CNOT gate:

𝑞1

𝑞0 𝑋

The mathematical representation must preserve the control-target relationship, though intermediate calculations
may use different but equivalent orderings:
𝐶𝑁 𝑂𝑇1,0 𝑞 1 𝑞0 = 𝐶𝑁 𝑂𝑇( 𝑞1 ⊗ 𝑞0 )
This flexibility in representation, while maintaining functional equivalence, is particularly useful when
analyzing complex quantum circuits or optimizing quantum computations.

1.7 Lecture 7: More Multi-Qubit Gates, Reversibility Property, No-


Cloning Theorem
Review Questions
Question 10: Number of Measurement Bases

How many different bases can we measure a 𝑛-qubit system in?

Solution: Infinite
2
𝑃(𝑏) = ⟨𝑏|𝜓⟩
In quantum mechanics, a measurement basis for an 𝑛-qubit system is a set of orthonormal basis states in
a 2𝑛 -dimensional Hilbert space. The most common measurement basis is the computational basis, given by
{|0⟩, |1⟩}⊗𝑛 . However, we can measure in any orthonormal basis.
The space of all possible measurement bases corresponds to the space of all possible orthonormal bases,
which is parameterized by the unitary group 𝑈(2𝑛 ). The set of all 2𝑛 -dimensional orthonormal bases is described
by the unitary group 𝑈(2𝑛 ), modulo the global phase 𝑈(1). Since this space is continuous and has infinitely many
parameters, there exist an infinite number of measurement bases.
1. Phase I: Introduction and Background 19

Question 11: Output of Quantum Circuit

What is the output quantum state of the following quantum circuit:

|0⟩ 𝑞 2 𝑋 𝑋

|0⟩ 𝑞 1 𝑆 𝑋

|0⟩ 𝑞 0 𝑋

Solution: 011
• For 𝑞2 , the two 𝑋 gates essentially cancel each other out as the gate is Hermitian (𝑋𝑋 = 𝐼).
• For 𝑞1 , the 𝑆 gate does not affect the starting state |0⟩, and then the 𝑋 gate flips the signal to |1⟩.
• For 𝑞0 , the 𝑋 gate simply flips the signal from |0⟩ to |1⟩.
Remembering that we read the diagram top-down as the most significant bit to the least significant bit,
respectively, the output is 011.

More Multi-Qubit Gates


𝐶𝑋(𝑞0 → 𝑞1 ) Gate

Definition 1.7.1: 𝐶𝑋(𝑞0 → 𝑞1 ) Gate

The control and target qubits of a CNOT gate can be swapped using Hadamard gates:

(𝐻 ⊗ 𝐻) · 𝐶𝑁 𝑂𝑇control,target · (𝐻 ⊗ 𝐻) = 𝐶𝑁 𝑂𝑇target,control

This transformation can be visualized in a circuit diagram:

|𝑐⟩ 𝐻 𝐻

|𝑡⟩ 𝐻 𝑋 𝐻

The 𝐶𝑋(𝑞 0 → 𝑞1 ) gate, also known as 𝐶𝑁 𝑂𝑇𝑡𝑎𝑟 𝑔𝑒𝑡,𝑐𝑜𝑛𝑡𝑟𝑜𝑙 , is a variant of the CNOT gate where the control
and target qubits are swapped. Its matrix representation is:

1 0 0 0
­0 0 0 1®
© ª
𝐶𝑁 𝑂𝑇𝑡𝑎𝑟 𝑔𝑒𝑡,𝑐𝑜𝑛𝑡𝑟𝑜𝑙 =­
­0 0 1 0®
®

«0 1 0 0¬
This gate flips the target qubit (𝑞1 ) if the control qubit (𝑞0 ) is in state |1⟩.

Derivation of the 𝐶𝑋(𝑞 0 → 𝑞1 ) Gate


The control and target qubits of a CNOT gate can be swapped using Hadamard (𝐻) gates applied to both qubits.
Mathematically, this operation is represented as:
(𝐻 ⊗ 𝐻) · CNOTcontrol,target · (𝐻 ⊗ 𝐻) = CNOTtarget,control
1. Phase I: Introduction and Background 20

The transformed CNOT gate is:


(𝐻 ⊗ 𝐻) · CNOT · (𝐻 ⊗ 𝐻).

Step 1: Compute CNOT · (𝐻 ⊗ 𝐻)


First, multiply the CNOT matrix with 𝐻 ⊗ 𝐻:
1 0 0 0 1 1 1 1
­0 1 0 0® 1 ­1 −1 1 −1®
© ª © ª
CNOT · (𝐻 ⊗ 𝐻) = ­ · ­
­0 0 0 1® 2 ­1 1 −1 −1®
® ®

« 0 0 1 0¬ «1 −1 −1 1 ¬
This results in:
1 1 1 1
1 ­1 −1 1 −1®
© ª
CNOT · (𝐻 ⊗ 𝐻) = ­
2 ­1 −1 −1 1®
®

«1 1 −1 −1¬
Notice that the third and fourth rows of the matrix switch places due to the CNOT gate’s effect.

Step 2: Multiply (𝐻 ⊗ 𝐻) to the Above Result


Now, multiply 𝐻 ⊗ 𝐻 from the left:
1 1 1 1
1 ­1 −1 1 −1®
© ª
(𝐻 ⊗ 𝐻) · ­
2 ­1 −1 −1 1®
®

«1 1 −1 −1¬
Expanding this:
1 1 1 1 1 1 1 1
1 ­1 −1 1 −1® 1 ­1 −1 1 −1®
© ª © ª
−1
®· ­
−1® 2 ­1 −1 −1
2 ­1 1 1®
­ ®

«1 −1 −1 1¬ «1 1 −1 −1¬
After computation, the resulting matrix is:
1 0 0 0
­0 0 0 1®
© ª
CNOTtarget,control =­
­0 0 1 0®
®

«0 1 0 0¬
This matrix corresponds to the CNOT gate with the control and target qubits swapped.

SWAP Gate
Definition 1.7.2: SWAP Gate

The SWAP gate exchanges the states of two qubits. Its matrix representation is:

1 0 0 0
­0 0 1 0®
© ª
𝑆𝑊 𝐴𝑃 = ­
­0 1 0 0®
®

«0 0 0 1¬
The action of SWAP on basis states is given by:

𝑆𝑊 𝐴𝑃 |𝑎𝑏⟩ = |𝑏𝑎⟩ , 𝑎, 𝑏 ∈ {0, 1}

Effects of SWAP Gate The SWAP gate interchanges the states of two qubits. For any 2-qubit computational
basis state, its action is:
1. Phase I: Introduction and Background 21

Note:-
SWAP |00⟩ = |00⟩ , SWAP |01⟩ = |10⟩ , SWAP |10⟩ = |01⟩ , SWAP |11⟩ = |11⟩

Thus, for any superposition of 2-qubit states, the SWAP gate exchanges the amplitudes corresponding to
each qubit’s position.

Circuit Representations
The standard circuit representations for these 2-qubit gates are:

𝐶𝑁 𝑂𝑇target, control : 𝑋

SWAP:
.

𝑛-Qubit Gates
Before we just looked at the 2-qubit version of the Controlled X gate, but it extends to 𝑛-qubits.

Toffoli Gate
Definition 1.7.3: Toffoli Gate

(CCX) is a three-qubit gate with two control qubits and one target qubit. Its matrix representation is:

1 0 0 0 0 0 0 0
©0 1 0 0 0 0 0 0ª®
­
­0 0 1 0 0 0 0 0®®
­
­0 0 0 1 0 0 0 0®®
Toffoli = ­­
­0 0 0 0 1 0 0 0®®
­0 0 0 0 0 1 0 0®®
­
­0 0 0 0 0 0 0 1®
«0 0 0 0 0 0 1 0¬

The Toffoli gate is Hermitian and only flips the target qubit if both control qubits are in state |1⟩.

Circuit Representation
The standard circuit representation for the Toffoli/ 𝐶𝐶𝑋 gate is as follows:

CCX:

Effects of Toffoli Gate The Toffoli (CCX) gate acts on a 3-qubit system, where the first two qubits serve as
control qubits and the third is the target. Its effect on the computational basis states is:
1. Phase I: Introduction and Background 22

Note:-
Toffoli |000⟩ = |000⟩ Toffoli |100⟩ = |100⟩
Toffoli |001⟩ = |001⟩ Toffoli |101⟩ = |101⟩
Toffoli |010⟩ = |010⟩ Toffoli |110⟩ = |111⟩
Toffoli |011⟩ = |011⟩ Toffoli |111⟩ = |110⟩

In essence, the target qubit is flipped only when both control qubits are in the |1⟩ state; otherwise, the
state remains unchanged.
As you would expect, multi-controlled 𝑋 gates are Hermitian.

Example 1.7.1 (Quantum Circuit Showing Hermitian Property)


A quantum circuit composed of Hermitian gates (e.g., 𝑋, 𝑍, 𝐻) will cancel out when the circuit is reversed,
resulting in the identity operation.

𝜓 𝐻 𝑍 𝑋 𝑋 𝑍 𝐻 𝜓

In this example, the quantum circuit consists of a sequence of Hermitian gates: the Hadamard (𝐻), Pauli-Z
(𝑍), and Pauli-X (𝑋) gates. These gates satisfy the property:

𝐻 = 𝐻†, 𝑋 = 𝑋†, 𝑍 = 𝑍†

Since these gates are their own inverses (i.e., 𝐻𝐻 = 𝐼, 𝑋𝑋 = 𝐼, and 𝑍𝑍 = 𝐼), if we apply the same sequence
of gates in reverse order, they cancel out, leaving the identity operation.
The circuit above first applies 𝐻, then 𝑍, then 𝑋 twice (which cancels itself out), then 𝑍 again, and finally
𝐻 again. This results in:
𝐻𝑍𝑋𝑋𝑍𝐻 = 𝐼
Hence, the overall operation on the qubit is the identity transformation, meaning the final state remains
the same as the initial state 𝜓 .

Definition 1.7.4: Reversibility Property of Quantum Computing

Quantum operations are inherently reversible due to the unitary nature of quantum gates. This means
that any quantum circuit can be reversed by applying the inverse of each gate in the reverse order.
Mathematically, if a quantum circuit is represented by a unitary matrix 𝑈, its reverse is represented by
𝑈 † , and since quantum gates are unitary, they satisfy the property:

𝑈 †𝑈 = 𝑈𝑈 † = 𝐼

This reversibility is a fundamental difference between quantum and classical computing and is directly
tied to the no information loss principle in quantum mechanics.

Why Reversibility is Important: In classical computing, operations such as the AND gate lose information.
For example, given the output of an AND gate, we cannot uniquely determine the original input:

(0, 0) ↦→ 0, (0, 1) ↦→ 0, (1, 0) ↦→ 0, (1, 1) ↦→ 1

Since multiple inputs can produce the same output, information is lost, making the operation irreversible.

Classical AND Gate (Irreversible)


1. Phase I: Introduction and Background 23

𝐴
𝐴 𝐵 𝐴∧𝐵
𝐴∧𝐵
0 0 0
𝐵 0 1 0
1 0 0
1 1 1

This classical AND gate demonstrates information loss (irreversibility) because multiple distinct input states map
to the same output state. As shown in the truth table, three different input combinations (0,0), (0,1), and (1,0)
all produce the same output 0. Given only the output 0, it is impossible to determine which of these three input
states generated it—this loss of information about the system’s initial state makes the operation irreversible.

Quantum Reversibility: In contrast, quantum gates are always unitary, meaning they preserve the total
amount of information. Given the final state of a quantum system, we can always determine its previous state by
applying the inverse transformation. This is why quantum circuits must be composed of reversible operations.

Example 1.7.2 (Example of a Reversible Quantum Circuit:)

𝜓 𝐻 𝑋 𝑋 𝐻 𝜓

In this example, the quantum circuit consists of a sequence of unitary gates: the Hadamard (𝐻) and the
Pauli-X (𝑋) gates. These gates satisfy:

𝐻 = 𝐻†, 𝑋 = 𝑋†

Since these gates are their own inverses (i.e., 𝐻𝐻 = 𝐼 and 𝑋𝑋 = 𝐼), if we apply the same sequence of gates
in reverse order, they cancel out, leaving the identity operation:

𝐻𝑋𝑋𝐻 = 𝐼

Key Properties of Reversible Quantum Gates:


1. Every quantum gate 𝑈 has an inverse 𝑈 † , ensuring that no information is lost.

2. The composition of unitary gates remains unitary, preserving reversibility.


3. Classical Toffoli and Fredkin3 are reversible and can be used to construct reversible classical circuits, which
is why they are also fundamental in quantum computing.
4. Measurement is not reversible, as it collapses the quantum state and introduces information loss.

The reversibility of quantum computing is crucial for error correction, fault-tolerant quantum computation,
and simulating physical systems where information is conserved.

Example 1.7.3 (Example of Reversing a Quantum Circuit)


Consider a circuit composed of gates 𝐴, 𝐵, and 𝐶:

|𝜓final ⟩ = 𝐶𝐵𝐴|𝜓initial ⟩.

The reverse circuit applies 𝐶 † , 𝐵† , and 𝐴† in reverse order:

|𝜓reversed ⟩ = 𝐴† 𝐵† 𝐶 † |𝜓final ⟩ = 𝐴† 𝐵† 𝐶 † 𝐶𝐵𝐴|𝜓initial ⟩ = |𝜓initial ⟩.

3 More on Fredkin gates: https://en.wikipedia.org/wiki/Fredkin_gate


1. Phase I: Introduction and Background 24

Definition 1.7.5: Quantum No-Cloning Theorem

The no-cloning theorem states that it is impossible to create an identical copy of an arbitrary unknown
quantum state. This result follows directly from the linearity of quantum mechanics.

Example 1.7.4 (Simple 2-Qubit Example)


Consider two qubits in states 𝜓 and |0⟩. The no-cloning theorem implies that there is no unitary operation
𝑈 such that:
𝑈( 𝜓 ⊗ |0⟩) = 𝜓 ⊗ 𝜓 .

Proof. Proof of the Quantum No-Cloning Theorem


Assume a unitary operator 𝑈 exists that can clone an arbitrary quantum state 𝜓 . Then, for two different
states 𝜓 and 𝜙 , we would have:
𝑈( 𝜓 ⊗ |0⟩) = 𝜓 ⊗ 𝜓 ,
𝑈( 𝜙 ⊗ |0⟩) = 𝜙 ⊗ 𝜙 .
Now, consider the superposition state |𝜉⟩ = 𝑎 𝜓 + 𝑏 𝜙 . Applying 𝑈 to |𝜉⟩ ⊗ |0⟩ should produce:

𝑈(|𝜉⟩ ⊗ |0⟩) = 𝑎𝑈( 𝜓 ⊗ |0⟩) + 𝑏𝑈( 𝜙 ⊗ |0⟩) = 𝑎( 𝜓 ⊗ 𝜓 ) + 𝑏( 𝜙 ⊗ 𝜙 ).

However, if 𝑈 could clone |𝜉⟩, the result should be:

𝑈(|𝜉⟩ ⊗ |0⟩) = |𝜉⟩ ⊗ |𝜉⟩ = (𝑎 𝜓 + 𝑏 𝜙 ) ⊗ (𝑎 𝜓 + 𝑏 𝜙 ).

Expanding this, we get:

|𝜉⟩ ⊗ |𝜉⟩ = 𝑎 2 ( 𝜓 ⊗ 𝜓 ) + 𝑎𝑏( 𝜓 ⊗ 𝜙 ) + 𝑎𝑏( 𝜙 ⊗ 𝜓 ) + 𝑏 2 ( 𝜙 ⊗ 𝜙 ).

Comparing the two expressions, we see that the terms 𝜓 ⊗ 𝜙 and 𝜙 ⊗ 𝜓 appear in the expanded
|𝜉⟩ ⊗ |𝜉⟩, but they do not appear in 𝑎( 𝜓 ⊗ 𝜓 ) + 𝑏( 𝜙 ⊗ 𝜙 ). This inconsistency demonstrates that a unitary
operator 𝑈 cannot clone an arbitrary quantum state, proving the no-cloning theorem. ■
Chapter 2

Phase II: Fundamentals of Quantum


Algorithms

2.1 Lecture 8: Entanglement, Bell State, and Intro to Cirq


Review from Previous Lecture
Question 12: Quantum Circuit Final State

Given this circuit diagram and assuming an initial state 𝜓 𝑖 = |00⟩, what will the final state 𝜓 𝑓 measure?

|0⟩ 𝑞 1 𝑋 𝐻

|0⟩ 𝑞 0 𝑋 𝐻

Solution: 𝜓 𝑓 = |−−⟩

Entanglement
In this section, we introduce quantum entanglement—a phenomenon where the states of two or more qubits
become inseparably linked, leading to correlations between measurement outcomes that cannot be explained
classically.
Definition 2.1.1: Entanglement

”Quantum entanglement is the phenomenon of a group of particles being generated, interacting, or


sharing spatial proximity in a manner such that the quantum state of each particle of the group cannot
be described independently of the state of the others, including when the particles are separated by a large
distance.” a
a https://en.wikipedia.org/wiki/Quantum_entanglement

What is Entanglement?
To understand quantum entanglement, let’s compare classical and quantum communication systems:

Consider two classical email clients, Alice and Bob:

• When Alice sends an email, she knows exactly what she sent
2. Phase II: Fundamentals of Quantum Algorithms 26

• Bob knows exactly what he received


• The message state is definite and independent

• Multiple copies can exist

Now consider two quantum ”email clients” with entangled qubits:

• Neither Alice nor Bob knows their qubit’s state before measurement

• When Alice measures her qubit, Bob’s qubit instantly becomes correlated
• The qubits share a single quantum state
• No copies can be made (no-cloning theorem)
• The correlation exists regardless of distance

This ”spooky action at a distance”1 , as Einstein called it, has no classical analog and is a fundamental
feature of quantum mechanics.

Bell-Pair Circuit
The Bell-Pair circuit is the most analogous thing to quantum computing’s Hello, world! program. It prepares
a maximally entangled two-qubit state (a Bell state).

|0⟩ 𝑞 1 𝐻

|0⟩ 𝑞 0 𝑋

Proof. Showing Full Entanglement Mathematically Starting with the initial state:

𝜓0 = |0⟩ 1 ⊗ |0⟩ 0 = |00⟩ ,

we first apply a Hadamard gate on qubit 𝑞1 :

1
𝐻 |0⟩ = √ (|0⟩ + |1⟩).
2
Thus, the state after the Hadamard becomes:
1 1
(𝐻 ⊗ 𝐼) |00⟩ = √ (|0⟩ + |1⟩) ⊗ |0⟩ = √ (|00⟩ + |10⟩).
2 2
Next, we apply the CNOT gate with qubit 𝑞1 as the control and qubit 𝑞0 as the target. The CNOT gate
acts as follows:
CNOT |00⟩ = |00⟩ , CNOT |10⟩ = |11⟩ .
Thus, the final state after the CNOT is:

1
𝜓Bell = √ (|00⟩ + |11⟩).
2

This state is fully entangled since it cannot be factored as a tensor product of individual qubit states.

1 ”Spooky action at a distance”: https://en.wikipedia.org/wiki/Action at a distance
2. Phase II: Fundamentals of Quantum Algorithms 27

As a consequence of being fully entangled:

1. Entangled circuits cannot be expressed as a product state. For example, the Bell state
1
𝜓Bell = √ (|00⟩ + |11⟩)
2

cannot be decomposed into 𝜙 1


⊗ |𝜒⟩ 0 .
2. Measurement outcomes are correlated. For instance, if qubit 𝑞 1 is measured as |0⟩, then qubit 𝑞0 will also
be found in the state |0⟩; similarly, if 𝑞1 is measured as |1⟩, then 𝑞0 will be |1⟩.

Extending the Bell-Pair Circuit to a 𝑛-Qubit System


The Bell state can be generalized to an 𝑛-qubit system, often taking the form of a Greenberger–Horne–Zeilinger
(GHZ) state:

|0⟩ 𝑞 𝑛−1 𝐻

|0⟩ 𝑞 𝑛−2 𝑋

..
.

|0⟩ 𝑞1 𝑋

|0⟩ 𝑞0 𝑋

The 𝑛-qubit Bell circuit follows a clear pattern:

1. Initial Hadamard gate on the topmost qubit creates superposition

2. Cascade of CNOT gates propagates the entanglement down


3. Each CNOT uses the previous qubit as control and current qubit as target
4. Final state has all qubits entangled together

The resulting state:


1
𝜓 𝑓 = √ (|00 · · · 00⟩ + |11 · · · 11⟩)
2
represents a superposition where all qubits are either all 0 or all 1. Measuring any qubit collapses the entire
state, forcing all other qubits to match the measured value.

Note:-
It is important to note that there are equivalent diagrams that can be drawn for the 𝑛-qubit Bell state circuit,
and that you should not be fooled by diagrams that do not match the general diagram shown above.

Example 2.1.1 (Alternative 𝑛-Qubit Bell Circuit)


2. Phase II: Fundamentals of Quantum Algorithms 28

|0⟩ 𝑞 𝑛−1 𝐻

|0⟩ 𝑞 𝑛−2 𝑋

|0⟩ 𝑞1 𝑋

|0⟩ 𝑞0 𝑋

This alternative representation achieves the same final state by having the first qubit control all CNOT
operations directly. While functionally equivalent, this requires longer-range interactions which may be
harder to implement on real quantum hardware.

Aside
Shorthand Notation Used for Final Quantum States

Common notational shortcuts can be confusing for beginners. Here are some important distinctions:

• |+1⟩ typically means √1 (|01⟩ + |11⟩), not |+⟩ ⊗ |1⟩


2

• |−1⟩ represents √1 (|01⟩ − |11⟩), not to be confused with − |1⟩ or 𝑍 |1⟩


2

• In general, |±𝑥⟩ represents √1 (|0𝑥⟩ ± |1𝑥⟩) where 𝑥 is a bit string


2

• The notation 𝜓 + and 𝜓 − is often used for Bell states √1 (|01⟩ ± |10⟩)
2

Always check the context and definitions when encountering shorthand notation, as conventions may vary
between sources.

Partial Entanglement There also exists the middle ground of partially-entangled systems where only some
of the qubits are entangled while others have independent states.

|0⟩ 𝑞2 𝐻

|0⟩ 𝑞1 𝐻

|0⟩ 𝑞0 𝑋

In this case, 𝑞 1 and 𝑞 0 become entangled through the CNOT gate, while 𝑞 2 remains in a superposition
state but independent of the other qubits. The final state is:
1 1
𝜓 𝑓 = √ |+⟩ 2 ⊗ √ (|00⟩ 10 + |11⟩ 10 )
2 2

Getting Started with Cirq


Cirq2 is an open-source framework for programming quantum computers, developed by Google Quantum AI.
It provides tools for creating, manipulating, and optimizing quantum circuits, as well as simulating quantum
computations.

Key features of Cirq include:


2 Cirq documentation: https://quantumai.google/cirq
2. Phase II: Fundamentals of Quantum Algorithms 29

• Native support for quantum gates and circuits


• Built-in quantum simulator

• Tools for noise modeling and error mitigation

Overview and Installation


Cirq allows you to work with qubits, gates, and operations to build circuits. To begin, install Cirq in your Python
environment (a Google Colab workbook is my personal recommendation):

1 pip install --quiet cirq

Then import the library:

1 import cirq

Defining Qubits
Cirq supports different types of qubits:

• NamedQubit: Qubits with custom names.


• LineQubit: Qubits arranged in a linear array.
• GridQubit: Qubits arranged in a 2D grid.

For example, to create line qubits:

1 q0, q1, q2 = cirq.LineQubit.range(3)

Gates and Operations


In Cirq, a Gate represents an abstract quantum operation, while an Operation is a gate applied to specific qubits.

• Single-qubit gates: cirq.X, cirq.H, cirq.S, etc.


• Two-qubit gates: cirq.CNOT, cirq.CZ, cirq.SWAP, etc.

Example: Applying a Hadamard gate to qubit 𝑞0 and a CNOT with 𝑞0 as control and 𝑞1 as target:

1 circuit = cirq.Circuit()
2 circuit.append(cirq.H(q0))
3 circuit.append(cirq.CNOT(q0, q1))

Circuits and Moments


A Circuit in Cirq is composed of Moments—collections of operations that occur simultaneously (on disjoint sets
of qubits). When you append operations, Cirq automatically schedules them into moments.
2. Phase II: Fundamentals of Quantum Algorithms 30

Simulation and Measurement


Cirq provides a simulator to compute the resulting state vector or sample measurement outcomes.

• simulate(): Returns the final state vector.


• run(): Samples measurement outcomes.

Example: Creating and Simulating a Bell State

1 import cirq

2 # Create two line qubits.


3 q0, q1 = cirq.LineQubit.range(2)

4 # Construct the Bell state circuit.


5 bell_circuit = cirq.Circuit(
6 cirq.H(q0), # Create superposition on q0.
7 cirq.CNOT(q0, q1) # Entangle q0 with q1.
8 )

9 print("Bell Circuit:")
10 print(bell_circuit)

11 # Initialize the simulator.


12 simulator = cirq.Simulator()

13 # Simulate to obtain the final state vector.


14 result = simulator.simulate(bell_circuit)
15 print("Final state vector:")
16 print(result.final_state_vector)

17 # Add measurement and run the circuit.


18 bell_circuit.append(cirq.measure(q0, q1, key='result'))
19 samples = simulator.run(bell_circuit, repetitions=1024)
20 print("Measurement histogram:")
21 print(samples.histogram(key='result'))

Advanced Topics in Cirq


Cirq also supports:

• Parameter Sweeps: Optimize variational algorithms using free parameters.


• Unitary Access and Decomposition: Retrieve matrix representations and decompose complex gates.
• Transformers: Automatically merge or re-schedule operations for hardware compatibility.

Example: Sweeping a Parameter in an 𝑋 Gate

1 import sympy
2 import matplotlib.pyplot as plt

3 # Define a qubit.
4 q = cirq.GridQubit(1, 1)

5 # Create a circuit with an X gate raised to a symbolic exponent.


6 circuit = cirq.Circuit(cirq.X(q) ** sympy.Symbol('t'),
7 cirq.measure(q, key='m'))

8 # Sweep the parameter 't' from 0 to 2.


2. Phase II: Fundamentals of Quantum Algorithms 31

9 param_sweep = cirq.Linspace('t', start=0, stop=2, length=200)

10 # Simulate the sweep.


11 simulator = cirq.Simulator()
12 trials = simulator.run_sweep(circuit, param_sweep, repetitions=1000)

13 # Plot the frequency of measuring 1.


14 x_data = [trial.params['t'] for trial in trials]
15 y_data = [trial.histogram(key='m')[1] / 1000.0 for trial in trials]
16 plt.scatter(x_data, y_data)
17 plt.xlabel("Parameter t")
18 plt.ylabel("Frequency of 1")
19 plt.show()

2.2 Lecture 9: Grover’s Search Algorithm


Problem Statement
Given a bitstring 𝑥 ∈ {0, 1}𝑛 and a function
(
1, if 𝑥 is the marked (or winning) state,
𝑓 (𝑥) =
0, otherwise,

our goal is to find the unique (or one of the) 𝑥 such that 𝑓 (𝑥) = 1.

In plain terms, imagine you have an unsorted database of 𝑁 = 2𝑛 items, and only one item is “special.”
Classically, you must check each item one by one (on average, 𝑂(2𝑛 ) trials) to find the special
√ item. Grover’s
algorithm, however, uses quantum amplitude amplification to solve this problem in only 𝑂( 2𝑛 ) iterations—a
quadratic speedup over classical search.

Grover’s Algorithm Circuit


The general structure of Grover’s algorithm is as follows:

1. State Preparation: Initialize all qubits in the state |0⟩ ⊗𝑛 and apply 𝐻 ⊗𝑛 to create a uniform superposition:
1 Õ
|𝑠⟩ = 𝐻 ⊗𝑛 |0⟩ ⊗𝑛 = √ |𝑥⟩ .
2𝑛 𝑥∈{0 ,1}𝑛


2. Grover Iteration: Repeat the following two steps approximately 2𝑛 times:

• Oracle 𝑂: Flip the phase of the marked state(s); that is, for every 𝑥,

𝑂 |𝑥⟩ = (−1) 𝑓 (𝑥) |𝑥⟩ .

For example, if the winning state is |𝑤⟩, then 𝑂 |𝑤⟩ = − |𝑤⟩.


• Diffusion Operator 𝐷: Reflect all amplitudes about the average amplitude. This operator is given
by
𝐷 = 2 |𝑠⟩ ⟨𝑠| − 𝐼.
In practice, 𝐷 is implemented as

𝐷 = 𝐻 ⊗𝑛 𝑋 ⊗𝑛 (𝐶𝑍) 𝑋 ⊗𝑛 𝐻 ⊗𝑛 ,

where the 𝐶𝑍 gate here represents a controlled phase flip on |1⟩ ⊗𝑛 (for 𝑛 > 2, this is a multi-controlled
𝑍 gate).
2. Phase II: Fundamentals of Quantum Algorithms 32

The high-level circuit for an 𝑛-qubit Grover algorithm is illustrated as:

𝑞 𝑛−1 𝐻

𝑞 𝑛−2 𝐻

.. .. 𝑓 (𝑥) .. ..
. . . Diffusion Circuit .
Oracle

𝑞1 𝐻

𝑞0 𝐻

| {z }

Repeat 2𝑛 times

Inversion About the Mean


The diffusion operator 𝐷 reflects the amplitudes of all states about the average amplitude. This process is often
referred to as ”inversion about the mean.” The following diagram illustrates this concept:

Amplitude

Initial Amplitudes
Reflected Amplitudes

Average Amplitude

States
|000⟩ |001⟩ |010⟩ |011⟩ |100⟩ |101⟩ |110⟩

The blue bars represent the initial amplitudes of the states, and the red dashed bars represent the amplitudes
after inversion about the mean. The marked state’s amplitude is amplified, while the amplitudes of the other
states are reduced.

2-Qubit Example
To build intuition, consider the case 𝑛 = 2 (i.e., 𝑁 = 4) with the winning state chosen as |11⟩.

Oracle: For a 2-qubit system, the Oracle 𝑂 can be implemented as a controlled-𝑍 (CZ) gate:

1 0 0 0
­0 1 0 0 ®
© ª
𝐶𝑍 = ­ ®,
­0 0 1 0 ®
«0 0 0 −1¬
which multiplies the state |11⟩ by −1.
2. Phase II: Fundamentals of Quantum Algorithms 33

Diffusion Operator: For 2 qubits, the diffusion operator is given by:

𝐷 = 𝐻 ⊗2 𝑋 ⊗2 𝐶𝑍 𝑋 ⊗2 𝐻 ⊗2 .

2-Qubit Grover Circuit:

|0⟩ 𝐻 𝐻 𝑋 𝑋 𝐻

|0⟩ 𝐻 𝐻 𝑋 𝐻 𝑋 𝐻 𝑋 𝐻

Explanation:

• Oracle: The Oracle adds a phase of −1 to the winning state |11⟩, effectively marking it.
• Diffusion Operator: The diffusion circuit (implemented as 𝐻 𝑋 𝐶𝑍 𝑋 𝐻) reflects all amplitudes about
the average. This inversion about the mean amplifies the amplitude of the marked state.

Walkthrough of the Algorithm and Generalization to 𝑛 Qubits


Grover’s algorithm can be summarized in the following pseudocode:
Algorithm 1: Grover’s Search Algorithm
Input: A function 𝑓 : {0, 1}𝑛 → {0, 1} with a unique marked state 𝑥0 such that 𝑓 (𝑥0 ) = 1.
Output: The marked element 𝑥 0 .
⊗𝑛
1 Initialize: Set the quantum state to 𝜓 ← |0⟩ .
2 Apply 𝐻
⊗𝑛 to obtain the uniform superposition:

1 Õ
|𝑠⟩ = 𝐻 ⊗𝑛 |0⟩ ⊗𝑛 = √ |𝑥⟩ .
2𝑛 𝑥∈{0 ,1}𝑛

 √ 
3 for 𝑖 = 1 to 𝜋4 2𝑛 do
4 Apply the Oracle 𝑂 which performs:
𝑂 |𝑥⟩ = (−1) 𝑓 (𝑥) |𝑥⟩ ,
(i.e., flip the phase of the marked state).;
5 Apply the Diffusion Operator 𝐷 = 2 |𝑠⟩ ⟨𝑠| − 𝐼 (which reflects amplitudes about the average).;
6 Measure the state in the computational basis to obtain 𝑥0 .;

Detailed Explanation:
1. Initialization: All qubits are set to |0⟩ and then put into an equal superposition via 𝐻 ⊗𝑛 .
2. Oracle Application: The Oracle selectively flips the phase of the winning state(s) (e.g., for the marked
state |𝑤⟩, 𝑂 |𝑤⟩ = − |𝑤⟩).
3. Diffusion (Inversion about the Mean): This operator reflects the state vector about the average
amplitude. Geometrically, one can view the process as a rotation in a two-dimensional subspace.

4. Iteration: Repeating the Oracle and Diffusion steps approximately 2𝑛 times amplifies the probability
amplitude of the marked state.
5. Measurement: Finally, a measurement in the computational basis yields the marked element with high
probability.
This algorithm demonstrates how quantum algorithms can achieve a quadratic speedup over classical brute-
force search methods.
2. Phase II: Fundamentals of Quantum Algorithms 34

2.3 Lecture 10: Quantum Logic Gates, Applying Grover’s Search


Algorithm to SAT
Review Question from Last Lecture
Question 13: Function of the Hadamard Layer in Grover’s Algorithm

Why does Grover’s algorithm apply a Hadamard (𝐻) gate to each of the 𝑛 qubits at the beginning of the
circuit?

Solution: The purpose of the Hadamard layer is that it allows up to work with all bitstring permutations
simultaneously by putting all states in equal superposition.
The Hadamard layer initializes the system in a uniform superposition of all possible 2𝑛 states, allowing
Grover’s algorithm to explore all bitstring permutations simultaneously. For 𝑛 qubits starting at |0⟩ ⊗𝑛 , applying
𝐻 ⊗𝑛 yields:
1 Õ
|𝑠⟩ = 𝐻 ⊗𝑛 |0⟩ ⊗𝑛 = √ |𝑥⟩.
2𝑛 𝑥∈{0,1}𝑛
This equal superposition ensures that the algorithm can amplify the amplitude of the solution state(s)
efficiently.

Quantum Implementations of Classical Logic Gates


OR Gate
The quantum OR gate computes 𝑐 = 𝑎 ∨ 𝑏 using a combination of CNOT and Toffoli gates. Below is the two-way
OR implementation:
|𝑎⟩

|𝑏⟩

|𝑐⟩
Truth Table:
𝑎 𝑏 𝑐 in 𝑐 out = 𝑎 ∨ 𝑏
0 0 0 0
0 1 0 1
1 0 0 1
1 1 0 1
The circuit uses CCNOT (Toffoli) to set 𝑐 if both 𝑎 and 𝑏 are 1, then CNOTs to flip 𝑐 if either 𝑎 or 𝑏 is 1,
effectively computing OR. NOT gates (𝑋) can be added to inputs for negated terms (e.g., ¬𝑎 ∨ ¬𝑏).

NOR Gate
A NOR gate (𝑐 = ¬(𝑎 ∨ 𝑏)) can be implemented by adding an 𝑋 gate on the output qubit after the OR circuit:

|𝑎⟩

|𝑏⟩

|𝑐⟩ 𝑋

Truth Table:
𝑎 𝑏 𝑐 in 𝑐 out = ¬(𝑎 ∨ 𝑏)
0 0 0 1
0 1 0 0
1 0 0 0
1 1 0 0
2. Phase II: Fundamentals of Quantum Algorithms 35

AND Gate
An AND gate (𝑐 = 𝑎 ∧ 𝑏) is directly implemented with a Toffoli gate:

|𝑎⟩
|𝑏⟩

|𝑐⟩

Truth Table:
𝑎 𝑏 𝑐 in 𝑐out = 𝑎 ∧ 𝑏
0 0 0 0
0 1 0 0
1 0 0 0
1 1 0 1

NAND Gate
A NAND gate (𝑐 = ¬(𝑎 ∧ 𝑏)) adds an 𝑋 gate after the AND:

|𝑎⟩
|𝑏⟩

|𝑐⟩ 𝑋

Truth Table:
𝑎 𝑏 𝑐 in 𝑐 out = ¬(𝑎 ∧ 𝑏)
0 0 0 1
0 1 0 1
1 0 0 1
1 1 0 0

Applying Grover’s Algorithm to SAT


Definition 2.3.1: Quantum Kickback

Quantum kickback occurs when a controlled operation transfers a phase from the target qubit to the
control qubit(s). In Grover’s algorithm, the oracle uses this to mark solution states. Consider a simple
example with a controlled-𝑋 and phase:
|+⟩

|−⟩

Initial state: |+⟩|−⟩ = √1 (|0⟩ + |1⟩) ⊗ √1 (|0⟩ − |1⟩) = 12 (|00⟩ − |01⟩ + |10⟩ − |11⟩).
2 2
After CNOT:
1 1 1
(|00⟩ − |01⟩ + |11⟩ − |10⟩) = √ (|0⟩ − |1⟩) ⊗ √ (|0⟩ − |1⟩) = |−⟩|−⟩.
2 2 2
The phase of the target (|−⟩) ”kicks back” to the control, flipping its relative phase. In Grover’s oracle, a
multi-controlled 𝑋 on an ancilla in |−⟩ state marks solutions with a −1 phase.

Implications of Quantum Kickback Quantum kickback enables efficient phase marking in Grover’s algorithm
without altering the computational basis states directly. It implies that:

• Ancilla qubits in superposition (e.g., |−⟩) can encode solution conditions.3


3 ancilla: extra qubits (beyond the clauses) that we need to complete the complete the computation
2. Phase II: Fundamentals of Quantum Algorithms 36

• The oracle’s design must ensure correct phase inversion for all satisfying assignments.
• When designing algorithms, we leverage kickback to avoid classical computation of each clause, reducing
circuit depth and enhancing quantum speedup.

Example 2.3.1 (Alexandria Ship Example)


In 48 BCE Alexandria, a merchant must maximize passengers on a ship to Italy under these constraints:

1. Arsinoe (A) won’t go if Cleopatra (C) is on the ship: ¬𝐴 ∨ ¬𝐶.


2. Arsinoe won’t go alone: ¬𝐴 ∨ 𝐽 ∨ 𝑃.
3. Ptolemy (P) only goes if Julius Caesar (J) goes: ¬𝑃 ∨ 𝐽.
4. Ptolemy won’t go if Cleopatra is on: ¬𝑃 ∨ ¬𝐶.

5. Julius Caesar must go: 𝐽.


6. Cleopatra won’t go if Julius Caesar is on: ¬𝐶 ∨ ¬𝐽.

Goal: Find the maximum number of passengers (A, C, J, P) satisfying all constraints using Grover’s
algorithm.

Creating SAT Clauses The problem is a SAT instance with clauses:

1. ¬𝐴 ∨ ¬𝐶 (Arsinoe-Cleopatra conflict).
2. ¬𝐴 ∨ 𝐽 ∨ 𝑃 (Arsinoe not alone).
3. ¬𝑃 ∨ 𝐽 (Ptolemy needs Caesar).
4. ¬𝑃 ∨ ¬𝐶 (Ptolemy-Cleopatra conflict).
5. 𝐽 (Caesar must go).
6. ¬𝐶 ∨ ¬𝐽 (Cleopatra-Caesar conflict).

These are implemented as OR gates in the quantum circuit, with an ancilla qubit per clause. The final
ancilla (𝑞 9 ) computes the AND of all clauses using a multi-controlled 𝑋, marking satisfying assignments with a
phase flip.

Cirq Implementation
Below is the Cirq code with detailed explanations:

1 import cirq

2 # Qubits: A=0, C=1, J=2, P=3, clause ancillas=4-8, final output=9


3 qubits = cirq.LineQubit.range(10)

4 def twoway_OR(circuit, a, b, c, not_a, not_b):


5 if not_a: circuit.append(cirq.X(a))
6 if not_b: circuit.append(cirq.X(b))
7 circuit.append(cirq.CCNOT(a, b, c)) # AND to target
8 circuit.append(cirq.CNOT(a, c)) # OR logic
9 circuit.append(cirq.CNOT(b, c))
10 if not_a: circuit.append(cirq.X(a))
11 if not_b: circuit.append(cirq.X(b))
12 return circuit
2. Phase II: Fundamentals of Quantum Algorithms 37

Lines 6-10 : Implements 𝑐 = 𝑎 ∨ 𝑏 by computing AND then adding single-qubit terms, with optional inversions
for negated inputs.

1 clauses_circuit = cirq.Circuit()
2 twoway_OR(clauses_circuit, qubits[0], qubits[1], qubits[4], 1, 1) # A or not C
3 threeway_OR(clauses_circuit, qubits[0], qubits[2], qubits[3], qubits[5], 1, 0, 0) # not A or J
↩→ or P
4 twoway_OR(clauses_circuit, qubits[1], qubits[2], qubits[6], 1, 1) # not C or not J
5 twoway_OR(clauses_circuit, qubits[1], qubits[3], qubits[7], 1, 1) # not C or not P
6 twoway_OR(clauses_circuit, qubits[2], qubits[3], qubits[8], 0, 1) # J or not P

7 oracle_circuit = cirq.Circuit()
8 oracle_circuit.append(clauses_circuit)
9 oracle_circuit.append(cirq.X(qubits[9]).controlled_by(qubits[2], qubits[4], qubits[5],
10 qubits[6], qubits[7], qubits[8]))
11 oracle_circuit.append(clauses_circuit)

Lines 11-14 : The oracle computes all clauses, then uses a multi-controlled 𝑋 on 𝑞 9 (in |−⟩ state) to flip the phase
of satisfying states, leveraging kickback.

1 final_circuit = cirq.Circuit()
2 final_circuit.append(cirq.H.on_each(qubits[0:4])) # Superposition
3 final_circuit.append(cirq.X(qubits[9])) # Prepare ancilla
4 final_circuit.append(cirq.H(qubits[9]))
5 final_circuit.append(oracle_circuit)
6 final_circuit.append(diffusion_circuit) # From notebook
7 final_circuit.append(cirq.measure(qubits[0:4][::-1], key='PJCA'))

Lines 5-7 : Initializes input qubits in superposition and ancilla in |−⟩, applies oracle and diffusion, then
measures.

Results from the Circuit Running the circuit with 8192 repetitions yields:

Counter({5: 2079, 13: 2043, 12: 2037, 4: 2033})

Converting to binary (PJCA order):

• 5 = 0101: 𝑃 = 0, 𝐽 = 1, 𝐶 = 0, 𝐴 = 1 (J, A).


• 13 = 1101: 𝑃 = 1, 𝐽 = 1, 𝐶 = 0, 𝐴 = 1 (P, J, A).
• 12 = 1100: 𝑃 = 1, 𝐽 = 1, 𝐶 = 0, 𝐴 = 0 (P, J).

• 4 = 0100: 𝑃 = 0, 𝐽 = 1, 𝐶 = 0, 𝐴 = 0 (J).

All solutions have 𝐽 = 1 (Caesar goes), 𝐶 = 0 (Cleopatra stays), and vary in A and P, satisfying all
constraints. The maximum passengers (3) is 𝑃 = 1, 𝐽 = 1, 𝐴 = 1, excluding Cleopatra, optimizing the merchant’s
goal.
We have shown how Grover’s Search Algorithm efficiently solves this SAT problem, amplifying valid con-
figurations quadratically faster than classical search!
However, when we look at the representation of this circuit, it is clear that there are some optimizations
that we can do to make it have a much shallower depth and not rely on so many ancilla qubits— which we will
fix in the next chapter.
2. Phase II: Fundamentals of Quantum Algorithms 38

2.4 Lecture 11: Quantum Circuit Optimizations


The biggest sources of inefficiencies from the Grover’s Search circuit that we saw at the end of the last lecture
were:

1. The way in which we implemented the multi-way OR gates.


2. The extensive use of ancilla qubits.

We will address both of these inefficiencies to get a shallower and simpler circuit.

More Efficient OR Gate Implementation


The original OR gate implementations (e.g., twoway OR, threeway OR) in Lecture 10 used multiple Toffoli and
CNOT gates, leading to high depth and gate redundancy. For example, the three-way OR (𝑑 = 𝑎 ∨ 𝑏 ∨ 𝑐) had a
depth of 6. We optimize this using a single multi-controlled NOT gate:

1 def OR(circuit, qubits, nots):


2 for index, is_not in enumerate(nots):
3 if not is_not:
4 circuit.append(cirq.X(qubits[index]))
5 circuit.append(cirq.X(qubits[-1]))
6 circuit.append(cirq.X(qubits[-1]).controlled_by(*qubits[:-1]))
7 for index, is_not in enumerate(nots):
8 if not is_not:
9 circuit.append(cirq.X(qubits[index]))
10 return circuit

Explanation:
• Lines 6-8 : Inverts the output qubit, then applies a multi-controlled 𝑋 (e.g., Toffoli for 2 inputs, CCCNOT
for 3) to flip it back only if all inputs are 0 (after negation if needed). This computes 𝑎 ∨ 𝑏 ∨ 𝑐 efficiently.
• Negations: 𝑋 gates preprocess inputs based on nots (0 for normal, 1 for negated), e.g., ¬𝑎 ∨ ¬𝑏 uses 𝑋 on
𝑎 and 𝑏.
Circuit Diagram (e.g., ¬𝑎 ∨ ¬𝑏):

|𝑎⟩ 𝑋 𝑋

|𝑏⟩ 𝑋 𝑋

|𝑐⟩

Truth Table:
𝑎 𝑏 𝑐 = ¬𝑎 ∨ ¬𝑏
0 0 1
0 1 1
1 0 1
1 1 0
Advantages:
• Reduces depth to 3 (two 𝑋 layers + one multi-controlled 𝑋) vs. 5 in twoway OR.

• Eliminates redundant CNOTs, e.g., in threeway OR, depth drops from 6 to 4.


• Scales efficiently for 𝑛-way OR with one 𝑛-controlled 𝑋 gate.
2. Phase II: Fundamentals of Quantum Algorithms 39

Applying this to the Alexandria ship clauses (e.g., ¬𝐴 ∨ ¬𝐶, ¬𝐴 ∨ 𝐽 ∨ 𝑃):

1 OR(clauses_circuit, [qubits[0], qubits[1], qubits[4]], [1, 1]) # NOT A OR NOT C


2 OR(clauses_circuit, [qubits[0], qubits[2], qubits[3], qubits[5]], [1, 0, 0]) # NOT A OR J OR P

This reduces gate count and depth per clause, improving the oracle’s efficiency.

Reducing Ancilla Qubits


Converting from CNF to ANF
The Lecture 10 CNF implementation used 6 ancilla qubits for the Alexandria ship problem’s clauses, scaling as
𝑂(# of clauses). Converting to Algebraic Normal Form (ANF) reduces this to 𝑂(1) ancilla—typically one—by
expressing the SAT problem as a single XOR polynomial.
CNF (Lecture 10):

(¬𝐴 ∨ ¬𝐶) ∧ (¬𝐴 ∨ 𝐽 ∨ 𝑃) ∧ (¬𝐶 ∨ ¬𝐽) ∧ (¬𝐶 ∨ ¬𝑃) ∧ 𝐽 ∧ (𝐽 ∨ ¬𝑃)

ANF Conversion (using SymPy):

1 from sympy import symbols, ANFform


2 P, J, C, A = symbols('P, J, C, A')
3 phrase = (~A | ~C) & (~A | J | P) & (~C | ~J) & (~C | ~P) & J & (J | ~P)
4 truth_table = [int(bool(phrase.subs({P: int(seq[0]), J: int(seq[1]), C: int(seq[2]), A:
↩→ int(seq[3])})))
5 for seq in itertools.product("01", repeat=4)]
6 anf = ANFform([P, J, C, A], truth_table) # Output: J XOR C J

Resulting ANF: 𝑓 = 𝐽 ⊕ 𝐶𝐽 (simplified form from truth table).


Truth Table Verification:
𝑃 𝐽 𝐶 𝐴 𝑓
0 0 0 0 0
0 0 0 1 0
0 0 1 0 0
0 0 1 1 0
0 1 0 0 1
0 1 0 1 1
0 1 1 0 0
0 1 1 1 0
1 0 0 0 0
1 0 0 1 0
1 0 1 0 0
1 0 1 1 0
1 1 0 0 1
1 1 0 1 1
1 1 1 0 0
1 1 1 1 0
Matches Lecture 10 solutions (e.g., 4=0100, 5=0101, 12=1100, 13=1101).

Oracle Implementation:

1 oracle_circuit = cirq.Circuit()
2 qubits = cirq.LineQubit.range(5) # A=0, C=1, J=2, P=3, out=4
3 oracle_circuit.append(cirq.CNOT(qubits[2], qubits[4])) # J
4 oracle_circuit.append(cirq.CCNOT(qubits[1], qubits[2], qubits[4])) # C J
2. Phase II: Fundamentals of Quantum Algorithms 40

Circuit Diagram:
|𝐴⟩
|𝐶⟩
|𝐽⟩
|𝑃⟩
|𝑜𝑢𝑡⟩

Advantages:
• Ancilla: Only 1 ancilla vs. 6, reducing qubit overhead.

• Depth: 2 gates (CNOT, Toffoli) vs. multiple OR gates plus a 6-controlled 𝑋.


• Generality: ANF conversion applies to any CNF, often simplifying to fewer terms.

Full Circuit Results (8192 runs):

Counter({5: 2075, 13: 2060, 4: 2047, 12: 2010})


Matches Lecture 10, confirming correctness.

Single Winner Case (A AND NOT C AND J AND P):

1 phrase = A & ~C & J & P


2 anf = ANFform([P, J, C, A], truth_table) # P J A XOR P J C A
3 oracle_circuit.append(cirq.X(qubits[4]).controlled_by(qubits[0], qubits[2], qubits[3]))
4 oracle_circuit.append(cirq.X(qubits[4]).controlled_by(qubits[0], qubits[1], qubits[2],
↩→ qubits[3]))

Results (3 iterations): High probability for 13=1101 (𝑃 = 1, 𝐽 = 1, 𝐶 = 0, 𝐴 = 1).

These optimizations reduce gate redundancy and ancilla usage, enhancing Grover’s efficiency for SAT
problems.

Looking at the Cirq circuit output, we can see how much simpler the circuit looks:

0: ---H---------------H---X-------@---X---H-------M-----------
| |
1: ---H-----------@---H---X-------@---X---H-------M-----------
| | |
2: ---H-------@---@---H---X-------@---X---H-------M-----------
| | | |
3: ---H---------------H---X---H---X---H---X---H---M('PJCA')---
| |
4: ---X---H---X---X-------------------------------------------
Chapter 3

Phase III: Advanced Quantum


Algorithms

3.1 Lecture 12: Introduction to Variational Quantum Algorithms


Before we can begin discussions on Quantum Approximate Optimization Algorithms (QAOA)1 , we must first
refine our conception of the classes of algorithms that are affected by quantum computing. Additionally, we
will get an introduction to a broader class of algorithms called variational quantum algorithms (VQA), of which
QAOA is a subset.

Classes of Algorithms
We can group algorithms into two classes: (1) those with proven quantum speedup and (2) those with not fully
proven quantum speedup.

Proven Quantum Speedup Algorithms


We have already seen one of these algorithms with Grover’s Algorithm, which has proven quadratic speedup.
√ problem over 𝑁 items, Grover’s algorithm reduces the complexity from 𝑂(𝑁) in
This means that for a search
classical computing to 𝑂( 𝑁) in the quantum domain. Other examples include:

• Shor’s Algorithm: Provides exponential speedup for integer factorization, reducing the complexity from
𝑂(exp((log 𝑁)1/3 )) to 𝑂((log 𝑁)3 ).
• Quantum Fourier Transform (QFT): Used in phase estimation, offering exponential speedup over
classical FFT for certain applications.

These algorithms leverage quantum superposition, entanglement, and interference to achieve rigorously
proven advantages, often validated through mathematical analysis of their unitary operators and measurement
probabilities.

Heuristic Quantum Algorithms


Heuristic quantum algorithms lack a fully proven speedup but show promise based on empirical evidence or
specific problem instances. These include:

• Quantum Approximate Optimization Algorithm (QAOA): A hybrid quantum-classical approach


for combinatorial optimization, conjectured to offer speedup for certain graphs, though the exact advantage
remains under investigation.
• Quantum Machine Learning (QML): Algorithms like quantum support vector machines or clustering
may provide polynomial or context-specific speedups, often relying on variational techniques (see below).
1 This class of algorithms are also interchangeably referred to as ”Quantum Alternating Operator Ansatz,” with ”ansatz” meaning

”guess” in German for reasons that will become clear in the next lectures.
3. Phase III: Advanced Quantum Algorithms 42

• Quantum Simulation: Simulating quantum systems (e.g., molecular dynamics) is believed to be expo-
nentially faster than classical methods, but the speedup depends on the Hamiltonian and is not universally
proven.

These algorithms often use an ”ansatz”—a parameterized guess for the quantum state—adjusted itera-
tively, making their performance problem-dependent and harder to analyze theoretically.
Definition 3.1.1: Ansatz

A trial wavefunction or trial state used as a starting point for approximations or optimizations. It is a
parameterized quantum state that serves as an educated guess for the solution to a particular problem,
such as finding the ground state of a quantum system.

Variational Quantum Algorithms (VQA)


Variational Quantum Algorithms (VQA) are a class of hybrid quantum-classical algorithms that optimize a
cost function by varying circuit parameters to achieve an objective. As noted in the lecture notes, they involve
”varying circuit parameters,” typically through a parameterized quantum circuit (the ansatz), followed by classical
optimization of the parameters based on measurement outcomes. Key features include:

• Hybrid Nature: A quantum circuit prepares a state 𝜓(𝜃) with parameters 𝜃, measured to compute a
cost 𝐶(𝜃), which a classical optimizer (e.g., gradient descent) minimizes.
• Applications: VQAs are used for optimization (e.g., QAOA), quantum chemistry (e.g., Variational Quan-
tum Eigensolver, VQE), and machine learning.
• Flexibility: The ansatz can be tailored to the problem, balancing expressiveness with hardware constraints
like qubit count and gate depth.

The general process is depicted as:


varying circuit classical optimization
𝜓(𝜃) −−−−−−−−−−−→ Measure 𝐶(𝜃) −−−−−−−−−−−−−−−−→ 𝜃opt

Advantages:
• Robust to noise in near-term quantum devices (NISQ).
• Scales with available quantum resources, unlike exact algorithms requiring deep circuits.

Challenges:
• Barren plateaus in the optimization landscape can hinder convergence.
• Ansatz design impacts solution quality and computational cost.

Example 3.1.1 (Toy Example: Bell State Preparation)


|00⟩+|11⟩
A simple VQA example is preparing a Bell state, such as |Φ+ ⟩ = √ , using a parameterized circuit.
2
Consider a circuit with a rotation gate 𝑅 𝑦 (𝜃) on one qubit followed by a CNOT:
Circuit Diagram:
|0⟩ 𝑅 𝑦 (𝜃)

|0⟩

Objective: Minimize the cost function 𝐶(𝜃) = 1 − |⟨Φ+ |𝜓(𝜃)⟩|2 , where 𝜓(𝜃) = CNOT · (𝑅 𝑦 (𝜃) |0⟩) ⊗ |0⟩.
3. Phase III: Advanced Quantum Algorithms 43

|0⟩+|1⟩
For 𝜃 = 𝜋/2, 𝑅 𝑦 (𝜋/2) |0⟩ = √ , and the circuit yields the Bell state exactly.
2
Truth Table (post-measurement probabilities):

𝑞0 𝑞1 𝑃(𝑞 0 , 𝑞1 )
0 0 0.5
0 1 0
1 0 0
1 1 0.5

This toy example illustrates parameter tuning to achieve a target state, a core concept in VQAs.

Cirq Implementation
Below is a Cirq implementation of the Bell state preparation:

1 import cirq
2 import numpy as np

3 # Define qubits
4 q0, q1 = cirq.LineQubit.range(2)

5 # Parameterized circuit
6 theta = np.pi / 2 # Optimal parameter
7 circuit = cirq.Circuit(
8 cirq.ry(theta).on(q0), # Rotation
9 cirq.CNOT(q0, q1) # Entanglement
10 )

11 # Simulate
12 simulator = cirq.Simulator()
13 result = simulator.simulate(circuit)
14 state = result.final_state_vector
15 print("Final state:", np.round(state, 3))

16 # Measure (8192 shots)


17 circuit.append(cirq.measure(q0, q1, key='result'))
18 samples = simulator.run(circuit, repetitions=8192)
19 counts = samples.histogram(key='result')
20 print("Counts:", counts)

Output Explanation:

• State Vector : Approximately [0.707, 0, 0, 0.707], matching |Φ+ ⟩.


• Counts: Roughly {0 : 4096, 3 : 4096} (binary 00 and 11), confirming 50% probability each.
This demonstrates a VQA’s ability to prepare a desired quantum state via parameter optimization, foun-
dational to more complex algorithms like QAOA.
3. Phase III: Advanced Quantum Algorithms 44

3.2 Lecture 13: Introduction to Quantum Approximate Optimization


Algorithms (QAOA)
Review
Question 14: VQA

What varies when running a variational quantum algorithm?

Solution: Rotation gate angles.

Question 15: Ansatz in QAOA

What does ”ansatz” refer to in Quantum Alternating Operator Ansatz (aka QAOA)?

Solution: Making a guess about the quantum circuit to use for optimization.

Quantum Approximate Optimization Algorithms


Definition 3.2.1: Quantum Approximate Optimization Algorithm (QAOA)

The Quantum Approximate Optimization Algorithm (QAOA) is a hybrid quantum-classical al-


gorithm within the Variational Quantum Algorithm (VQA) family, designed to approximate solutions
to combinatorial optimization problems (e.g., Max-Cut, graph coloring). Introduced by Farhi, Gold-
stone, and Gutmann, a QAOA uses a parameterized quantum circuit to prepare a state 𝜓(𝛾, 𝛽) whose
expectation value with respect to a cost Hamiltonian 𝐻𝐶 is minimized via classical optimization.
a ”A Quantum Approximate Optimization Algorithm”: https://arxiv.org/abs/1411.4028

QAOA Core Principle


Quantum circuit prepares state 𝜓(𝛾, 𝛽)
Classical optimizer adjusts 𝛾, 𝛽 to minimize
⟨𝜓(𝛾, 𝛽)|𝐻𝐶 |𝜓(𝛾, 𝛽)⟩

Figure 3.1: Conceptual view of QAOA as a hybrid quantum-classical algorithm

Core Ideas:
• Cost Hamiltonian (𝐻𝐶 ): Encodes the problem’s objective, e.g., 𝐻𝐶 = 𝑍 𝑖 𝑍 𝑗 for Max-Cut, where
Í
⟨𝑖,𝑗⟩
lower energy states correspond to better solutions.

• Mixing Hamiltonian (𝐻𝑀 ): Typically 𝐻𝑀 = 𝑋𝑖 , drives exploration across the solution space.
Í
𝑖

• Ansatz State: 𝜓(𝛾, 𝛽) = 𝑃𝑝=1 𝑒 −𝑖𝛽 𝑝 𝐻𝑀 𝑒 −𝑖𝛾𝑝 𝐻𝐶 |𝑠⟩, where |𝑠⟩ is a uniform superposition (e.g., 𝐻 ⊗𝑛 |0⟩ ⊗𝑛 ),
Î
and 𝑃 is the number of layers.

• Goal : Find 𝛾 = (𝛾1 , . . . , 𝛾𝑃 ) and 𝛽 = (𝛽 1 , . . . , 𝛽 𝑃 ) minimizing ⟨𝜓(𝛾, 𝛽)|𝐻𝐶 |𝜓(𝛾, 𝛽)⟩.


3. Phase III: Advanced Quantum Algorithms 45

Note:-
QAOA’s hybrid nature makes it suitable for Noisy Intermediate-Scale Quantum (NISQ) devices, as it relies
on shallow circuits and classical feedback loops.

Initialize qubits in |𝑠⟩ = 𝐻 ⊗𝑛 |0⟩ ⊗𝑛

Apply cost unitary 𝑒 −𝑖𝛾𝑝 𝐻𝐶

Repeat Apply mixing unitary 𝑒 −𝑖𝛽 𝑝 𝐻𝑀 Repeat for 𝑝 = 1 to 𝑃

Measure in computational basis

Optimize parameters 𝛾, 𝛽

Figure 3.2: QAOA algorithm workflow

Algorithm Steps:
1. Initialize: For 𝑛 qubits, apply Hadamard gates: |𝑠⟩ = 𝐻 ⊗𝑛 |0⟩ ⊗𝑛 = √1
Í
𝑥∈{0 ,1}𝑛 |𝑥⟩.
2𝑛

2. Apply Ansatz: For 𝑝 = 1 to 𝑃, apply 𝑒 −𝑖𝛾𝑝 𝐻𝐶 (cost evolution) followed by 𝑒 −𝑖𝛽 𝑝 𝐻𝑀 (mixing evolution).
3. Measure: Compute ⟨𝐻𝐶 ⟩ by measuring in the computational basis and calculating the expectation value.
4. Optimize: Use a classical algorithm (e.g., gradient descent, BFGS, Nelder-Mead) to adjust 𝛾𝑝 and 𝛽 𝑝
parameters.
5. Repeat: Iterate until ⟨𝐻𝐶 ⟩ converges to an approximate minimum or a set number of iterations is reached.

Max-Cut Example
Max-Cut is a classic combinatorial optimization problem where we aim to partition graph vertices into two sets,
maximizing the number (or weight) of edges crossing between the sets.

3 2

0 1

Figure 3.3: A 4-node cycle graph with an optimal Max-Cut solution (nodes colored by partition)

Consider a 4-node cycle graph with edges {(0, 1), (1, 2), (2, 3), (3, 0)} and weights 𝑤 𝑖𝑗 = 1. The Max-Cut
problem seeks a partition maximizing cut edges.

Cost Hamiltonian:

For the Max-Cut problem, the cost Hamiltonian is constructed as:


Õ 1 − 𝑍𝑖 𝑍 𝑗 1Õ
𝐻𝐶 = = constant − 𝑍𝑖 𝑍 𝑗
2 2
⟨𝑖,𝑗⟩ ⟨𝑖,𝑗⟩
3. Phase III: Advanced Quantum Algorithms 46

For our 4-node cycle graph, this becomes:


1
𝐻𝐶 = 2 − (𝑍0 𝑍1 + 𝑍1 𝑍2 + 𝑍2 𝑍3 + 𝑍3 𝑍0 )
2
Since the constant term doesn’t affect optimization, we typically use:

𝐻𝐶 ∝ −(𝑍0 𝑍1 + 𝑍1 𝑍2 + 𝑍2 𝑍3 + 𝑍3 𝑍0 )

Eigenstate |0101⟩ (alternating partition) has eigenvalue −4 (corresponding to 4 cuts, which is optimal).

Mixing Hamiltonian:
𝐻𝑀 = 𝑋0 + 𝑋1 + 𝑋2 + 𝑋3

The mixing Hamiltonian generates transitions between computational basis states, enabling exploration of
the solution space.

QAOA Circuit Implementation (𝑃 = 1):

𝑞0 : |0⟩ 𝐻 𝑅 𝑋 (2𝛽)

𝑞1 : |0⟩ 𝐻 𝑅 𝑍 (2𝛾) 𝑅 𝑋 (2𝛽)

𝑞2 : |0⟩ 𝐻 𝑅 𝑍 (2𝛾) 𝑅 𝑋 (2𝛽)

𝑞3 : |0⟩ 𝐻 𝑅 𝑋 (2𝛽)

Figure 3.4: Detailed QAOA circuit for the 4-node Max-Cut problem with 𝑃 = 1

• Implementing 𝑒 −𝑖𝛾𝑍 𝑖 𝑍 𝑗 : We use CNOTs and 𝑅 𝑍 (2𝛾) gates, since 𝑒 −𝑖𝛾𝑍 𝑖 𝑍 𝑗 = CNOT𝑖,𝑗 ·(𝐼 ⊗𝑅 𝑍 (2𝛾))·CNOT𝑖,𝑗 .

• Implementing 𝑒 −𝑖𝛽𝑋𝑖 : We can directly implement this with 𝑅 𝑋 (2𝛽) rotation gates.

Example 3.2.1 (Simplified Max-Cut Circuit (𝑃 = 1))


The QAOA ansatz for 𝑃 = 1 can be represented at a higher level as:

𝑞0 : |0⟩ 𝐻 𝑒 −𝑖𝛾𝑍0 𝑍1 𝑒 −𝑖𝛾𝑍3 𝑍0 𝑅 𝑋 (2𝛽)

𝑞1 : |0⟩ 𝐻 𝑒 −𝑖𝛾𝑍1 𝑍2 𝑅 𝑋 (2𝛽)

𝑞2 : |0⟩ 𝐻 𝑒 −𝑖𝛾𝑍2 𝑍3 𝑅 𝑋 (2𝛽)

𝑞3 : |0⟩ 𝐻 𝑅 𝑋 (2𝛽)

This structure clearly shows the alternating pattern of cost evolution (𝑒 −𝑖𝛾𝑍 𝑖 𝑍 𝑗 gates) followed by mixing
evolution (𝑅 𝑋 (2𝛽) gates).
3. Phase III: Advanced Quantum Algorithms 47

Circuit Implementation in Cirq


Here’s a complete QAOA circuit for the 4-qubit Max-Cut with 𝑃 = 1 using Google’s Cirq framework:

1 import cirq
2 import numpy as np
3 import matplotlib.pyplot as plt
4 from scipy.optimize import minimize

5 # Define the 4-node cycle graph


6 def get_graph():
7 edges = [(0, 1), (1, 2), (2, 3), (3, 0)]
8 return edges

9 # Create QAOA circuit for Max-Cut


10 def create_qaoa_circuit(qubits, edges, gamma, beta):
11 circuit = cirq.Circuit()

12 # Initialize with Hadamard gates


13 circuit.append(cirq.H.on_each(qubits))

14 # Apply cost Hamiltonian


15 for i, j in edges:
16 circuit.append(cirq.ZZPowGate(exponent=2*gamma/np.pi).on(qubits[i], qubits[j]))

17 # Apply mixing Hamiltonian


18 circuit.append(cirq.rx(2*beta).on_each(qubits))

19 return circuit

20 # Calculate Max-Cut expectation value from bitstring


21 def calculate_cut_value(bitstring, edges):
22 cut_value = 0
23 for i, j in edges:
24 if bitstring[i] != bitstring[j]:
25 cut_value += 1
26 return cut_value

27 # Main QAOA function


28 def run_qaoa_max_cut(gamma, beta, num_qubits=4, shots=8192):
29 qubits = cirq.LineQubit.range(num_qubits)
30 edges = get_graph()

31 # Create and run the circuit


32 circuit = create_qaoa_circuit(qubits, edges, gamma, beta)
33 measurement_circuit = circuit + cirq.measure(*qubits, key='result')

34 # Simulate
35 simulator = cirq.Simulator()
36 result = simulator.run(measurement_circuit, repetitions=shots)

37 # Process results
38 counts = result.histogram(key='result')

39 # Calculate expected cut value


40 expectation = 0
41 total_samples = sum(counts.values())

42 for bitstring, count in counts.items():


43 # Convert integer to binary representation
44 binary = format(bitstring, f'0{ num_qubits} b')
3. Phase III: Advanced Quantum Algorithms 48

45 cut_val = calculate_cut_value([int(bit) for bit in binary], edges)


46 expectation += cut_val * (count / total_samples)

47 return -expectation # Negative since we're minimizing

48 # Optimize parameters
49 def optimize_qaoa():
50 # Initial parameters
51 initial_params = [0.5, 0.5] # [gamma, beta]

52 # Perform optimization
53 result = minimize(
54 lambda params: run_qaoa_max_cut(params[0], params[1]),
55 initial_params,
56 method='COBYLA',
57 options={'maxiter': 100}
58 )

59 # Return optimized parameters


60 return result.x

61 # Execute full QAOA


62 gamma_opt, beta_opt = optimize_qaoa()
63 circuit = create_qaoa_circuit(cirq.LineQubit.range(4), get_graph(), gamma_opt, beta_opt)
64 print(f"Optimized parameters: gamma={ gamma_opt} , beta={ beta_opt} ")
65 print(f"Estimated Max-Cut: { -run_qaoa_max_cut(gamma_opt, beta_opt)} ")

QAOA Advantages
• NISQ Compatibility: QAOA uses shallow circuits (small 𝑃), making it feasible on current noisy quantum
hardware without error correction.
• Theoretical Guarantees: For 𝑃 → ∞, QAOA approaches the exact solution, resembling adiabatic quan-
tum computation2 .
• Problem Flexibility: Can be adapted to many NP-hard problems by appropriate encoding of the cost
Hamiltonian.

Aside

The connection to adiabatic computation suggests QAOA’s theoretical power, but practical limits (e.g.,
noise, coherence time) often restrict 𝑃 to small values in current hardware.

2 Farhi et al. demonstrated that QAOA with 𝑃 → ∞ converges to the adiabatic quantum algorithm, which provides a theoretical

foundation for QAOA’s potential quantum advantage.


3. Phase III: Advanced Quantum Algorithms 49

Performance

Theoretical

NISQ Reality

𝑃 (circuit depth)
Practical limit

Figure 3.5: Theoretical vs. practical QAOA performance as function of circuit depth 𝑃

QAOA Limitations
• Barren Plateaus: For large problem sizes, the optimization landscape can become exponentially flat in
certain regions, making it difficult for classical optimizers to find good parameters3 .
• Unproven Quantum Advantage: No guaranteed polynomial speedup over classical algorithms has been
proven for general cases; performance depends on the specific problem instance and 𝑃.
• Parameter Optimization Challenges: Finding optimal 𝛾 and 𝛽 parameters becomes increasingly diffi-
cult as 𝑃 and problem size grow.

3.3 Lecture 14: More on QAOA: Cost and Mixer Hamiltonians, Full
Circuit
Review
Question 16: QAOA Components

What are the two main components that alternate in a QAOA circuit?

Solution: The two main components are:


1. Cost evolution operator: 𝑒 −𝑖𝛾𝑝 𝐻𝐶 , which encodes the problem’s objective function
2. Mixing evolution operator: 𝑒 −𝑖𝛽 𝑝 𝐻𝑀 , which explores the solution space

Cost Hamiltonians in Detail


Definition 3.3.1: Cost Hamiltonian

The Cost Hamiltonian 𝐻𝐶 in QAOA encodes the objective function of the optimization problem. It is
designed such that its ground state (lowest energy eigenstate) corresponds to the optimal solution of the
classical problem.

Properties of Cost Hamiltonians:


• Diagonal in computational basis: 𝐻𝐶 is typically diagonal in the 𝑍-basis, making measurements
straightforward.
• Problem-specific: Each optimization problem requires a different 𝐻𝐶 .
• Locality: Many practical 𝐻𝐶 terms involve only a few qubits (e.g., 2-local terms like 𝑍 𝑖 𝑍 𝑗 for Max-Cut).
3 McClean et al., ”Barren plateaus in quantum neural network training landscapes”, https://arxiv.org/abs/1803.11173
3. Phase III: Advanced Quantum Algorithms 50

Example 3.3.1 (Max-𝑘-SAT Cost Hamiltonian)


For the Max-𝑘-SAT problem, each clause 𝑐 is encoded as an operator 𝐶 𝑐 . For example, the clause (𝑥1 ∨
¬𝑥 2 ∨ 𝑥 3 ) is encoded as:
𝐼 − 𝑍1 𝐼 + 𝑍2 𝐼 − 𝑍3
𝐶𝑐 = · ·
2 2 2
The overall cost Hamiltonian is: Õ1−𝐶
𝑐
𝐻𝐶 =
𝑐
2
This gives higher energy to states that satisfy more clauses.

Cost Hamiltonian 𝐻𝐶

Max-Cut Max-SAT Max Independent Set

Í 1−𝑍 𝑖 𝑍 𝑗 Í 1−𝐶 𝑐
(𝑖,𝑗)∈𝐸 𝑐
Í 1−𝑍 𝑖
2 2
𝑖∈𝑉 2 −
Í (1−𝑍 𝑖 )(1−𝑍 𝑗 )
(𝑖,𝑗)∈𝐸 4

Figure 3.6: Different cost Hamiltonians for various optimization problems

Implementing Cost Hamiltonians


The operator 𝑒 −𝑖𝛾𝐻𝐶 can be challenging to implement directly. When 𝐻𝐶 consists of terms that commute with
each other, we can decompose the exponential:
Ö
ℎ𝑗
Í
𝑒 −𝑖𝛾𝐻𝐶 = 𝑒 −𝑖𝛾 𝑗 = 𝑒 −𝑖𝛾ℎ 𝑗
𝑗

For the Max-Cut problem, each term is of the form 𝑍 𝑖 𝑍 𝑗 , and we can implement 𝑒 −𝑖𝛾𝑍 𝑖 𝑍 𝑗 using the
following circuit:

𝑞𝑖

𝑞𝑗 𝑅 𝑍 (2𝛾)

Figure 3.7: Circuit for implementing 𝑒 −𝑖𝛾𝑍 𝑖 𝑍 𝑗

Note:-
The decomposition 𝑒 −𝑖𝛾𝐻𝐶 = 𝑗 𝑒 −𝑖𝛾ℎ 𝑗 is only valid when all terms ℎ 𝑗 commute. For non-commuting terms,
Î
more sophisticated techniques like Trotter-Suzuki decomposition are required.
3. Phase III: Advanced Quantum Algorithms 51

Mixer Hamiltonians in Detail


Definition 3.3.2: Mixer Hamiltonian

The Mixer Hamiltonian 𝐻𝑀 in QAOA drives the exploration of the solution space. It is typically chosen
to be non-commuting with the cost Hamiltonian 𝐻𝐶 to enable transitions between different states in the
computational basis.

Standard Mixer:
Í𝑛
• The most common mixer is the transverse field: 𝐻𝑀 = 𝑖=1 𝑋𝑖
• Implemented directly as 𝑅 𝑋 (2𝛽) gates on each qubit
• Allows exploration of the entire 2𝑛 solution space

𝑞1 𝑅 𝑋 (2𝛽)

𝑞2 𝑅 𝑋 (2𝛽)

.. .. ..
. . .

𝑞𝑛 𝑅 𝑋 (2𝛽)

Figure 3.8: Circuit for implementing the standard mixer 𝑒 −𝑖𝛽 𝑋𝑖


Í
𝑖

Advanced Mixers:

• Problem-specific mixers: Designed to preserve constraints of the problem


• XY mixers: 𝐻𝑀 = (𝑖,𝑗)∈𝐸 (𝑋 𝑖 𝑋 𝑗 + 𝑌𝑖 𝑌𝑗 ) for problems with hard constraints
Í

• Controlled mixers: Conditionally apply mixing operations based on constraint satisfaction

Example 3.3.2 (XY Mixer for Number-Preserving Problems)


For problems where the total number of 1s must remain constant (e.g., graph coloring with a fixed number
of colors), an XY mixer can be used:
Õ Õ
𝑋𝑌
𝐻𝑀 = (𝑋𝑖 𝑋 𝑗 + 𝑌𝑖 𝑌𝑗 ) = (|01⟩⟨10| + |10⟩⟨01|) (3.1)
𝑖<𝑗 𝑖<𝑗

This mixer only swaps 0s and 1s between qubits, preserving the total Hamming weight of the state.
Implementation requires more complex gate sequences.

𝑞𝑖 𝐻 𝐻

𝑞𝑗 𝐻 𝑅 𝑍 (2𝛽) 𝐻

Figure 3.9: Implementation of one term in the XY mixer


3. Phase III: Advanced Quantum Algorithms 52

Full QAOA Circuit Implementation


Definition 3.3.3: QAOA Circuit Depth

The QAOA circuit depth parameter 𝑃 determines how many alternating layers of cost and mixer
operators are applied. Higher 𝑃 typically leads to better approximation quality but increases circuit
complexity.

Circuit for QAOA with Depth 𝑃:

𝑞1 𝐻 𝑅 𝑋 (2𝛽 1 ) 𝑅 𝑋 (2𝛽 2 ) ... 𝑅 𝑋 (2𝛽 𝑃 )

𝑞2 𝐻 𝑒 −𝑖𝛾1 𝐻𝐶 𝑅 𝑋 (2𝛽 1 ) 𝑒 −𝑖𝛾2 𝐻𝐶 𝑅 𝑋 (2𝛽 2 ) ... 𝑒 −𝑖𝛾𝑃 𝐻𝐶 𝑅 𝑋 (2𝛽 𝑃 )

𝑞𝑛 𝐻 𝑅 𝑋 (2𝛽 1 ) 𝑅 𝑋 (2𝛽 2 ) ... 𝑅 𝑋 (2𝛽 𝑃 )

Figure 3.10: General structure of a QAOA circuit with depth 𝑃

The circuit consists of:


1. Initial state preparation: 𝐻 ⊗𝑛 |0⟩ ⊗𝑛
2. 𝑃 repetitions of:

• Cost operator: 𝑒 −𝑖𝛾𝑝 𝐻𝐶


• Mixer operator: 𝑒 −𝑖𝛽 𝑝 𝐻𝑀
3. Final measurement in the computational basis

Example 3.3.3 (Full Max-Cut QAOA Circuit for 𝑃 = 2)


For a 4-node cycle graph (Max-Cut problem) with 𝑃 = 2:

𝑞0 𝐻 𝑒 −𝑖𝛾1 𝑍0 𝑍1 𝑒 −𝑖𝛾1 𝑍0 𝑍3 𝑅 𝑋 (2𝛽 1 ) 𝑒 −𝑖𝛾2 𝑍0 𝑍1 𝑒 −𝑖𝛾2 𝑍0 𝑍3 𝑅 𝑋 (2𝛽 2 )

𝑞1 𝐻 𝑒 −𝑖𝛾1 𝑍1 𝑍2 𝑅 𝑋 (2𝛽 1 ) 𝑒 −𝑖𝛾2 𝑍1 𝑍2 𝑅 𝑋 (2𝛽 2 )

𝑞2 𝐻 𝑅 𝑋 (2𝛽 1 ) 𝑅 𝑋 (2𝛽 2 )

𝑞3 𝐻 𝑒 −𝑖𝛾1 𝑍2 𝑍3 𝑅 𝑋 (2𝛽 1 ) 𝑒 −𝑖𝛾2 𝑍2 𝑍3 𝑅 𝑋 (2𝛽 2 )

Figure 3.11: QAOA circuit for Max-Cut on a 4-node cycle with 𝑃 = 2

Note that for clarity, the implementation of 𝑒 −𝑖𝛾𝑍 𝑖 𝑍 𝑗 with CNOT and 𝑅 𝑍 gates is not shown explicitly in
this diagram.
3. Phase III: Advanced Quantum Algorithms 53

Parameter Optimization Strategies


Definition 3.3.4: QAOA Parameter Optimization

The process of finding optimal values for the parameters 𝛾 = (𝛾1 , . . . , 𝛾𝑃 ) and 𝛽 = (𝛽1 , . . . , 𝛽 𝑃 ) to minimize
the expectation value ⟨𝜓(𝛾, 𝛽)|𝐻𝐶 |𝜓(𝛾, 𝛽)⟩.

Classical Optimization Methods:

• Gradient-free methods: Nelder-Mead, COBYLA, Powell


• Gradient-based methods: BFGS, L-BFGS, SPSA
• Global optimization: Basin-hopping, Differential Evolution

Algorithm 2: QAOA Parameter Optimization


Input : Problem Hamiltonian 𝐻𝐶 , Mixing Hamiltonian 𝐻𝑀 , Number of layers 𝑃
Output: Optimized parameters 𝛾 ∗ , 𝛽 ∗
1 Initialize parameters 𝛾 = (𝛾1 , . . . , 𝛾𝑃 ) and 𝛽 = (𝛽 1 , . . . , 𝛽 𝑃 );
2 Initialize optimizer (e.g., COBYLA, BFGS);
3 Function CostFunction(𝛾, 𝛽):
4 Prepare state 𝜓(𝛾, 𝛽) using QAOA circuit;
5 Measure 𝜓(𝛾, 𝛽) 𝐻𝐶 𝜓(𝛾, 𝛽) (multiple shots);
6 return Measured expectation value;
7 while not converged do
8 Evaluate CostFunction(𝛾, 𝛽);
9 Update 𝛾, 𝛽 using optimization algorithm step;
10 return Optimized parameters 𝛾 ∗ , 𝛽∗ ;

Optimization Challenges:
• Barren plateaus: Gradients become exponentially small in high dimensions

• Local minima: Many local optima can trap optimizers


• Noise effects: Hardware noise affects optimization landscape
• Shot noise: Finite measurement samples introduce uncertainty in cost evaluation

Example 3.3.4 (Parameter Initialization Strategies)


Different initialization strategies for QAOA parameters:

• Random initialization: Start with random values in [0, 𝜋] for both 𝛾 and 𝛽.
𝑝 𝑝
• Linear ramps: Initialize 𝛾𝑝 = 𝑃 · 𝜋 and 𝛽 𝑝 = (1 − 𝑃 ) · 𝜋2 .
• Educated guess: For Max-Cut, good initial points are known analytically for 𝑃 = 1: 𝛾 ≈ 0.785
and 𝛽 ≈ 0.393.
• Layer-by-layer training: Optimize parameters for 𝑃 = 1, then use them to initialize the first layer
of 𝑃 = 2, etc.
3. Phase III: Advanced Quantum Algorithms 54

−2

⟨𝐻𝐶 ⟩
−3

−4
0 1.5
1 1
2 0.5
𝛾 3 0 𝛽

Figure 3.12: Example landscape for Max-Cut QAOA with 𝑃 = 1 on a 4-node cycle graph. The red dot
indicates the optimal parameters.

Theoretical Insights for QAOA


Adiabatic Quantum Computing Connection:

• As 𝑃 → ∞, QAOA approximates adiabatic quantum computing


• QAOA with optimal parameters can outperform the standard adiabatic algorithm
• For 𝑃 = 𝑝𝑜𝑙 𝑦(𝑛), QAOA can capture quantum advantage for certain problems

Note:-
The connection to adiabatic quantum computing suggests that QAOA can potentially solve NP-hard problems
efficiently for specific instances, though this is not guaranteed in general.

Concentration of Parameters:
• For certain problems, optimal QAOA parameters concentrate (become instance-independent) as problem
size grows

• This allows precomputing parameters for problem classes rather than instances
• Particularly relevant for local cost functions like Max-Cut on regular graphs

Example 3.3.5 (Parameter Concentration Example)


For Max-Cut on 3-regular graphs, optimal 𝛾 and 𝛽 values for 𝑃 = 1 are nearly identical across different
random instances as the number of vertices increases. This means we can reuse the same parameters for
any 3-regular graph without instance-specific optimization.
3. Phase III: Advanced Quantum Algorithms 55

1.5

Optimal parameter values


1

0.5
𝛾
𝛽
0
10 20 30 40 50 60
Number of vertices 𝑛

Figure 3.13: Parameter concentration for Max-Cut QAOA on 3-regular graphs

3.4 Lecture 15: Wrapping Up QAOA: Intro to Coding in PennyLane,


QUBO
Review
Question 17: QAOA Circuit

What are the main components of a QAOA circuit and how are they arranged?

Solution: A QAOA circuit consists of:


1. Initial state preparation: Apply Hadamard gates to create equal superposition 𝐻 ⊗𝑛 |0⟩ ⊗𝑛
2. 𝑃 alternating layers of:
• Cost operator: 𝑒 −𝑖𝛾𝑝 𝐻𝐶 which encodes the problem’s objective function
• Mixer operator: 𝑒 −𝑖𝛽 𝑝 𝐻𝑀 which explores the solution space
3. Final measurement in the computational basis

PennyLane
Definition 3.4.1: PennyLane

PennyLane is an open-source software framework for quantum machine learning, quantum computing, and
quantum chemistry. It enables users to train quantum circuits in the same way as neural networks, using
automatic differentiation techniques from machine learning.

Key Features of PennyLane:


• Hybrid quantum-classical computation: Seamlessly connects classical machine learning libraries with
quantum processing units
• Automatic differentiation: Computes gradients of quantum circuits for optimization tasks
• Hardware agnostic: Works with multiple quantum computing platforms and simulators
• Built-in optimizers: Includes various classical optimization algorithms
• Quantum machine learning toolkit: Provides implementations of common quantum algorithms and
models
3. Phase III: Advanced Quantum Algorithms 56

Qiskit Cirq Forest

PennyLane

PyTorch TensorFlow JAX

Figure 3.14: PennyLane connects classical ML frameworks with quantum computing platforms

Basic Structure of a PennyLane Program:


1. Define a quantum device
2. Create a quantum circuit using a QNode decorator

3. Define a cost function


4. Optimize the circuit parameters

1 # Basic PennyLane workflow


2 import pennylane as qml
3 from pennylane import numpy as np

4 # 1. Define a device
5 dev = qml.device("default.qubit", wires=4)

6 # 2. Define a quantum circuit (QNode)


7 @qml.qnode(dev)
8 def circuit(params):
9 # Prepare initial state
10 for i in range(4):
11 qml.Hadamard(wires=i)

12 # Apply parameterized gates


13 qml.RX(params[0], wires=0)
14 qml.RY(params[1], wires=1)

15 # Return expectation values


16 return qml.expval(qml.PauliZ(0))

17 # 3. Run the circuit


18 params = np.array([0.1, 0.2], requires_grad=True)
19 result = circuit(params)

QAOA Implementation in PennyLane Here’s how to implement QAOA for MaxCut in PennyLane:

1 import pennylane as qml


3. Phase III: Advanced Quantum Algorithms 57

2 import networkx as nx
3 from pennylane import numpy as np

4 # Define the graph


5 edges = [(0, 1), (0, 2), (0, 3), (1, 2), (2, 3)]
6 graph = nx.Graph(edges)

7 # Get the MaxCut cost and mixer Hamiltonians


8 C, B = qml.qaoa.maxcut(graph)

9 # Define the number of layers


10 L = 1
11 num_qubits = 4
12 qubits = range(num_qubits)

13 # Define the QAOA layers


14 def qaoa_layer(gamma, beta):
15 qml.qaoa.cost_layer(gamma, C)
16 qml.qaoa.mixer_layer(beta, B)

17 # Define the full circuit


18 def circuit(params, **kwargs):
19 for qubit in qubits:
20 qml.Hadamard(wires=qubit)
21 qml.layer(qaoa_layer, L, params[0], params[1])

22 # Create a quantum device


23 dev = qml.device("default.qubit", wires=qubits)

24 # Define the cost function


25 @qml.qnode(dev)
26 def cost_function(params):
27 circuit(params)
28 return qml.expval(C)

29 # Optimize the parameters


30 optimizer = qml.AdagradOptimizer(stepsize=0.1)
31 steps = 50
32 params = np.array([[np.random.random()*2*np.pi],
33 [np.random.random()*2*np.pi]],
34 requires_grad=True)

35 for i in range(steps):
36 params = optimizer.step(cost_function, params)

37 print("Optimal Cost:", cost_function(params))


38 print("Optimal Parameters:", params)

Note:-
PennyLane’s built-in QAOA module simplifies implementation by automatically constructing the cost and
mixer Hamiltonians for problems like MaxCut. The qml.layer function is useful for applying repeated layers
with different parameters.
3. Phase III: Advanced Quantum Algorithms 58

Quadratic Unconstrained Binary Optimization (QUBO)


Definition 3.4.2: Quadratic Unconstrained Binary Optimization (QUBO)

QUBO is a mathematical optimization model involving binary variables with a quadratic objective func-
tion. It can be expressed as minimizing:
𝑛 Õ
Õ 𝑛
𝑓 (x) = x𝑇 𝑄x = 𝑄 𝑖𝑗 𝑥 𝑖 𝑥 𝑗
𝑖=1 𝑗=1

where x ∈ {0, 1}𝑛 is a binary vector, and 𝑄 is an 𝑛 × 𝑛 real-valued matrix representing the coefficients of
the objective function.

QUBO Formulation:
• Linear terms: Represented on the diagonal of 𝑄 (𝑄 𝑖𝑖 )
• Quadratic terms: Represented on the off-diagonal elements of 𝑄 (𝑄 𝑖𝑗 where 𝑖 ≠ 𝑗)
• Can represent many NP-hard problems, including MaxCut, graph coloring, and traveling salesman problem

Example 3.4.1 (Job Priorities)


Consider a scheduling problem with 6 jobs (𝐽0 to 𝐽5 ) where each job has a priority value 𝐶 𝑖 and there are
interference costs 𝐼 𝑖𝑗 if jobs 𝑖 and 𝑗 are scheduled together.

• Decision variables: 𝑥 𝑖 = 1 if job 𝑖 is selected, 0 otherwise


• Priority values: 𝐶 𝑖 represents the value of completing job 𝑖

• Interference costs: 𝐼 𝑖𝑗 represents the penalty if both jobs 𝑖 and 𝑗 are selected

The QUBO formulation is:


5
Õ 5 Õ
Õ 5
Maximize 𝑓 (𝑥) = 𝐶𝑖 𝑥𝑖 − 𝐼 𝑖𝑗 𝑥 𝑖 𝑥 𝑗
𝑖=0 𝑖=0 𝑗>𝑖

This can be rewritten in matrix form:


𝑓 (𝑥) = x𝑇 𝑄x
where 𝑄 is a 6×6 matrix with:
• Diagonal elements 𝑄 𝑖𝑖 = 𝐶 𝑖 (job priorities)
𝐼 𝑖𝑗
• Off-diagonal elements 𝑄 𝑖𝑗 = − 2 (interference costs)

For a QAOA implementation, we convert this to an Ising Hamiltonian by substituting 𝑥 𝑖 = 1+𝑠 𝑖


2 , resulting
in a Hamiltonian with 𝑍 𝑖 terms (for individual job priorities) and 𝑍 𝑖 𝑍 𝑗 terms (for job interferences).

QUBO in Code

1 import pennylane as qml


2 import numpy as np
3 import networkx as nx

4 # Define a QUBO problem


5 num_qubits = 6 # 6 jobs
3. Phase III: Advanced Quantum Algorithms 59

6 np.random.seed(42)

7 # Generate random job priorities and interference costs


8 priorities = np.random.uniform(1, 10, size=num_qubits)
9 interferences = np.random.uniform(0, 5, size=(num_qubits, num_qubits))
10 interferences = (interferences + interferences.T) / 2 # Make symmetric
11 np.fill_diagonal(interferences, 0) # No self-interference

12 # Create QUBO matrix


13 Q = np.zeros((num_qubits, num_qubits))
14 for i in range(num_qubits):
15 Q[i, i] = priorities[i] # Diagonal elements are priorities
16 for j in range(num_qubits):
17 if i != j:
18 Q[i, j] = -interferences[i, j] / 2 # Off-diagonals are -interferences/2

19 # Convert QUBO to Ising Hamiltonian


20 def qubo_to_ising(Q):
21 n = Q.shape[0]
22 J = np.zeros((n, n))
23 h = np.zeros(n)
24 offset = 0

25 for i in range(n):
26 for j in range(n):
27 if i == j:
28 h[i] += Q[i, i] / 2
29 offset += Q[i, i] / 4
30 else:
31 J[i, j] = Q[i, j] / 4
32 h[i] += Q[i, j] / 4
33 offset += Q[i, j] / 4

34 return h, J, offset

35 h, J, offset = qubo_to_ising(Q)

36 # Create a PennyLane device


37 dev = qml.device("default.qubit", wires=range(num_qubits))

38 # Define the cost Hamiltonian operator


39 def cost_hamiltonian(h, J):
40 obs = []
41 # Single-qubit terms
42 for i, coeff in enumerate(h):
43 if abs(coeff) > 1e-10:
44 obs.append(coeff * qml.PauliZ(i))

45 # Two-qubit terms
46 for i in range(num_qubits):
47 for j in range(i+1, num_qubits):
48 if abs(J[i, j]) > 1e-10:
49 obs.append(J[i, j] * qml.PauliZ(i) @ qml.PauliZ(j))

50 return qml.Hamiltonian(coeffs=[1.0] * len(obs), observables=obs)

51 # Create the cost Hamiltonian


52 H_C = cost_hamiltonian(h, J)

53 # Define the mixer Hamiltonian


54 H_M = qml.Hamiltonian(
3. Phase III: Advanced Quantum Algorithms 60

55 coeffs=[1.0] * num_qubits,
56 observables=[qml.PauliX(i) for i in range(num_qubits)]
57 )

58 # Define the QAOA layers


59 def qaoa_layer(gamma, beta):
60 qml.exp(H_C, gamma)
61 qml.exp(H_M, beta)

62 # Define the QAOA circuit


63 @qml.qnode(dev)
64 def qaoa_circuit(params, p=1):
65 # Initial state
66 for i in range(num_qubits):
67 qml.Hadamard(wires=i)

68 # QAOA layers
69 for i in range(p):
70 qaoa_layer(params[2*i], params[2*i+1])

71 # Return expectation value of the cost Hamiltonian


72 return qml.expval(H_C)

73 # Optimize the QAOA parameters


74 p = 1 # Number of QAOA layers
75 params = np.random.uniform(0, 2*np.pi, size=2*p)
76 steps = 100
77 optimizer = qml.GradientDescentOptimizer(stepsize=0.1)

78 for i in range(steps):
79 params = optimizer.step(lambda p: qaoa_circuit(p, p=p), params)
80 if i % 10 == 0:
81 cost = qaoa_circuit(params, p=p)
82 print(f"Step { i} : Cost = { cost} ")

83 # Final cost
84 final_cost = qaoa_circuit(params, p=p)
85 print(f"Final cost: { final_cost} ")
86 print(f"Optimal parameters: { params} ")

87 # Execute circuit with optimal parameters and measure in computational basis


88 @qml.qnode(dev)
89 def qaoa_measure(params, p=1):
90 # Initial state
91 for i in range(num_qubits):
92 qml.Hadamard(wires=i)

93 # QAOA layers
94 for i in range(p):
95 qaoa_layer(params[2*i], params[2*i+1])

96 # Return samples in computational basis


97 return qml.sample(wires=range(num_qubits))

98 # Get samples
99 n_samples = 1000
100 samples = qaoa_measure(params, p=p)
101 samples = np.array([samples for _ in range(n_samples)])

102 # Convert to binary solutions


103 binary_samples = (samples + 1) // 2 # Convert from {-1,1} to {0,1}
3. Phase III: Advanced Quantum Algorithms 61

104 # Evaluate the original QUBO objective for each sample


105 def evaluate_qubo(x, Q):
106 return x.T @ Q @ x

107 # Find the best solution


108 best_cost = float('inf')
109 best_solution = None
110 for sample in binary_samples:
111 cost = evaluate_qubo(sample, Q)
112 if cost < best_cost:
113 best_cost = cost
114 best_solution = sample

115 print(f"Best solution found: { best_solution} ")


116 print(f"Best solution cost: { best_cost} ")

Note:-
The code demonstrates converting a QUBO problem into an Ising Hamiltonian and solving it with QAOA in
PennyLane. Key points:

• The job scheduling problem is transformed into a QUBO matrix 𝑄


• The QUBO-to-Ising conversion involves a variable transformation from 𝑥 𝑖 ∈ {0, 1} to 𝑠 𝑖 ∈ {−1, +1}
• The Ising Hamiltonian has single-qubit 𝑍 𝑖 terms (from job priorities) and two-qubit 𝑍 𝑖 𝑍 𝑗 terms (from
job interferences)

• The QAOA circuit alternates between problem Hamiltonian evolution and mixer Hamiltonian evolution
• Multiple samples are taken to find the best binary solution to the original problem

Key Takeaways from QAOA Implementation


• QAOA is a versatile algorithm that can be applied to various combinatorial optimization problems
• The QUBO formulation provides a standardized approach to encode optimization problems for quantum
algorithms
• PennyLane simplifies the implementation of quantum algorithms with its high-level abstractions and auto-
matic differentiation
• The performance of QAOA depends on several factors:
– Number of layers (𝑝)
– Choice of classical optimizer
– Initial parameter values
– Problem structure and size
• QAOA represents a promising approach for quantum advantage in the NISQ era, especially for problems
with efficient problem Hamiltonian implementations

Practical Considerations
When implementing QAOA for real-world problems, consider:

• Problem encoding efficiency: Different encodings may lead to circuits of varying depths and complexities
3. Phase III: Advanced Quantum Algorithms 62

• Parameter initialization: Good initial parameters can significantly speed up convergence


• Hardware constraints: Consider connectivity limitations and noise characteristics of actual quantum
hardware
• Classical preprocessing: Many problems benefit from classical preprocessing before quantum solving
• Hybrid approaches: Combining quantum and classical algorithms often yields the best results in practice
Chapter 4

Phase IV: Special Topics in Quantum


Computing

4.1 Lecture 16: Quantum Compiler Optimizations


Review
Question 18: Number of 𝐶𝑋 Gates

How many 𝐶𝑋 gates are required to implement the following QUBO cost function:

𝑐(𝑥) = 0.1𝑥1 𝑥 2 + 0.0𝑥 0 𝑥2 + 0.2𝑥 1 𝑥2 + 0.3𝑥 0 𝑥 1

Solution: To implement this QUBO cost function, we need to count the number of unique two-qubit interactions:

• 𝑥1 𝑥 2 : appears twice (0.1 and 0.2)


• 𝑥0 𝑥 1 : appears once (0.3)
• 𝑥0 𝑥 2 : appears once (0.0, but still requires a gate)

These interactions suggest 4 distinct 𝐶𝑋 gates are required, noting that repeated interactions don’t neces-
sarily increase gate count.
4

Overview of Quantum Compilers


Until now, we have primarily explored quantum algorithms through simulation and theoretical models. However,
translating these algorithms to actual quantum hardware requires sophisticated compilation techniques. Quantum
compilers bridge the gap between theoretical quantum circuits and physical quantum processors by addressing
several key challenges:

• Hardware Constraints: Different quantum hardware have varying gate sets, qubit connectivity, and noise
characteristics
• Circuit Optimization: Reducing the number of gates and circuit depth to mitigate quantum decoherence
• Error Mitigation: Transforming circuits to be more resilient to quantum noise
• Basis Gate Translation: Converting high-level quantum gates to hardware-native gate sets

Compilers apply logical operations to optimize certain desirable metrics to make the execution of a quantum
circuit on quantum hardware more feasible, while preserving the mathematical properties of the circuit.
Compilers for quantum circuits achieve this by two means– reducing (1) the number of gates, and (2) the
circuit depth.
4. Phase IV: Special Topics in Quantum Computing 64

Quantum Compiler Optimizations


Quantum compiler optimizations can be categorized into several key strategies:

Gate Deletion Gate deletion is an optimization technique that removes quantum gates which have no signifi-
cant impact on the final quantum state. This can occur in scenarios where:
• Gates cancel each other out (e.g., 𝑅 𝑧 (0) or successive rotations that net to zero)
• Gates act on qubits not involved in the final measurement
• Redundant gates can be eliminated without changing the circuit’s computational outcome

Example 4.1.1 (Gate Deletion Example)


Consider a circuit with successive rotations:

𝑅 𝑧 (𝜋/2) ◦ 𝑅 𝑧 (−𝜋/2) ≡ Identity

A quantum compiler would recognize this and delete both gates, reducing circuit complexity.

Gate Synthesis Gate synthesis involves combining multiple gates into more efficient, hardware-compatible
implementations. The primary goals are:
• Reduce total gate count
• Minimize circuit depth
• Ensure compatibility with hardware gate sets

Example 4.1.2 (Gate Synthesis)


Converting a three-qubit Toffoli gate into a sequence of elementary 𝐶𝑋 and single-qubit rotations that
can be implemented on hardware with limited multi-qubit gate capabilities.

Gate Decomposition Gate decomposition breaks complex multi-qubit gates into sequences of simpler, hardware-
native gates. This is crucial because:
• Quantum hardware often supports only limited gate types (e.g., 𝐶𝑋, single-qubit rotations)
• Complex gates like Toffoli must be decomposed into supported primitive gates
• Decomposition helps manage qubit connectivity constraints

Example 4.1.3 (Toffoli Gate Decomposition)


A Toffoli gate controlling on two qubits can be decomposed into a sequence of 𝐶𝑋 and single-qubit
rotations:

1. Reduce to controlled-𝑉 gate


2. Use ancilla qubits to implement multi-controlled rotations
3. Minimize total gate count and depth

Practical Implications
The effectiveness of quantum compiler optimizations directly impacts:
• Circuit Fidelity: Fewer gates mean less accumulated noise
• Computational Efficiency: Reduced gate count and depth
• Hardware Utilization: Better adaptation to specific quantum hardware constraints
4. Phase IV: Special Topics in Quantum Computing 65

Note:-
Modern quantum compilers like Qiskit, Cirq, and PennyLane implement sophisticated optimization passes
that can dramatically reduce circuit complexity before execution.

4.2 Lecture 17: More on Quantum Compiler Optimizations, Quan-


tum Computer Architectures
More on Quantum Compiler Optimizations
While our previous lecture explored gate deletion, synthesis, and decomposition, gate commutativity represents
another crucial optimization technique. Not all quantum gates commute, but certain gate combinations can be
rearranged to improve circuit efficiency.

Gate Commutativity In quantum computing, gate commutativity refers to the ability to reorder certain
quantum gates without changing the final quantum state, enabling compiler-level optimizations.

• Commutative Gates: Some single-qubit gates, like 𝑅 𝑧 and 𝑅 𝑥 , can be reordered


• Non-Commutative Gates: Controlled gates like 𝐶𝑋 have strict ordering constraints
• Optimization Strategies:
1. Identify gates that can be safely reordered
2. Minimize circuit depth
3. Reduce gate interaction complexity

Example 4.2.1 (Gate Commutativity Example)


Consider two single-qubit rotations:

𝑅 𝑧 (𝛼) ◦ 𝑅 𝑥 (𝛽) ≈ 𝑅 𝑥 (𝛽) ◦ 𝑅 𝑧 (𝛼)

This property allows compilers to rearrange gates to optimize circuit structure.

Note:-
Not all gate pairs commute. The non-commutativity of quantum gates is fundamental to quantum computing’s
power and complexity.

Superconducting Qubit Architectures


Definition 4.2.1: Superconducting Qubit

A quantum bit implemented using superconducting circuits, typically based on Josephson junctions, op-
erating at extremely low temperatures to maintain quantum coherence.

Josephson Junction Fundamentals A Josephson junction is a key component in superconducting qubit


design:

• Consists of two superconductors separated by a thin insulating barrier


• Exhibits quantum tunneling of Cooper pairs
• Creates a nonlinear energy level structure crucial for qubit implementation
• Represented in circuit diagrams with an X symbol
4. Phase IV: Special Topics in Quantum Computing 66

Aside
Why Are Quantum Computers Kept So Cold?

Quantum computers require extreme cooling (millikelvin temperatures) to:

• Minimize thermal noise


• Preserve quantum coherence

• Reduce electron scattering


• Maintain superconducting properties

Typical operating temperatures are around 10-15 millikelvin, colder than outer space!

Frequency Management in Quantum Circuits


Definition 4.2.2: Detuning

The deliberate offset of qubit operating frequencies to prevent unwanted interactions and frequency colli-
sions.

Key challenges in superconducting qubit architectures:

• Frequency Collisions: Qubits operating at similar frequencies can unintentionally couple


• Detuning Strategies:
1. Adjust individual qubit frequencies
2. Create frequency separation
3. Minimize cross-talk between qubits

Noise Effects in Quantum Computing Quantum computation is fundamentally challenged by two noise
types:

• Coherent Noise:
– Predictable and potentially controllable
– Minimized by reducing total 1 and 2-qubit gate operations
– Can be partially mitigated through precise gate implementations
• Non-Coherent Noise:
– Unpredictable and harder to control
– Reduced by minimizing circuit depth
– Directly impacts the critical path of quantum computations

Quantum State Decay and Measurement Challenges


• Quantum states naturally decay over time (decoherence)
• Measurement intrinsically disturbs quantum state
• Dynamical Decoupling (DD) techniques can help:
– Insertion of precise control pulses
– Attempts to cancel out environmental noise
– Extends quantum state coherence time
4. Phase IV: Special Topics in Quantum Computing 67

Key Takeaways
• Quantum compiler optimizations extend beyond simple gate manipulation

• Superconducting qubits rely on complex physical mechanisms


• Noise management is critical in quantum computing architectures
• Frequency control and state preservation are fundamental challenges

4.3 Lecture 18: Quantum Circuits as DAGs, Qubit Topologies, Log-


ical to Physical Mapping
Representing Quantum Circuits as Directed Acyclic Graphs (DAGs)
Quantum circuits are complex, but they can be visualized as Directed Acyclic Graphs (DAGs), where each gate is
a node, and directed edges show which gates must happen before others. This helps in understanding the circuit’s
flow and dependencies.
Definition 4.3.1: Directed Acyclic Graph (DAG)

A graph with directed edges and no cycles, used to represent a quantum circuit where:
• Nodes represent quantum gates or operations
• Directed edges indicate dependencies between gates (which operations must be performed before
others)

• Time flows in the direction of the edges


• The acyclic property ensures no operation can depend on future operations
• Qubit lines from circuit diagrams become vertices at different time steps

• Two-qubit gates create edges between the affected qubits, establishing execution dependencies
This representation provides a mathematical foundation for analyzing circuit complexity, parallelism, and
execution constraints.

The conversion process from a standard quantum circuit to a DAG follows these principles:

1. Each quantum gate operation (single-qubit gates like 𝐻, 𝑋 , 𝑅 𝑥 , 𝑅 𝑦 , 𝑅 𝑧 or two-qubit gates like CNOT, CZ)
becomes a node in the graph.
2. Directed edges connect a gate to all subsequent gates that depend on it:

• Gates acting on the same qubit(s) later in the circuit


• Two-qubit gates create dependencies between their control and target qubits

3. The resulting graph is inherently acyclic due to the temporal sequential nature of quantum circuits, with
operations flowing forward in time without feedback loops.

4. Gates that can be executed in parallel (acting on independent qubits) will not have dependency paths
between them.

This representation makes it clear which operations can be performed simultaneously and which ones must
wait for prior operations to complete.
4. Phase IV: Special Topics in Quantum Computing 68

Definition 4.3.2: Critical Path

The longest path through the circuit’s DAG representation from input to output, which determines:

• The minimum execution time of the quantum circuit

• The sequence of dependent operations that cannot be parallelized


• The circuit depth when optimal parallelization is applied

The critical path is particularly important for quantum computing because:

• Quantum states are highly susceptible to decoherence over time


• Minimizing the critical path reduces the total time qubits must maintain coherence
• The number of two-qubit gates in the critical path often dominates error rates
• It provides a key metric for comparing different implementations of the same algorithm

From the DAG, finding the critical path is a well-studied graph problem that can be solved efficiently using
topological sorting and dynamic programming to compute the longest path length.

Different Current Qubit Topology Designs


Where early qubit topology designs would potentially have some qubits with up to 4 qubit connections, this
proved to produce noise effects that would cause incorrect output. Modern designs as of writing make use of
altered qubit topology layouts that have at most 3 connections to other qubits.
An interesting aspect is the fundamental trade-off between connectivity and noise: more connections be-
tween qubits can enable faster computations with fewer SWAP operations, but each additional coupling point
introduces potential sources of crosstalk and errors. This trade-off has led modern designs to favor more conser-
vative connectivity patterns that prioritize gate fidelity over maximum connectivity.
This process of converting the circuit design onto actual, physical quantum hardware is appropriately called
logical to physical mapping. Furthermore, the process seen in the above example where each qubit’s path is
manifested in the physical circuit (potentially with the use of SWAP gates due to the physical connections of the
hardware) is called routing.

Definition 4.3.3: Logical → Physical Mapping

The process of assigning logical qubits in a quantum algorithm to physical qubits on a quantum processor,
considering:

• The hardware connectivity constraints of the physical device

• The specific interactions required by the quantum algorithm


• The quality and error rates of individual physical qubits
• The fidelity of two-qubit gate operations between specific physical qubits

Effective logical-to-physical mapping minimizes the number of additional operations (like SWAP gates)
needed to execute the circuit on hardware with limited connectivity, which is crucial for reducing noise
exposure and improving overall circuit performance.
4. Phase IV: Special Topics in Quantum Computing 69

Definition 4.3.4: Routing

The process of determining how to move quantum information between non-adjacent qubits on a quantum
processor with limited connectivity, including:

• Inserting SWAP operations to move quantum states between physical qubits


• Determining the optimal sequence of SWAP operations to enable two-qubit gates between logical
qubits mapped to non-adjacent physical qubits
• Balancing the trade-off between circuit depth increase and total gate count

• Considering the relative error rates of different physical connections when deciding routing paths

Efficient routing is critical for quantum circuit execution on NISQ (Noisy Intermediate-Scale Quantum)
devices, as poor routing decisions can significantly degrade algorithm performance through accumulated
errors.

As quantum devices continue to scale up, the complexity of the mapping and routing problems grows sig-
nificantly, making efficient compilation techniques an essential area of research for practical quantum computing.

4.4 Lecture 19: More on Logical to Physical Mapping


We will continue to delve deeper into the process of mapping logical quantum circuits to physical quantum
hardware, focusing on IBM’s heavy-hex lattice topology. This mapping is a critical step in quantum computing
due to the constrained connectivity of physical qubits, often requiring the insertion of SWAP gates to enable
interactions between non-adjacent qubits. We will explore how to decide on an effective mapping, and the
consequences of suboptimal choices on circuit efficiency. The IBM hardware operates with a specific basis gate
set—CX, X, RZ, and SX—into which all circuits must be decomposed, adding another layer of complexity to the
mapping process.

IBM’s Heavy-Hex Lattice Topology


IBM’s quantum processors, such as those in the Falcon and Hummingbird families, employ the heavy-hex lattice,
a hexagonal arrangement of qubits with additional edge qubits designed to minimize error rates. This topology
reduces frequency collisions and spectator errors compared to denser layouts like square lattices, enhancing scal-
ability and error correction capabilities.1 For example, in a simplified seven-qubit heavy-hex layout, qubits might
be arranged as a chain (p0-p1-p2-p3-p4) with dangling qubits (p5 connected to p1, p6 to p3), where each qubit
has at most three neighbors.

This connectivity can be represented conceptually as:

• p0 – p1 – p2 – p3 – p4
• p5 – p1
• p6 – p3

Such a structure balances connectivity with error mitigation, as explored in research on topological codes.2

Basis Gates and Hardware Constraints


IBM’s superconducting qubit platforms utilize a basis gate set consisting of CX (CNOT), X, RZ, and SX gates. All
logical circuits must be transpiled into these gates for execution on IBM hardware.3 This constraint, enforced by
1 SeeThe IBM Quantum heavy hex lattice for more details on the design motivation.
2 Refer to Creating entangled logical qubits in the heavy-hex lattice with topological codes for insights into error correction on this
topology.
3 Details on native gates are available at Native gates and operations.
4. Phase IV: Special Topics in Quantum Computing 70

tools like Qiskit’s transpiler, ensures compatibility but impacts circuit depth and fidelity. For instance, a SWAP
gate, necessary for non-adjacent qubit interactions, decomposes into three CX gates, amplifying the importance
of efficient mapping.

Example 4.4.1 (Mapping Logical Circuits to Physical Hardware)


Consider a simple logical circuit with a single CNOT gate between two qubits, q0 and q1:

On a physical device with a linear topology (p0-p1-p2, where p0 is connected to p1, and p1 to p2), the
mapping decision determines the circuit’s efficiency:

Optimal Mapping
Map q0 to p0 and q1 to p1, where p0 and p1 are adjacent. The physical circuit remains:

p0 (q0)

p1 (q1)
p2

This requires no additional gates, preserving the circuit’s depth and minimizing error accumulation.

Suboptimal Mapping
Map q0 to p0 and q1 to p2, where p0 and p2 are not directly connected. To execute the CNOT, we must
swap q1 to an adjacent position:

1. SWAP p1 and p2 to move q1 to p1.


2. Apply CNOT between p0 and p1.
3. SWAP p1 and p2 back to restore the original mapping (if needed).

The physical circuit becomes:


p0 (q0)

p1
p2 (q1)

Each SWAP decomposes into three CX gates, adding six CX gates total, significantly increasing depth
and error potential.a
a For SWAP gate decomposition, see Explore gates and circuits with IBM Quantum Composer.

Efficiency Impacts of Mapping Choices


The choice of mapping directly affects circuit efficiency:

• Optimal Mapping: No SWAPs, minimal gate count, and low error rate.
• Suboptimal Mapping: Two SWAPs, six additional CX gates, increased depth, and higher error proba-
bility due to more operations.
4. Phase IV: Special Topics in Quantum Computing 71

For a larger circuit, such as one with three qubits (q0, q1, q2) and gates CX q0 q1, CX q1 q2, CX q0 q2, mapping
q0 to p0, q1 to p1, and q2 to p2 leverages adjacency for the first two gates but requires a SWAP for the third
(p0 to p2). A better strategy might cluster frequently interacting qubits, reducing SWAP overhead, as seen in
optimization studies.4

Mapping Type Number of SWAPs Additional CNOTs Circuit Depth Increase Error Potential
Optimal (Adjacent) 0 0 0 Low
Suboptimal (Non-Adjacent) 2 6 Significant High

Table 4.1: Comparison of mapping efficiency for a two-qubit CNOT circuit.

Example 4.4.2 (Larger Circuit Mapping Example)


Consider a three-qubit logical circuit:

q0

q1

q2

On a heavy-hex segment (p0-p1-p2), an optimal mapping (q0 to p0, q1 to p1, q2 to p2) executes the first
two gates directly but requires a SWAP for CX q0 q2:

p0 (q0)

p1 (q1)

p2 (q2)

Here, the SWAP p1 p2 moves q2 to p1, allowing the CNOT, adding three CX gates. A suboptimal mapping
(e.g., q0 to p0, q1 to p2, q2 to p1) would require multiple SWAPs, worsening efficiency.

Practical Implications
Efficient mapping is crucial for quantum algorithm performance, especially as hardware scales to larger qubit
counts (e.g., IBM’s Crossbill with 408 qubits).5 Suboptimal mappings can render circuits impractical due to
excessive depth, while optimal mappings, guided by tools like Qiskit, enhance fidelity.6

4.5 Lecture 20: Quantum Error Correction– Bit Flip Errors


Quantum circuits are highly sensitive to errors due to decoherence and environmental noise, making error correc-
tion a cornerstone of reliable quantum computation. This sensitivity stems from qubits losing their quantum state
through interactions with the environment, a process known as decoherence. In quantum computing, significant
effort is devoted not only to compiler optimizations that reduce circuit depth but also to creating redundancies
within quantum circuits to protect information and enable fault-tolerant computation.7 This lecture contrasts
4 See Linear Depth QFT over IBM Heavy-hex Architecture for mapping optimization techniques.
5 See IBM roadmap to quantum-centric supercomputers for future hardware plans.
6 For hardware-aware strategies, see Hardware-aware approach for fault-tolerant quantum computation.
7 For an overview, see What is quantum error correction?
4. Phase IV: Special Topics in Quantum Computing 72

classical error correction with quantum approaches, highlighting the unique challenges posed by quantum me-
chanics.

Classical Error Correction


Classical bits, which can be either 0 or 1, are prone to errors with a probability 𝑝 ∈ [0, 1], where the bit flips with
probability 𝑝 and remains correct with probability 1 − 𝑝. This is formally expressed as:
(
correct, with probability 1 − 𝑝
𝑏=
incorrect, with probability 𝑝

Classical bits typically experience only bit-flip errors (e.g., 0 to 1 or 1 to 0), unlike quantum bits, which
can also suffer phase flips due to their superposition and entanglement properties.

Example 4.5.1 (Error Encoding of 3 for Classical Bit)


Suppose 𝑏 = 0. Classically, we can build redundancies by making three copies of 𝑏, sending 000, and taking
a majority vote at the receiver to decode the original bit. The possible received states, their probabilities,
and the decoded outcomes are shown in the table below:

Received State Probability Decoded Value Correct?


000 (1 − 𝑝)3 0 Yes
001 (1 − 𝑝)2 𝑝 0 Yes
010 (1 − 𝑝)2 𝑝 0 Yes
100 (1 − 𝑝)2 𝑝 0 Yes
011 (1 − 𝑝)𝑝 2 1 No
101 (1 − 𝑝)𝑝 2 1 No
110 (1 − 𝑝)𝑝 2 1 No
111 𝑝3 1 No

Table 4.2: Probabilities of received states for a 3-bit repetition code.

The probability of correctly decoding 𝑏 = 0 is the sum of probabilities where the majority is 0: (1 − 𝑝)3 +
3(1 − 𝑝)2 𝑝 = 1 − 3𝑝 2 + 2𝑝 3 . This improves the success probability from the initial 1 − 𝑝 to 1 − 3𝑝 2 + 2𝑝 3 .

For 𝑝 = 0.01, the initial success rate without encoding is 0.99, but with three-bit redundancy, it increases
to 0.999702, significantly enhancing reliability.

Interestingly, modern devices like smart phones employ similar redundancy techniques, often using 5-
7 redundancy bits in flash memory for error correction. This contributes to power consumption due to the
additional storage and processing required, a trade-off for improved data integrity in noisy environments.

Qubit Flip Error Correction


Quantum error correction is fundamentally more complex than its classical counterpart due to the no-cloning
theorem, which states that an unknown quantum state cannot be perfectly copied.8 This prevents us from simply
making trivial copies of a qubit’s state, as in classical systems. Even attempting to ”clone” a qubit would not
preserve the original superposition |𝜓⟩ = 𝛼|0⟩ + 𝛽|1⟩, rendering direct repetition impractical. Instead, quantum
error correction relies on encoding logical qubits into entangled states across multiple physical qubits, using codes
like the repetition code.

8 For details on the no-cloning theorem, see Quantum circuits.


4. Phase IV: Special Topics in Quantum Computing 73

Definition 4.5.1: Repetition Code

The quantum repetition code encodes a single logical qubit into multiple physical qubits to protect
against errors. For a code distance of 3, the state |𝜓⟩ = 𝛼|0⟩ + 𝛽|1⟩ is encoded into |𝜓3 ⟩ = 𝛼|000⟩ + 𝛽|111⟩.
This is achieved by starting with the initial qubit in |𝜓⟩ and two ancilla qubits in |0⟩, then applying CNOT
gates from the original qubit to the ancillas:

𝑞0 𝜓

𝑞 1 : |0⟩

𝑞 2 : |0⟩

This circuit entangles the qubits such that a single bit-flip error (e.g., 𝑋 on one qubit) can be detected
and corrected using syndrome measurements without collapsing the superposition.a
a See Protecting expressive circuits with a quantum error detection code for encoding techniques.

Definition 4.5.2: Syndrome

In quantum computing, syndrome measurement is a process used in quantum error correction (QEC) to
identify errors without revealing the quantum information stored in the qubits. The syndrome measure-
ment provides information about the type of error that has occurred, such as a bit flip or a phase flip, but
it does not reveal the information stored in the logical qubit, thus preserving quantum superposition

To correct a single qubit flip error, consider the encoded state |𝜓3 ⟩ = 𝛼 |000⟩ + 𝛽 |111⟩. If an 𝑋 error occurs
on 𝑞1 , the state becomes 𝛼 |010⟩ + 𝛽 |101⟩. Syndrome measurements are performed using two ancilla qubits to
measure the parities 𝑞 0 𝑞 1 and 𝑞 1 𝑞2 :

• Measure 𝑋 ⊗ 𝑋 between 𝑞 0 and 𝑞 1 with an ancilla initialized in |+⟩, applying CNOTs from 𝑞0 and 𝑞 1 to
the ancilla, then measuring it in the 𝑍-basis. Outcome -1 indicates a flip on 𝑞0 or 𝑞 1 .
• Measure 𝑋 ⊗ 𝑋 between 𝑞1 and 𝑞 2 similarly. Outcome -1 indicates a flip on 𝑞 1 or 𝑞 2 .

For the error on 𝑞1 :


• 𝑞 0 𝑞 1 : -1 (flip detected).
• 𝑞 1 𝑞 2 : -1 (flip detected).

• Syndrome (-1, -1) uniquely identifies 𝑞1 , and an 𝑋 gate corrects it, restoring |𝜓3 ⟩.
This process, detailed in Error correcting codes for near-term quantum computers, ensures correction
without measuring the logical state directly, preserving quantum information.

Aside

Silent Data Corruption (SDC) occurs when errors go undetected, posing significant risks in computing
systems. In classical systems, SDC can corrupt data silently, leading to integrity issues in storage or
processing. In quantum computing, undetected errors can propagate through entanglements, undermining
computation reliability and producing incorrect results. This is particularly challenging due to the fragility
of quantum states, making robust error correction essential to mitigate SDC and achieve fault tolerance.a
a See Why error correction is quantum computing’s defining challenge for SDC implications.
4. Phase IV: Special Topics in Quantum Computing 74

4.6 Lecture 21: Quantum Error Correction– Phase Flip Errors


In the previous lecture, we explored bit flip error detection and correction in quantum error correction, addressing
errors that flip a qubit’s state from |0⟩ to |1⟩ or vice versa. However, quantum systems are also susceptible to
another class of errors: phase flip errors, which apply a 𝑍 gate, transforming |𝜓⟩ = 𝛼|0⟩ + 𝛽|1⟩ into 𝛼|0⟩ − 𝛽|1⟩.
These errors alter the relative phase between basis states, a critical issue in quantum computing due to the
importance of phase in superpositions and entanglement. In this section, we will examine how to detect and
correct phase flip errors, highlighting their similarity to bit flip correction but with key differences involving
Hadamard and Z gates.

Phase Flip Error Correction


Phase flip errors are represented by the Pauli 𝑍 operator, which applies a -1 phase to the |1⟩ component of a
qubit’s state. For a single qubit in |𝜓⟩ = 𝛼|0⟩ + 𝛽|1⟩, a phase flip results in 𝑍|𝜓⟩ = 𝛼|0⟩ − 𝛽|1⟩. Unlike bit flip
errors, which are detectable in the computational basis (|0⟩, |1⟩), phase flips are more apparent in the Hadamard
|0⟩+|1⟩ |0⟩−|1⟩
basis (|+⟩ = √ , |−⟩ = √ ), where a 𝑍 gate flips |+⟩ to |−⟩.
2 2
To correct phase flip errors, we can adapt the repetition code used for bit flips by transforming the basis.
The phase flip code encodes a logical qubit into three physical qubits, similar to the bit flip code, but uses
Hadamard gates to switch to the |+⟩, |−⟩ basis for error detection. The logical states are:
• Logical |0𝐿 ⟩ = | + ++⟩
• Logical |1𝐿 ⟩ = | − −−⟩

For an arbitrary state |𝜓⟩ = 𝛼|0⟩ + 𝛽|1⟩, the encoded state is 𝛼| + ++⟩ + 𝛽| − −−⟩. The encoding circuit is:

𝑞2 : |𝜓⟩ 𝐻 𝐻

𝑞 1 : |0⟩ 𝐻 𝐻

𝑞 0 : |0⟩ 𝐻 𝐻

This circuit:
1. Applies Hadamard gates to all qubits, transforming 𝑞2 : |𝜓⟩ → 𝛼|+⟩ + 𝛽|−⟩, 𝑞 1 , 𝑞0 : |0⟩ → |+⟩.
2. Uses CNOTs to entangle the qubits, producing 𝛼| + ++⟩ + 𝛽| − −−⟩.
3. Applies Hadamard gates again to return to the computational basis for further operations, though for error
detection, we work in the Hadamard basis.
To detect a phase flip (e.g., 𝑍 on 𝑞 1 ), we measure syndromes using ancilla qubits in the Hadamard basis.
A 𝑍 error on 𝑞 1 flips | + ++⟩ → | + −+⟩ or | − −−⟩ → | − +−⟩. The syndrome measurement circuit is:
𝑞2 𝐻 𝐻

𝑞1 𝐻 𝐻

𝑞0 𝐻 𝐻

𝑎 1 : |0⟩

𝑎 0 : |0⟩

Here, ancillas measure parities 𝑋0 𝑋1 and 𝑋1 𝑋2 :


4. Phase IV: Special Topics in Quantum Computing 75

• 𝑋0 𝑋1 : CNOTs from 𝑞 0 and 𝑞 1 to 𝑎 0 , measured as 1 if 𝑞0 ≠ 𝑞1 .


• 𝑋1 𝑋2 : CNOTs from 𝑞 1 and 𝑞 2 to 𝑎 1 , measured as 1 if 𝑞1 ≠ 𝑞2 .
The syndrome outcomes are:

𝑎 1 (𝑋0 𝑋1 ) 𝑎 0 (𝑋1 𝑋2 ) Syndrome Action


0 0 00 No error
1 0 10 Apply 𝑍 to 𝑞0
1 1 11 Apply 𝑍 to 𝑞1
0 1 01 Apply 𝑍 to 𝑞2

Table 4.3: Syndrome measurements for phase flip error correction.

For example, a 𝑍 error on 𝑞 1 yields syndrome 11, indicating 𝑞1 differs from both 𝑞 0 and 𝑞2 . Applying 𝑍
to 𝑞 1 corrects the error, restoring 𝛼| + ++⟩ + 𝛽| − −−⟩.9
This approach mirrors bit flip correction but operates in the Hadamard basis, leveraging the fact that a
𝑍 gate in the computational basis corresponds to an 𝑋 gate in the Hadamard basis (𝐻𝑍𝐻 = 𝑋), allowing us to
repurpose bit flip correction circuits with basis changes.

Generalizing Phase Correction to an n-Qubit System


Extending phase flip correction to an n-qubit system scales linearly in terms of physical qubits required. For a
code distance 𝑑 = 𝑛, we encode one logical qubit into 𝑛 physical qubits, producing logical states:

• |0𝐿 ⟩ = |+⟩ ⊗𝑛
• |1𝐿 ⟩ = |−⟩ ⊗𝑛

The encoding circuit generalizes to:

1. Apply Hadamard gates to 𝑞 0 : |𝜓⟩ and 𝑞 1 , . . . , 𝑞 𝑛−1 : |0⟩.


2. Apply CNOTs from 𝑞0 to each 𝑞 𝑖 (for 𝑖 = 1, . . . , 𝑛 − 1).
3. Optionally apply Hadamard gates to return to the computational basis.

For 𝑛 = 5, the circuit is:


𝑞4 : |𝜓⟩ 𝐻 𝐻

𝑞 3 : |0⟩ 𝐻 𝐻

𝑞 2 : |0⟩ 𝐻 𝐻

𝑞 1 : |0⟩ 𝐻 𝐻

𝑞 0 : |0⟩ 𝐻 𝐻

Syndrome measurements require 𝑛 − 1 ancillas to measure parities 𝑋𝑖 𝑋𝑖+1 for 𝑖 = 0, . . . , 𝑛 − 2. Each ancilla
detects differences between adjacent qubits, identifying up to ⌊(𝑛 − 1)/2⌋ errors. The number of physical qubits
scales as 𝑂(𝑛), and the circuit depth for encoding is linear in 𝑛, as each CNOT is sequential from 𝑞 0 . Error
correction scales similarly, with 𝑛 − 1 syndrome measurements.10
9 See Error correcting codes for near-term quantum computers for syndrome measurement techniques.
10 For scaling details, see Quantum Error Correction: an Introductory Guide.
4. Phase IV: Special Topics in Quantum Computing 76

This linear scaling makes phase flip correction feasible for larger systems, though practical implementations
must balance qubit count against error rates, as more qubits increase the likelihood of multiple errors, requiring
higher-distance codes.

Example 4.6.1 (Phase Flip Correction for Bell State Preparation)


|00⟩+|11⟩
Consider a Bell state preparation circuit, creating |Φ+ ⟩ = √ :
2

𝑞 1 : |0⟩ 𝐻

𝑞 0 : |0⟩

To protect against phase flips, we encode each qubit into a 3-qubit phase flip code. For 𝑞 1 , we encode
|0⟩+|1⟩ |+++⟩+|−−−⟩
|𝜓0 ⟩ = √ (after Hadamard) into √ , and similarly for 𝑞0 : |0⟩. The encoded circuit, adapted
2 2
for phase flip protection, requires 6 qubits (3 per logical qubit):

𝑞 1,0 : |0⟩ 𝐻 𝐻

𝑞 1,1 : |0⟩ 𝐻 𝐻

𝑞1,2 : |0⟩ 𝐻 𝐻

𝑞0,0 : |0⟩ 𝐻 𝐻

𝑞0,1 : |0⟩ 𝐻 𝐻

𝑞0,2 : |0⟩ 𝐻 𝐻

Here, 𝑞1,0 , 𝑞1,1 , 𝑞1,2 encode the first logical qubit, and 𝑞0,0 , 𝑞0,1 , 𝑞0,2 encode the second. The CNOT from
𝑞 0,0 to 𝑞1,0 entangles the logical qubits, approximating the Bell state in the encoded space. If a phase flip
occurs on 𝑞 0,1 , syndrome measurements (as above) on 𝑞 0,0 , 𝑞0,1 , 𝑞0,2 detect it with syndrome 11, and a 𝑍
gate corrects it. This protects the entangled state, ensuring the Bell pair’s integrity.a
a For encoded circuit examples, see Protecting expressive circuits with a quantum error detection code.

Aside
FPGA: Field-Programmable Gate Array
Field-Programmable Gate Arrays (FPGAs) are integrated circuits that can be configured post-
manufacturing to perform specific tasks, such as real-time error correction in quantum computers. In
quantum systems, the decoding and encoding units for error correction are often implemented on FP-
GAs due to their proximity to the hardware. This allows immediate application of corrective operations,
minimizing latency and reducing the risk of decoherence during error correction cycles. FPGAs enable
dynamic adjustments to syndrome measurements and corrections, critical for maintaining quantum state
integrity.a
a See Quantum Error Correction in Real-Time with FPGAs for implementation details.
4. Phase IV: Special Topics in Quantum Computing 77

Aside
CAT Qubits
As of time of writing (2025-04-11), a company named Alice & Bob is developing a novel type of supercon-
ducting qubit called a CAT qubit, named after Schrödinger’s cat to reflect its coherent superposition of
macroscopically distinct states. CAT qubits are engineered to exhibit biased noise, significantly increasing
bit flip error rates while suppressing phase flip errors to near-negligible levels. This design reduces the
overhead of error correction by focusing solely on bit flip correction, which is less resource-intensive. For
example, their approach could lower the number of physical qubits needed for fault-tolerant computation,
potentially accelerating practical quantum computing. However, the trade-off of higher bit flip errors
requires robust bit flip correction protocols.a
a See Alice & Bob’s CAT Qubit Technology for details.
Chapter 5

Phase V: Concluding Lectures

5.1 Lecture 22: Quantum Annealers, Trapped Ion Quantum Com-


puters
Quantum Annealers
Quantum annealing is a metaheuristic for finding the global minimum of a given objective function by exploiting
quantum mechanical effects such as quantum tunneling and quantum entanglement.

Basic Principles
Quantum annealing is a physical implementation of quantum adiabatic computation, which relies on the adiabatic
theorem of quantum mechanics. The system is initialized in a quantum superposition state (typically the ground
state of a simple Hamiltonian), and then slowly evolved to a final Hamiltonian whose ground state encodes the
solution to the problem.
Definition 5.1.1: Quantum Annealing

Quantum annealing is an optimization process that transforms a quantum system from an initial Hamil-
tonian 𝐻𝑖 with a known ground state to a final problem Hamiltonian 𝐻 𝑓 whose ground state represents
the solution to the optimization problem. The time-dependent Hamiltonian follows:

𝐻(𝑡) = 𝐴(𝑡)𝐻𝑖 + 𝐵(𝑡)𝐻 𝑓


where 𝐴(𝑡) decreases from 𝐴(0) = 1 to 𝐴(𝑇) = 0 and 𝐵(𝑡) increases from 𝐵(0) = 0 to 𝐵(𝑇) = 1 over annealing
time 𝑇.

D-Wave Systems
The most prominent implementation of quantum annealing hardware is by D-Wave Systems, which has progressed
through multiple generations:

• D-Wave One (2011): 128 qubits


• D-Wave Two (2013): 512 qubits
• D-Wave 2X (2015): 1,000+ qubits
• D-Wave Advantage (2020): 5,000+ qubits

• D-Wave Advantage2 (2023): Over 7,000 qubits

D-Wave’s quantum annealers are particularly suited for solving quadratic unconstrained binary optimiza-
tion (QUBO) problems, which can be mapped to the Ising model:
5. Phase V: Concluding Lectures 79

Õ Õ
𝐻= ℎ 𝑖 𝜎𝑖𝑧 + 𝐽𝑖𝑗 𝜎𝑖𝑧 𝜎 𝑗𝑧 (5.1)
𝑖 𝑖<𝑗

where 𝜎𝑖𝑧 are Pauli-Z operators, ℎ 𝑖 are local fields, and 𝐽𝑖𝑗 are coupling strengths between qubits.

Hardware Architecture
D-Wave’s quantum processing units (QPUs) consist of superconducting flux qubits arranged in a specific topology:

• Early systems: Chimera graph topology


• Newer systems: Pegasus and Zephyr topologies with higher connectivity

The limited connectivity between qubits requires problem embedding, which maps logical problems onto
the physical qubit topology, often using multiple physical qubits to represent a single logical qubit.

Applications and Limitations


Quantum annealers have been applied to various optimization problems:

• Portfolio optimization
• Traffic flow optimization
• Machine learning (training of Boltzmann machines)
• Drug discovery

• Material design

However, several limitations exist:

• Limited connectivity requiring complex embeddings


• Quantum effects may be suppressed by noise and decoherence
• Difficulty in verifying ”quantumness” and quantum advantage

• Problem size limitations due to available qubits and connectivity

Quantum Advantage Debate


The question of whether D-Wave’s systems provide quantum advantage remains contentious. While some studies
have shown modest speedups for specific problems, definitive evidence of exponential quantum advantage has not
been demonstrated. Recent research suggests that quantum annealers may provide advantages for problems with
specific structure, particularly those with tall, narrow energy barriers where quantum tunneling offers benefits
over classical simulated annealing.

Recent Developments
Recent advances in quantum annealing include:
• Reverse annealing protocols that start from candidate solutions
• Pause-and-quench annealing schedules

• Improved error correction techniques


• Hybrid quantum-classical algorithms that combine quantum annealing with classical optimization
5. Phase V: Concluding Lectures 80

Aside
While quantum annealers like D-Wave’s systems represent an alternative approach to gate-based quantum
computing, they are specialized machines designed for optimization problems rather than general-purpose
quantum computers. The debate about their quantum advantage continues, with researchers exploring
specific problem classes where quantum annealers might outperform classical methods.

Trapped Ion Quantum Computers


Trapped ion quantum computers represent one of the most promising and mature platforms for quantum infor-
mation processing, offering exceptional qubit coherence times and high-fidelity gate operations.

Fundamental Principles
In trapped ion quantum computing, individual ions (typically alkaline earth metal ions like Ca+ , Sr+ , or rare
earth ions like Yb+ ) are confined using electromagnetic fields in ultra-high vacuum environments.
Definition 5.1.2: Ion Trap

An ion trap is a device that uses electric or magnetic fields to capture charged particles in a confined
region of space. The most common type used in quantum computing is the linear Paul trap, which uses
oscillating electric fields to create a pseudopotential that confines ions in a linear chain.

Qubits are encoded in the internal electronic states of each ion, typically using:

• Hyperfine ground states (e.g., 2 S1/2 states in 171


Yb+ )
• Zeeman sublevels of ground states
• Optical transitions between ground and metastable excited states

Quantum Operations
• Initialization: Optical pumping techniques prepare ions in well-defined initial states with high fidelity.
• Single-qubit gates: Implemented using precisely controlled laser pulses or microwave radiation that drive
transitions between qubit states. These operations can achieve fidelities exceeding 99.9%.
• Two-qubit gates: Exploit the shared motional modes of the ion chain. The Coulomb interaction between
ions creates collective vibrational modes that can mediate entangling operations. Common implementations
include:
– Mølmer–Sørensen gates
– Cirac-Zoller gates
– Geometric phase gates
• Readout: State-dependent fluorescence detection, where one qubit state fluoresces when illuminated by a
laser while the other remains dark, allowing for high-fidelity measurement.

Example 5.1 (Mølmer–Sørensen Gate)


he Mølmer–Sørensen gate uses bichromatic laser fields to drive transitions that entangle pairs of ions
without populating the motional modes, making it robust against heating. The interaction Hamiltonian
can be written as: Õ
𝐻𝑀𝑆 = 𝐽𝑖𝑗 𝜎𝑖+ 𝜎+𝑗 + 𝜎𝑖− 𝜎−𝑗 (5.2)
𝑖,𝑗

where 𝜎+ and 𝜎− are the raising and lowering operators, and 𝐽𝑖𝑗 represents the coupling strength.
5. Phase V: Concluding Lectures 81

Key Advantages
Trapped ion quantum computers offer several notable advantages:

• Long coherence times: Ions are naturally isolated from their environment, with coherence times ranging
from seconds to minutes, orders of magnitude longer than most solid-state qubits.

• Identical qubits: As fundamental atomic systems, each ion of a given species is identical, eliminating the
variability found in manufactured solid-state qubits.
• High-fidelity operations: Both single and two-qubit gates have demonstrated fidelities well above 99%,
among the highest in any quantum computing platform.

• All-to-all connectivity: In small ion chains, each ion can interact with any other ion in the chain,
eliminating the need for swap networks found in architectures with nearest-neighbor connectivity.

Scaling Challenges and Solutions


Despite their advantages, trapped ion systems face challenges in scaling to larger numbers of qubits:

• Ion chain stability: As the number of ions in a single chain increases, the chain becomes more susceptible
to heating and instabilities.
• Gate speed limitations: The speed of entangling gates decreases as the ion chain grows, as motional
modes become more densely packed in frequency space.

• Laser control complexity: Precisely addressing individual ions with lasers becomes more challenging in
longer chains.

Proposed solutions to these scaling challenges include:

• Quantum charge-coupled device (QCCD) architecture: Multiple small ion chains connected by ion
transport between different trapping zones.
• Photonic interconnects: Using photons to entangle ions in physically separated traps.
• Microfabricated trap arrays: Creating integrated, scalable ion trap chips with multiple trapping regions
and built-in control elements.

• Sympathetic cooling: Using auxiliary ”coolant” ions of a different species to mitigate heating effects.

Leading Research Groups and Companies


Major players in trapped ion quantum computing include:

• Academic groups:
– University of Innsbruck (Rainer Blatt)
– University of Maryland/JQI (Christopher Monroe)
– NIST (David Wineland, Dietrich Leibfried)
– Oxford University (David Lucas)
• Companies:
– IonQ (founded by Christopher Monroe and Jungsang Kim)
– Quantinuum (formerly Honeywell Quantum Solutions, merged with Cambridge Quantum Computing)
– Alpine Quantum Technologies (AQT)
– Universal Quantum
5. Phase V: Concluding Lectures 82

Recent Achievements
Recent milestones in trapped ion quantum computing include:

• Demonstrations of quantum error correction codes

• Implementation of variational quantum algorithms and quantum simulations


• Realization of high-fidelity multi-qubit gates (3+ qubits)
• Creation of high-fidelity entangled states with 10+ qubits
• Demonstration of quantum advantage in certain specialized tasks

Under realistic noise models for trapped ion systems, fault-tolerant quantum computation is achievable
with gate error rates below approximately 10−4 using standard quantum error correction codes, making trapped
ions a promising platform for scalable quantum computation.
Definition 5.1.3: Quantum Volume

Quantum Volume is a hardware-agnostic metric introduced by IBM to characterize the capabilities of


quantum computers. It measures the largest random circuit of equal width and depth that the quantum
computer can successfully implement. Trapped ion quantum computers have demonstrated some of the
highest quantum volumes among current platforms.

Note:-
While superconducting qubits have received significant attention due to their rapid development by companies
like IBM and Google, trapped ion systems continue to set records for gate fidelities and coherence times.
The race between these technologies (and others like silicon spin qubits) remains ongoing, with each offering
distinct advantages and challenges for practical quantum computing.

5.2 Lecture 23: Neutral Atom Quantum Computers, Photonic Quan-


tum Computers
Neutral Atom Quantum Computers
Neutral atom quantum computers represent a promising platform for quantum computing, leveraging individual
neutral atoms as qubits. These atoms are typically trapped using optical tweezers or other trapping methods,
allowing for precise control and manipulation.

Basic Principles
In neutral atom quantum computing, qubits are encoded in the internal states of the atoms, such as hyperfine
levels or Rydberg states. Rydberg states, in particular, are used for their strong interactions, which enable
entangling operations between distant atoms.

The basic operations include:

• State Preparation: Cooling and trapping atoms, then preparing them in the desired quantum state.
• Single-Qubit Gates: Manipulated using laser pulses to drive transitions between atomic states.
• Two-Qubit Gates: Achieved through Rydberg interactions, where the excitation of one atom affects
another within the blockade radius.

• Measurement: Typically done by fluorescence detection or other methods to read out the atomic states.
5. Phase V: Concluding Lectures 83

Definition 5.2.1: Rydberg Blockade

The Rydberg blockade is a phenomenon where the excitation of one atom to a Rydberg state prevents
nearby atoms from being excited due to strong van der Waals interactions. This enables entangling gates
with a Hamiltonian of the form:
ÕΩ ÕΔ
𝑖 𝑖
Õ
𝐻= 𝜎𝑥𝑖 + 𝜎𝑧𝑖 + 𝑉𝑖𝑗 𝑛 𝑖 𝑛 𝑗
2 2
𝑖 𝑖 𝑖<𝑗

where Ω𝑖 is the Rabi frequency, Δ𝑖 is the detuning, 𝑉𝑖𝑗 is the interaction strength, and 𝑛 𝑖 is the Rydberg
state projector.

Hardware Implementations
Leading companies in this field include QuEra and Pasqal. For example, QuEra’s Aquila system operates with
up to 256 qubits in analogue mode, utilizing Rydberg interactions for computation1 . Pasqal offers systems with
up to 100 qubits, supporting both digital and analog computation modes 2 .

Table 5.1: Key Neutral Atom Quantum Computing Systems

Company System Qubit Count


QuEra Aquila Up to 256 (analogue)
Pasqal Fresnel Up to 100

Advantages
• Scalability: Neutral atom systems can potentially scale to thousands of qubits, limited mainly by laser
power and optical system performance.
• Long Coherence Times: Trap lifetimes can be very long, with reported times up to 6000 seconds at
cryogenic temperatures 3 .
• High Gate Fidelities: Two-qubit gate fidelities have reached ∼0.995, surpassing the threshold for error
correction.

Challenges
• Preparation Times: Rearranging atoms into desired configurations can be time-consuming, especially as
the number of qubits increases.
• Gate Speeds: While gate fidelities are high, the speed of operations is slower compared to superconducting
qubits, with two-qubit gates taking around 1 𝜇s.

Recent Developments
Recent advancements, particularly noted in 2024, include:
• Accurate Entangling Gates: Demonstration of two-qubit operations with 99.5% fidelity using reconfig-
urable atom arrays4 .
• Error Correction: Implementation of quantum low-density parity-check (qLDPC) codes, which reduce
the resource overhead for error correction
• Applications: Successful use in quantum simulation for material science (e.g., high-temperature supercon-
ductors) and in solving combinatorial optimization problems, such as the Maximum Independent Set
1 See Aquila website
2 See Pasql website
3 See Neutral atom quantum computing hardware: performance and end-user perspective
4 See Neutral atom innovations by quantum systems accelerator mark quantum computing milestones
5. Phase V: Concluding Lectures 84

Note:-
Research suggests neutral atom quantum computers are gaining traction due to their scalability and high-
fidelity operations. Companies like QuEra and Pasqal are pushing the boundaries, with applications already
showing promise in specialized domains.

Photonic Quantum Computers


Photonic quantum computers use photons as qubits, offering a different approach to quantum computing with
unique advantages and challenges.

Basic Principles
In photonic quantum computing, qubits are encoded in properties of photons, such as polarization, path, or time-
bin. Photons are particularly suitable for quantum communication due to their ability to travel long distances
with low loss.

Key operations include:

• State Preparation: Generating single photons or entangled photon pairs.


• Single-Qubit Gates: Implemented using linear optical elements like beam splitters and phase shifters.
• Two-Qubit Gates: Achieved through interference and measurement, often requiring post-selection or
feed-forward techniques.
• Measurement: Detected using photon-number-resolving detectors or other methods.

Definition 5.2.2: Linear Optical Quantum Computing

Linear optical quantum computing uses linear optical elements to manipulate photonic qubits. The
Knill-Laflamme-Milburn (KLM) protocol enables universal quantum computing with linear optics, ancilla
photons, and post-selection, described by the transformation:

𝑈 = 𝑒 𝑖(𝑎
† 𝑏+𝑎𝑏 † )𝜃

where 𝑎 and 𝑏 are photon creation operators, and 𝜃 is the phase shift.

Hardware Implementations
Major players in photonic quantum computing include PsiQuantum and Xanadu. PsiQuantum is developing a
manufacturable photonic quantum computer using silicon photonics, with plans for a commercial system by 20295
In 2025, PsiQuantum announced the Omega chipset, a utility-scale photonic quantum computing chipset with
improved components, such as better photon detectors and reduced signal loss in optical waveguides 6

Additionally, a scale model of a photonic quantum computer called Aurora was demonstrated in 2025,
using 35 photonic chips to synthesize large cluster states and implement quantum error correction 7 .

Table 5.2: Key Photonic Quantum Computing Systems

Company/Project System Status


PsiQuantum Omega In development, commercial by 2029
Aurora Scale model 35 chips, demonstrated 2025
Xanadu Borealis Cloud-accessible prototype

5 See Sources: PsiQuantum Raising $750 Million to Push Photonic Quantum Computers Toward Commercial Reality
6 See PsiQuantum Announces Omega, a Manufacturable Photonic Quantum Computing Chipset
7 Scaling and networking a modular photonic quantum computer
5. Phase V: Concluding Lectures 85

Photonic Quantum Computers


Photonic quantum computers use photons as qubits, offering a different approach to quantum computing with
unique advantages and challenges.

Advantages
• Room-Temperature Operation: Most components operate at room temperature, reducing cooling re-
quirements.
• Integration with Networks: Photons can be easily transmitted over fiber optics, facilitating integration
with classical and quantum networks.

• Low Decoherence: Photons are less susceptible to decoherence compared to other qubit modalities.

Challenges
• High Loss Rates: Current photonic systems suffer from significant optical losses, with total losses around
56% in some components. Fault tolerance requires loss budgets of ∼1%, which is a major hurdle.
• Scalability: While photons are ideal for communication, creating and manipulating large numbers of
entangled photons is challenging.

Recent Developments
Significant progress in 2025 includes:

• Aurora System: A 35-chip photonic quantum computer that demonstrated the synthesis of a cluster state
with 86.4 billion modes and implemented a quantum error correction code.
• PsiQuantum’s Funding and Progress: In 2025, PsiQuantum raised at least $750 million to advance
its photonic quantum computing technology, with significant government support from the U.S., Australia,
and the UK.
• Component Improvements: Developments in photon detectors, optical waveguides, and high-speed
switches have improved the performance of photonic systems.

Applications
Photonic quantum computers are particularly suited for:

• Quantum Communication: Enabling secure communication protocols like quantum key distribution.
• Quantum Simulation: Simulating quantum systems that are difficult to model classically.

• General Quantum Computing: Once fault tolerance is achieved, they could perform a wide range of
computational tasks.

Note:-
The evidence leans toward photonic quantum computers being a strong contender for quantum communica-
tion and networking, with significant investments in 2025 signaling confidence in their commercial potential.
However, overcoming loss rates remains a critical challenge.
5. Phase V: Concluding Lectures 86

Comparison and Future Outlook


Both neutral atom and photonic quantum computers offer distinct advantages and face unique challenges.

• Neutral Atom Systems: More mature in terms of qubit numbers and gate fidelities, with systems already
operating with hundreds of qubits. However, they require cryogenic temperatures for some operations and
have slower gate speeds.
• Photonic Systems: Operate at room temperature and have natural advantages for communication and
networking. However, they currently suffer from high loss rates and are less mature in terms of large-scale
implementation.

The future of quantum computing may see a combination of these technologies, with photonic systems
handling communication and neutral atom systems performing computations, or vice versa. Alternatively, one
technology might emerge as the leader once fault tolerance is achieved.

In terms of timelines, PsiQuantum aims to deliver a commercial photonic quantum computer by 2029,
while neutral atom systems are already being used for specific applications today. Research suggests that hybrid
approaches or advancements in error correction could accelerate progress in both fields.

Aside
The race to build practical quantum computers continues, with both neutral atom and photonic approaches
showing significant promise. As research progresses, we can expect to see larger systems, improved error
correction, and new applications emerging in the coming years.
Chapter 6

Quantum Computing Quick Reference

6.1 Cheatsheet

Linear Algebra |−⟩ = √1 (|0⟩ − |1⟩)


2
Pauli Gates
𝜋 𝜋
Notation (𝜃 = 2 , 𝜙 = 0; 𝜃 = 2 , 𝜙
= 𝜋)  
0 1
• Phase: {| + 𝑖⟩, | − 𝑖⟩} where • Pauli-X (NOT): 𝑋 =
1 0
𝛼
  | + 𝑖⟩ = √1 (|0⟩ + 𝑖|1⟩)
• Bra-Ket: Ket |𝜓⟩ = , Bra 2 – 𝑋|0⟩ = |1⟩, 𝑋|1⟩ = |0⟩
𝛽 | − 𝑖⟩ = √1 (|0⟩ − 𝑖|1⟩) – 𝑋|+⟩ = |+⟩,
2  𝑋|−⟩ = −|−⟩
⟨𝜓| = [𝛼∗ 𝛽 ∗ ] 𝜋 𝜋 𝜋
= − 𝜋2 )
2,𝜙 = 2;𝜃 = 2,𝜙
(𝜃 = 0 −𝑖
• Inner Product: • Pauli-Y: 𝑌 =
𝑖 0
⟨𝜙|𝜓⟩ = 𝜙† 𝜓 = 𝑖 𝜙∗𝑖 𝜓 𝑖
Í
– 𝑌|0⟩ = 𝑖|1⟩, 𝑌|1⟩ = −𝑖|0⟩ 
• Norm: ∥𝜓∥ = ⟨𝜓|𝜓⟩ = 𝑖 |𝜓 𝑖 |2
2 Í 
1 0
• Outer Product: Bloch Sphere • Pauli-Z (Phase Flip): 𝑍 =
0 −1
𝜓 𝜙∗ 𝜓1 𝜙2∗
 
|𝜓⟩⟨𝜙| = 1 1∗ ∗ – 𝑍|0⟩ = |0⟩, 𝑍|1⟩ = −|1⟩
𝜓2 𝜙1 𝜓2 𝜙2 • Equation: |𝜓⟩ = cos 𝜃2 |0⟩ + 𝑒 𝑖𝜙 sin 𝜃2 |1⟩ – 𝑍|+⟩ = |−⟩, 𝑍|−⟩ = |+⟩
𝜓 1 𝜙 1  where 𝜃 ∈ [0, 𝜋], 𝜙 ∈ [0, 2𝜋)
𝜓 𝜙  • Cartesian Projection:
 
• Tensor Product: |𝜓⟩ ⊗ |𝜙⟩ =  1 2 
𝜓 2 𝜙 1 
𝜓 𝜙 
 2 2 𝑥 = sin 𝜃 cos 𝜙 Rotation Gates
• Matrix Mult: (𝐴𝐵)𝑖𝑗 = 𝑘 𝐴 𝑖 𝑘 𝐵 𝑘 𝑗 𝑦 = sin 𝜃 sin 𝜙
Í
• X-rotation:
• Unitary: 𝑈 † 𝑈 = 𝑈𝑈 † = 𝐼, preserves 𝑧 = cos 𝜃

cos 𝜃2 −𝑖 sin 𝜃2

norms and inner products 𝑅 𝑋 (𝜃) = 𝑒 −𝑖𝜃𝑋/2 =
−𝑖 sin 𝜃2 cos 𝜃2
• Hermitian: 𝐻 = 𝐻 † , eigenvalues are
• Y-rotation:
real cos 𝜃2 − sin 𝜃2
 
Quantum 𝑅𝑌 (𝜃) = 𝑒 −𝑖𝜃𝑌/2 =

• Magnitude: Real: ∥𝑣∥ = 𝑖 𝑣𝑖 ,
2
sin 𝜃2 cos 𝜃2
• Z-rotation:
Measurement

Complex: ∥𝑣∥ = 𝑖 |𝑣 𝑖 |2
𝑒 −𝑖𝜃/2
 
0
𝑅 𝑍 (𝜃) = 𝑒 −𝑖𝜃𝑍/2 =
Important Property: Tensor prod- • Probability: For measuring state |𝜓⟩ 0 𝑒 𝑖𝜃/2
ucts are not commutative: 𝐴 ⊗ 𝐵 ≠ 𝐵 ⊗ 𝐴 in basis |𝑏⟩:
generally
𝑃(𝑏) = |⟨𝑏|𝜓⟩|2 Other Important
• Post-measurement state: Gates
Qubit Representation |𝑏⟩⟨𝑏|𝜓⟩ 1 1
 
|𝜓new ⟩ = p • Hadamard: 𝐻 = √1
𝑃(𝑏) 1 −1
2
• Dirac Notation: |𝜓⟩ = 𝛼|0⟩ + 𝛽|1⟩,
– 𝐻|0⟩ = |+⟩, 𝐻|1⟩ = |−⟩
where 𝛼, 𝛽 ∈ ℂ and |𝛼|2 + |𝛽|2 =1 
• For |𝜓⟩ = 𝛼|0⟩ + 𝛽|1⟩: – 𝐻|+⟩ = |0⟩, 𝐻|−⟩ = |1⟩
1
• Computational Basis: |0⟩ = , – 𝐻2 = 𝐼
0 𝑃(0) = |𝛼|2 , 𝑃(1) = |𝛽|2

1 0

  • Phase (S): 𝑆 =
0 0 𝑖
|1⟩ =
1 – 𝑆|+⟩ = | + 𝑖⟩ = √1 (|0⟩ + 𝑖|1⟩)
2
Single-Qubit Gates – 𝑆2 = 𝑍  
1 0
Universal Bases • Properties:
• T Gate: 𝑇 =
0 𝑒 𝑖𝜋/4
• Computational: {|0⟩, |1⟩} – Reversible: 𝑈 † 𝑈 = 𝑈𝑈 † = 𝐼 – 𝑇|+⟩ = √1
(|0⟩ + 𝑒 𝑖𝜋/4 |1⟩)
2
(𝜃 = 0, 𝜙 = 0; 𝜃 = 𝜋, 𝜙 = 0) – Preserve norm: ∥𝑈|𝜓⟩∥ = ∥|𝜓⟩∥ – 𝑇 2 = 𝑆, 𝑇 4 = 𝑍
• Hadamard: {|+⟩, |−⟩} where – Linear:  
1 0
|+⟩ = √1 (|0⟩ + |1⟩) 𝑈(𝛼|𝜓⟩ + 𝛽|𝜙⟩) = 𝛼𝑈|𝜓⟩ + 𝛽𝑈|𝜙⟩ • General Phase: 𝑃(𝜃) =
2 0 𝑒 𝑖𝜃
6. Quantum Computing Quick Reference 88

– 𝑆 = 𝑃(𝜋/2), 𝑇 = 𝑃(𝜋/4), 𝑍 = 𝑃(𝜋) – To reverse a circuit, apply 𝑈 † • Phase Kickback: When a controlled
gates in reverse order operation transfers a phase from the
• No-Cloning Theorem: Cannot target qubit to the control qubit(s)
Circuit Notation create an identical copy of an unknown
quantum state
• Elements:
– Qubit: Horizontal line
š𝑈 : 𝑈(|𝜓⟩ ⊗ |0⟩) = |𝜓⟩ ⊗ |𝜓⟩ Quantum
– Gates: Boxes with labels • Entanglement: States that cannot be Implementations of
– Measurement: Meter symbol (if factored as tensor products of
available) individual states Classical Logic Gates
– Time: Left → Right – E.g., Bell state: √1 (|00⟩ + |11⟩)
2
– Controlled operations: Vertical • OR Gate: Computes 𝑐 = 𝑎 ∨ 𝑏
line with dot
– Control on |1⟩: Filled dot •
– Control on |0⟩: Empty dot ◦
Bell Pair |𝑎⟩

– Endianness: Top (MSB) → • Bell States (maximally entangled): |𝑏⟩


Bottom (LSB)
+ 1
|Φ ⟩ = √ (|00⟩ + |11⟩)
Important: Matrix order in circuit 2 |𝑐⟩
is opposite to mathematical notation: 1

𝑈1 𝑈2 in circuit = 𝑈2 𝑈1 in matrix form |Φ ⟩ = √ (|00⟩ − |11⟩) – Effect: |𝑎, 𝑏, 𝑐⟩ → |𝑎, 𝑏, 𝑐 ⊕ (𝑎 ∨ 𝑏)⟩
2
1 – Truth Table: |000⟩ → |000⟩,
+
|Ψ ⟩ = √ (|01⟩ + |10⟩) |010⟩ → |011⟩
2 – |100⟩ → |101⟩, |110⟩ → |111⟩
Multi-Qubit Gates |Ψ− ⟩ =
1 • NOR Gate: Computes 𝑐 = ¬(𝑎 ∨ 𝑏)
√ (|01⟩ − |10⟩)
• CNOT (Controlled-NOT): 2
|𝑎⟩
• Bell-Pair Circuit
1 0 0 0
0 1 0 0 |𝑏⟩
 
CNOT =  |0⟩ 𝑞1 𝐻
0 0 0 1

0 0 1 0
|𝑐⟩ 𝑋

– Effect: |𝑐, 𝑡⟩ → |𝑐, 𝑡 ⊕ 𝑐⟩ |0⟩ 𝑞0 𝑋
– |00⟩ → |00⟩, |01⟩ → |01⟩ – Effect:
– |10⟩ → |11⟩, |11⟩ → |10⟩ |𝑎, 𝑏, 𝑐⟩ → |𝑎, 𝑏, 𝑐 ⊕ ¬(𝑎 ∨ 𝑏)⟩
• Controlled-Z: Grover’s Algorithm – Truth Table: |000⟩ → |001⟩,
1 0 0 0 |010⟩ → |010⟩
• Purpose: Search unstructured √ – |100⟩ → |100⟩, |110⟩ → |110⟩
0 1 0 0
 
CZ =  database of 𝑁 items in 𝑂( 𝑁) time • AND Gate: Computes 𝑐 = 𝑎 ∧ 𝑏
0 0 1 0

0 0 0 −1 • Algorithm:
√ = 𝐻 |0⟩

1. Initialize: |𝑠⟩ ⊗𝑛 ⊗𝑛
|𝑎⟩
– Effect: |𝑥, 𝑦⟩ → (−1)𝑥 𝑦 |𝑥, 𝑦⟩ 2. Repeat 𝑂( 𝑁) times:
– Only changes |11⟩ → −|11⟩ – Oracle (𝑂): |𝑏⟩
– Symmetric: Either qubit can be 𝑂|𝑥⟩ = (−1) 𝑓 (𝑥) |𝑥⟩ where
control 𝑓 (𝑥) = 1 for solution |𝑐⟩
• Toffoli (CCNOT): – Diffusion (𝐷): 𝐷 = 2|𝑠⟩⟨𝑠| − 𝐼
– Effect: |𝑥, 𝑦, 𝑧⟩ → |𝑥, 𝑦, 𝑧 ⊕ (𝑥 · 𝑦)⟩ 3. Measure to find solution with – Effect: |𝑎, 𝑏, 𝑐⟩ → |𝑎, 𝑏, 𝑐 ⊕ (𝑎 ∧ 𝑏)⟩
– Flips target only if both controls high probability – Truth Table: |000⟩ → |000⟩,
are |1⟩ |010⟩ → |010⟩
• SWAP: Important Insight: Grover’s algo-
rithm provides quadratic speedup over – |100⟩ → |100⟩, |110⟩ → |111⟩
1 0 0 0 classical search, which is proven to be – Direct implementation using
0 0 1 0 Toffoli gate
 
SWAP =  optimal for quantum algorithms
0 1 0 0
 • NAND Gate: Computes 𝑐 = ¬(𝑎 ∧ 𝑏)
• Circuit
0 0 0 1

|𝑎⟩
– Effect: |𝑎, 𝑏⟩ → |𝑏, 𝑎⟩ 𝑞 𝑛−1 𝐻
– Implementation: |𝑏⟩
CNOT1,2 · CNOT2,1 · CNOT1,2 𝑞 𝑛−2 𝐻

• Flipped CNOT: 𝑓 (𝑥)


..
.
..
. Oracle
..
.
Diffusion Circuit ..
. |𝑐⟩ 𝑋
1 0 0 0 𝑞1 𝐻
0 0 0 1
 
(𝐻 ⊗ 𝐻) · CNOT · (𝐻 ⊗ 𝐻) =  – Effect:
0 0 1 0 |𝑎, 𝑏, 𝑐⟩ → |𝑎, 𝑏, 𝑐 ⊕ ¬(𝑎 ∧ 𝑏)⟩

𝑞0 𝐻
0 1 0 0
 – Truth Table: |000⟩ → |001⟩,
| {z

} |010⟩ → |011⟩
2𝑛 times – |100⟩ → |101⟩, |110⟩ → |110⟩
Key Quantum Repeat
• General Diffusion Circuit: Layer of • XOR Gate: Computes 𝑐 = 𝑎 ⊕ 𝑏
Properties H, then layer of X, H on LSB, then
|𝑎⟩
Controlled-X layer over all qubits,
• Reversibility: All quantum gates are another H on LSB, then layer of X, and
reversible then layer of H |𝑏⟩
6. Quantum Computing Quick Reference 89

– For 3-qubit implementation: • Comparison: • Max-Cut Circuit (𝑃 = 1):


– CNF: Intuitive, scales with
|𝑎⟩ clauses, higher depth
𝑞0 𝐻 𝑒 −𝑖𝛾𝑍𝑍 𝑒 −𝑖𝛾𝑍𝑍 𝑅 𝑋 (2𝛽)

– ANF: Compact, typically fewer 𝑞1


|𝑏⟩ 𝐻 𝑅 𝑋 (2𝛽)
ancilla, lower depth, needs 𝑍𝑍
conversion 𝑞2 𝐻 𝑅 𝑋 (2𝛽)
|𝑐⟩ 𝑍𝑍
ANF Advantage: Can reduce ancilla 𝑞3 𝐻 𝑅 𝑋 (2𝛽)
– Effect: |𝑎, 𝑏, 𝑐⟩ → |𝑎, 𝑏, 𝑐 ⊕ (𝑎 ⊕ 𝑏)⟩ qubits, simplifies oracle for Grover’s SAT
– Truth Table: |000⟩ → |000⟩, • Gate Implementation:
|010⟩ → |011⟩ −𝑖𝛾𝑍 𝑖 𝑍 𝑗
– 𝑒 : CNOT, 𝑅 𝑍 (2𝛾), CNOT
– |100⟩ → |101⟩, |110⟩ → |110⟩ – 𝑒 −𝑖𝛽𝑋𝑖 : 𝑅 𝑋 (2𝛽)
• XNOR Gate: Computes 𝑐 = ¬(𝑎 ⊕ 𝑏)
Variational Quantum • Properties:
|𝑎⟩ – Advantages: NISQ-friendly
Algorithms (VQA) (small 𝑃), scales to exact solution
|𝑏⟩ as 𝑃 → ∞
• Overview: Hybrid quantum–classical – Limitations: Barren plateaus,
algorithms that iteratively optimize a unproven speedup
|𝑐⟩ 𝑋 parameterized quantum circuit.
QAOA Insight: Hybrid approach
• Process:
– Effect: leverages quantum circuits for state
1. State Preparation: Create an
|𝑎, 𝑏, 𝑐⟩ → |𝑎, 𝑏, 𝑐 ⊕ ¬(𝑎 ⊕ 𝑏)⟩ preparation and classical optimization
ansatz 𝜓(𝜃) .
– Truth Table: |000⟩ → |001⟩, for parameter tuning, balancing NISQ
2. Measurement: Evaluate a cost
|010⟩ → |010⟩ constraints with computational power
function 𝐶(𝜃) based on quantum
– |100⟩ → |100⟩, |110⟩ → |111⟩
measurement outcomes.
Important Note: The output qubit |𝑐⟩ 3. Optimization: Adjust the
should be initialized to |0⟩ for classical parameters 𝜃 using a classical
logic gate operation. The circuits pre- optimizer. Advanced QAOA
serve input states (|𝑎⟩ and |𝑏⟩) allowing • Example (Bell State Preparation):
• Cost Hamiltonian (𝐻𝐶 ):
for reversible computation.   – Encodes the optimization
𝜓(𝜃) = CNOT 𝑅 𝑦 (𝜃) |0⟩ ⊗ |0⟩ objective. For any computational
basis state |𝑥⟩, the operator
with cost function satisfies
CNF and ANF for 𝐶(𝜃) = 1 − |⟨Φ+ |𝜓(𝜃)⟩|2 , 𝐻𝐶 |𝑥⟩ = 𝐶(𝑥) |𝑥⟩ ,
SAT where |Φ+ ⟩ = √1 (|00⟩ + |11⟩). where 𝐶(𝑥) is the classical cost
2 evaluated on bitstring 𝑥.
• CNF (Conjunctive Normal Form): – Max-Cut Example: The cost
– Form: 𝑖 (∨ 𝑗 𝑙 𝑖𝑗 ), 𝑙 𝑖𝑗 = 𝑥 𝑘 or ¬𝑥 𝑘
Ó
function is defined as
(literals) Quantum 1 Õ  
– E.g., (¬𝐴 ∨ ¬𝐶) ∧ (𝐽 ∨ 𝑃) 𝐶= 𝐼 − 𝑍𝑖 𝑍 𝑗 ,
2
– Quantum: OR gates per clause, Approximate (𝑖,𝑗)∈𝐸
multi-controlled 𝑋 for AND,
which assigns a cost based on the
𝑂(# clauses) ancilla Optimization number of edges cut by a
– Circuit:
𝑥1 Algorithm (QAOA) partition.
• Mixing Hamiltonian (𝐻 𝑀 ):
• Purpose: Approximate solutions to – Drives exploration of the solution
𝑥2 space; standard form:
combinatorial optimization problems
Õ
(e.g., Max-Cut) using a hybrid 𝐻𝑀 = 𝑋𝑖 .
𝑎1
quantum-classical approach 𝑖
• Key Components:
𝑥3 – Cost Hamiltonian (𝐻 – Advanced variants (e.g., XY
Í𝐶 ): Encodes mixers) can preserve additional
problem, e.g., 𝐻𝐶 = ⟨𝑖,𝑗⟩ 𝑍 𝑖 𝑍 𝑗 for
𝑎2 Max-Cut problem constraints.
– Mixing Hamiltonian (𝐻 𝑀 ): • Circuit Structure:
• ANF (Algebraic Normal Form): DrivesÍexploration, typically 1. Initialization: Prepare the
– Form: XOR of AND terms, e.g., 𝐻 𝑀 = 𝑖 𝑋𝑖 uniform superposition via
𝑓 = 𝐽 ⊕ 𝐶𝐽 – Ansatz : 𝜓(𝛾, 𝛽) = |𝑠⟩ = 𝐻 ⊗𝑛 |0⟩ ⊗𝑛 .
– Conversion: From CNF via truth Î𝑃 −𝑖𝛽 𝑝 𝐻 𝑀 −𝑖𝛾𝑝 𝐻𝐶 2. Alternating Layers: For each
table or Boolean algebra 𝑝=1 𝑒 𝑒 |𝑠⟩, where
layer 𝑝 = 1, . . . , 𝑃 apply:
– Quantum: CNOT/Toffoli for |𝑠⟩ = 𝐻 ⊗𝑛 |0⟩ ⊗𝑛 – Cost evolution: 𝑒 −𝑖𝛾𝑝 𝐻𝐶 .
XOR/AND, 𝑂(1) ancilla – Goal: Minimize – Mixer evolution: 𝑒 −𝑖𝛽 𝑝 𝐻𝑀 .
(typically 1) ⟨𝜓(𝛾, 𝛽)|𝐻𝐶 |𝜓(𝛾, 𝛽)⟩ 3. Measurement: Read out in the
– Circuit: • Steps: computational basis.
𝑥1 1. Initialize: |𝑠⟩ = 𝐻 ⊗𝑛 |0⟩ ⊗𝑛 (e.g., • Parameter Optimization:
𝑛 = 10 for ‘10 N → H‘) – Classical methods (e.g.,
𝑥2 2. Apply 𝑃 layers of 𝑒 −𝑖𝛾𝑝 𝐻𝐶 and COBYLA, BFGS) adjust
𝑒 −𝑖𝛽 𝑝 𝐻𝑀 {𝛾𝑝 , 𝛽 𝑝 }.
𝑥3 3. Measure ⟨𝐻𝐶 ⟩ – Initialization strategies include
4. Optimize 𝛾𝑝 , 𝛽 𝑝 classically random starts, linear ramps, or
𝑎 5. Repeat until convergence layer-by-layer training.
6. Quantum Computing Quick Reference 90

• Scaling & Limitations: • Matrix Exponentiation: Circuit Equivalences


– Increasing 𝑃 can improve
cos 𝜃 −𝑖 sin 𝜃 • CNOT Variants:
 
approximation quality
𝑒 −𝑖𝜃𝑋 = 𝑅 𝑋 (2𝜃) = – CNOT = CX = (𝐼 ⊗ 𝐻) · CZ · (𝐼 ⊗ 𝐻)
(approaching adiabatic dynamics) −𝑖 sin 𝜃 cos 𝜃
but raises challenges such as – Flipped CNOT:
cos 𝜃 − sin 𝜃
 
barren plateaus and hardware 𝑒 −𝑖𝜃𝑌 = 𝑅𝑌 (2𝜃) = (𝐻 ⊗ 𝐻) · CNOT · (𝐻 ⊗ 𝐻) (swaps
sin 𝜃 cos 𝜃 control and target)
noise.
𝑒 −𝑖𝜃 • Pauli Transformations:
 
0
𝑒 −𝑖𝜃𝑍 = 𝑅 𝑍 (2𝜃) = – 𝐻𝑋𝐻 = 𝑍
0 𝑒 𝑖𝜃
QUBO – 𝐻𝑍𝐻 = 𝑋
• Expected Value: – 𝑋𝑌𝑋 = −𝑌, 𝑌𝑍𝑌 = −𝑍,
• General Form of Cost Function: 𝑍𝑋𝑍 = −𝑋
𝑛−
Õ1 𝑛−
Õ1 𝑛−
Õ1 ⟨𝐻𝐶 ⟩ = ⟨𝜓|𝐻𝐶 |𝜓⟩ • Phase Gate Relations:
𝑐(𝑥) = 𝑐 𝑖𝑗 𝑥 𝑖 𝑥 𝑗 + 𝑐𝑖 𝑥𝑖 Õ – 𝑆 = 𝑇 2 , 𝑍 = 𝑆2 = 𝑇4
𝑖=0 𝑗=0 𝑖=0
= 𝑐(𝑥)|⟨𝑥|𝜓⟩|2 1 −𝑖
𝑥 – 𝐻𝑆𝐻 = √1 (rotates basis)
2 𝑖 1
• X-Basis ↔ s-Basis Conversions: Õ
= 𝑐(𝑥)𝑃(𝑥) • Rotation Decompositions:
1
𝑥 𝑖 = (1 − 𝑠 𝑖 ) 𝑥 – 𝑅 𝑋 (𝜃) = 𝐻𝑅 𝑍 (𝜃)𝐻
2 – 𝑅𝑌 (𝜃) = 𝑆† 𝑅 𝑍 (𝜃)𝑆
𝑠 𝑖 = 1 − 2𝑥 𝑖 = (−1)𝑥 𝑖 where 𝑃(𝑥) is the probability of
where 𝑠 𝑖 ∈ {−1, 1} are spin variables measuring bitstring 𝑥
Appendix

algebraic normal form, 39 eigenvalue, 5


ansatz, 42 eigenvalue equation, 5
Hermitian, 4
Bloch sphere, 7 Pauli matrices, 10
azimuthal angle, 7 unitary, 4
Cartesian coordinates conversion, 7 multi-qubit systems, 15
global phase, 7
polar angle, 7 neutral atom quantum computers, 82
advantages, 83
Circuit notation, 11 challenges, 83
multi-qubit gates, 17, 21 recent development, 83
Cirq, 28
introduction, 29 photonic quantum computers, 84
classical computing, 2, 6 advantages, 85
critical path, 67 applications, 85
challenges, 85
directed acyclic graph, 67 recent development, 85
proven quantum speedup algorithms, 41
entanglement, 25
QFT, 41
Bell state, 26
Shor’s Algorithm, 41
GHZ state, 27
n-qubit Bell state, 27 quantum annealers, 78
partial entanglement, 28 Quantum Approximate Optimization Algorithms,
proof, 26 44
error correction advantages, 48
classical error detection, 72 ansatz, 44
phase flip errors, 74 Applications, 61
quantum error detection, 72 Cost Hamiltonian, 44
repetition code, 72 Cost Hamiltonians, 49
syndrome, 73 Full QAOA Circuit, 51
Euler’s formula, 2 Implementing Cost Hamiltonians, 50
limitations, 49
Grover’s Search Algorithm
Mixer Hamiltonians, 50
Alexandria Ship Example, 36
Mixing Hamiltonian, 44
circuit, 31
Parameter Optimization, 52
problem statement, 31
PennyLane, 55
pseudocode, 33
QUBO, 57
heuristic quantum algorithms, 41 Theoretical Insights, 54
QAOA, 41 quantum compilers, 63
quantum machine learning, 41 optimizations, 63, 65
quantum stimulation, 41 quantum gates, 10
𝑛-qubit gates, 21
logical to physical mapping, 68 AND gate, 34
multi-qubit gates, 16
matrix CNOT with swapped target and control, 19
APPENDIX 92

controlled gates, 16 Reversibility Property of Quantum Computing, 22


controlled-Z gate, 17
SWAP gate, 20 superconducting qubit architectures, 65
Toffoli gate, 21 superposition, 1, 6
NAND gate, 35
trapped ion quantum computers, 80
NOR gate, 34
NOT gate, 11 universal bases
OR gate, 34 computational, 5, 7
optimizations, 38 angles, 9
Pauli-Y gate, 11 measurement, 9
Phase-Flip gate, 11 properties, 5
properties, 10 Hadamard basis, 7
rotation gates, 10 angles, 9
X-axis, 10 phase basis, 7
Y-axis, 10 angles, 9
Z-axis, 10
single-qubit gates, 13 Variational Quantum Algorithms, 42
vector, 2
General Phase gate, 14
adjoint, 2
Hadamard gate, 13
column, see ket 2
Phase gate, 13
dagger, see adjoint 2
T gate, 13 Dirac notation, 2, 7
quantum kickback, 35 bra, 2
quantum measurement, 8, 14 ket, 2
measurement bases, 14 eigenvector, 5
properties, 9 Euclidean norm, 3
Quantum No-Cloning Theorem, 23 inner product, 3
proof, 24 orthogonality, 3
qubit, 5, 6 outer product, 3
properties, 6 tensor product, 3
superposition, 9 properties, 15

You might also like