Quantum Computing Book
Quantum Computing Book
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
• 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.
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.
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.
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):
1+𝑖
• Example: |𝑣⟩ = , ⟨𝑣| = 1 − 𝑖
2 .
2
𝑒 𝑖𝜔 = cos(𝜔) + 𝑖 sin(𝜔)
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
𝑣1
𝑣2
vw = . 𝑤 1
†
𝑤2 ... 𝑤𝑛
..
𝑣
𝑚
This operation is useful for constructing quantum operators.
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.
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
𝑈 †𝑈 = 𝐼
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
𝐻 = 𝐻†
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 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 𝑖
𝐴v = 𝜆v
where 𝜆 ∈ ℂ is the eigenvalue. Eigenvalues provide insight into the structure of linear transformations.
In Braket notation, the eigenvalue equation is:
𝐴|v⟩ = 𝜆|v⟩
𝛼
𝜓 = 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:
Question 1
Show that any unitary matrix preserves the inner product of two vectors.
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:
• Quantum Computing: Allows coherent superposition with complex amplitudes and quantum interfer-
ence.
1. Phase I: Introduction and Background 7
𝜃 𝜃
|𝜓⟩ = 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:
Rearranging the Bloch sphere formula, we obtain that 𝜃 and 𝜙 can be expressed as:
!
𝛼2
𝜃 = 2 arccos(𝛼 1 ), 𝜙 = −𝑖 ln 𝜃
sin 2
𝑧 |0⟩
𝑦
|𝜓⟩
𝑥
|1⟩
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:
• Post-measurement state:
|𝑏⟩⟨𝑏|𝜓⟩
|𝜓new ⟩ = p
𝑃(𝑏)
⟨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:
A qubit exists in a complex vector space called a Hilbert space. The state of a qubit is given by:
where 𝑏 ∈ {0, 1}. This formula captures the quantum measurement postulate and ensures proper normalization
of the post-measurement state.
2
𝑃(𝑏) = ⟨𝑏|𝜓⟩
1. Phase I: Introduction and Background 10
Note:-
Probability Properties of Measurement:
𝑃(0) = 1 − 𝑃(1)
𝑃(+) = 1 − 𝑃(−)
𝑃(+𝑖) = 1 − 𝑃(−𝑖)
|𝜓final ⟩ = 𝑈|𝜓initial ⟩
Aside
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
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⟩
|0⟩ 𝑌 𝑋 𝑖 |0⟩
Question 3: Exercise 1
Solution:
1
𝐻|0⟩ = √ (|0⟩ + |1⟩)
2
1 1
𝑋𝐻|0⟩ = √ (|1⟩ + |0⟩) = √ (|0⟩ + |1⟩)
2 2
1
𝑆𝑋𝐻|0⟩ = √ (|0⟩ + 𝑖|1⟩)
2
Therefore:
Question 4: Exercise 2
Question 5: Exercise 3
Quantum gates manipulate individual qubits. Single-qubit gates are represented by unitary matrices that
operate on a single qubit.
Properties:
– Self-inverse: 𝐻 2 = 𝐼
– Maps computational basis to |±⟩ basis:
1
|+⟩ = √ (|0⟩ + |1⟩)
2
1
|−⟩ = √ (|0⟩ − |1⟩)
2
Note:-
𝐻 |0⟩ = |+⟩ , 𝐻 |1⟩ = |−⟩ , 𝐻 |+⟩ = |0⟩ , 𝐻 |−⟩ = |1⟩
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:
• T Gate:
1 0
𝑇=
0 𝑒 𝑖𝜋/4
Properties:
– 𝑇2 = 𝑆
– 𝑇4 = 𝑍
– Often used in quantum error correction
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.
𝑃(0) = ||𝛼||2
𝑃(1) = ||𝛽||2
• Y-basis: Eigenstates of Y
Multi-Qubit Systems
States for multiple qubits are represented as tensor products:
2𝑛 −1
𝑘=Õ Õ
𝜓 = 𝛼 𝑘 |𝑘⟩ , ||𝛼 𝑘 ||2 = 1
𝑘=0
Question 6: Exercise 1
†1 1 1
𝐻 =√ =𝐻
2 1 −1
1 1 1 1 1 1 0
𝐻𝐻 = = =𝐼
2 1 −1 1 −1 0 1
Question 7: Exercise 2
For 𝜓 = √1 (|00⟩ + |11⟩), find measurement probabilities for |00⟩ and |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
† 1 1 −𝑖
𝑈 =√
2 −𝑖 1
1 1 𝑖
1 −𝑖 1 0
𝑈𝑈 † = =
2 𝑖 1 −𝑖 1 0 1
∴ U is unitary.
Question 9: Exercise 4
Solution:
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
1 0 0 0
0 1 0 0 ®
© ª
𝐶𝑍 =
0 0 1 0 ®
®
«0 0 0 −1¬
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:
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:
For example, consider a circuit with two Hadamard gates applied to different qubits:
𝑞1 𝐻
𝑞0 𝐻
𝑞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.
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
|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.
The control and target qubits of a CNOT gate can be swapped using Hadamard gates:
(𝐻 ⊗ 𝐻) · 𝐶𝑁 𝑂𝑇control,target · (𝐻 ⊗ 𝐻) = 𝐶𝑁 𝑂𝑇target,control
|𝑐⟩ 𝐻 𝐻
|𝑡⟩ 𝐻 𝑋 𝐻
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⟩.
« 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.
«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:
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.
𝜓 𝐻 𝑍 𝑋 𝑋 𝑍 𝐻 𝜓
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 𝜓 .
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:
Since multiple inputs can produce the same output, information is lost, making the operation irreversible.
𝐴
𝐴 𝐵 𝐴∧𝐵
𝐴∧𝐵
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.
𝜓 𝐻 𝑋 𝑋 𝐻 𝜓
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:
𝐻𝑋𝑋𝐻 = 𝐼
The reversibility of quantum computing is crucial for error correction, fault-tolerant quantum computation,
and simulating physical systems where information is conserved.
|𝜓final ⟩ = 𝐶𝐵𝐴|𝜓initial ⟩.
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.
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
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
What is Entanglement?
To understand quantum entanglement, let’s compare classical and quantum communication systems:
• When Alice sends an email, she knows exactly what she sent
2. Phase II: Fundamentals of Quantum Algorithms 26
• 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:
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
1. Entangled circuits cannot be expressed as a product state. For example, the Bell state
1
𝜓Bell = √ (|00⟩ + |11⟩)
2
|0⟩ 𝑞 𝑛−1 𝐻
|0⟩ 𝑞 𝑛−2 𝑋
..
.
|0⟩ 𝑞1 𝑋
|0⟩ 𝑞0 𝑋
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.
|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:
• 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
1 import cirq
Defining Qubits
Cirq supports different types of qubits:
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))
1 import cirq
9 print("Bell Circuit:")
10 print(bell_circuit)
1 import sympy
2 import matplotlib.pyplot as plt
3 # Define a qubit.
4 q = cirq.GridQubit(1, 1)
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.
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 𝑥,
𝐷 = 𝐻 ⊗𝑛 𝑋 ⊗𝑛 (𝐶𝑍) 𝑋 ⊗𝑛 𝐻 ⊗𝑛 ,
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
𝑞 𝑛−1 𝐻
𝑞 𝑛−2 𝐻
.. .. 𝑓 (𝑥) .. ..
. . . Diffusion Circuit .
Oracle
𝑞1 𝐻
𝑞0 𝐻
| {z }
√
Repeat 2𝑛 times
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
𝐷 = 𝐻 ⊗2 𝑋 ⊗2 𝐶𝑍 𝑋 ⊗2 𝐻 ⊗2 .
|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.
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
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.
|𝑏⟩
|𝑐⟩
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
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:
• 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.
Goal: Find the maximum number of passengers (A, C, J, P) satisfying all constraints using Grover’s
algorithm.
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
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:
• 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
We will address both of these inefficiencies to get a shallower and simpler 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.
This reduces gate count and depth per clause, improving the oracle’s efficiency.
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.
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
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.
• 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.
”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.
• 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.
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.
|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))
Output Explanation:
What does ”ansatz” refer to in Quantum Alternating Operator Ansatz (aka QAOA)?
Solution: Making a guess about the quantum circuit to use for optimization.
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.
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.
Optimize parameters 𝛾, 𝛽
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:
𝐻𝐶 ∝ −(𝑍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.
𝑞0 : |0⟩ 𝐻 𝑅 𝑋 (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.
𝑞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
1 import cirq
2 import numpy as np
3 import matplotlib.pyplot as plt
4 from scipy.optimize import minimize
19 return circuit
34 # Simulate
35 simulator = cirq.Simulator()
36 result = simulator.run(measurement_circuit, repetitions=shots)
37 # Process results
38 counts = result.histogram(key='result')
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 )
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
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?
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.
Cost Hamiltonian 𝐻𝐶
Í 1−𝑍 𝑖 𝑍 𝑗 Í 1−𝐶 𝑐
(𝑖,𝑗)∈𝐸 𝑐
Í 1−𝑍 𝑖
2 2
𝑖∈𝑉 2 −
Í (1−𝑍 𝑖 )(1−𝑍 𝑗 )
(𝑖,𝑗)∈𝐸 4
For the Max-Cut problem, each term is of the form 𝑍 𝑖 𝑍 𝑗 , and we can implement 𝑒 −𝑖𝛾𝑍 𝑖 𝑍 𝑗 using the
following circuit:
𝑞𝑖
𝑞𝑗 𝑅 𝑍 (2𝛾)
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
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𝛽)
Advanced Mixers:
This mixer only swaps 0s and 1s between qubits, preserving the total Hamming weight of the state.
Implementation requires more complex gate sequences.
𝑞𝑖 𝐻 𝐻
𝑞𝑗 𝐻 𝑅 𝑍 (2𝛽) 𝐻
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.
𝑞2 𝐻 𝑅 𝑋 (2𝛽 1 ) 𝑅 𝑋 (2𝛽 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
The process of finding optimal values for the parameters 𝛾 = (𝛾1 , . . . , 𝛾𝑃 ) and 𝛽 = (𝛽1 , . . . , 𝛽 𝑃 ) to minimize
the expectation value ⟨𝜓(𝛾, 𝛽)|𝐻𝐶 |𝜓(𝛾, 𝛽)⟩.
Optimization Challenges:
• Barren plateaus: Gradients become exponentially small in high dimensions
• 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.
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
1.5
0.5
𝛾
𝛽
0
10 20 30 40 50 60
Number of vertices 𝑛
What are the main components of a QAOA circuit and how are they arranged?
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.
PennyLane
Figure 3.14: PennyLane connects classical ML frameworks with quantum computing platforms
4 # 1. Define a device
5 dev = qml.device("default.qubit", wires=4)
QAOA Implementation in PennyLane Here’s how to implement QAOA for MaxCut in PennyLane:
2 import networkx as nx
3 from pennylane import numpy as np
35 for i in range(steps):
36 params = optimizer.step(cost_function, 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
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
• Interference costs: 𝐼 𝑖𝑗 represents the penalty if both jobs 𝑖 and 𝑗 are selected
QUBO in Code
6 np.random.seed(42)
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)
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))
55 coeffs=[1.0] * num_qubits,
56 observables=[qml.PauliX(i) for i in range(num_qubits)]
57 )
68 # QAOA layers
69 for i in range(p):
70 qaoa_layer(params[2*i], params[2*i+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} ")
93 # QAOA layers
94 for i in range(p):
95 qaoa_layer(params[2*i], params[2*i+1])
98 # Get samples
99 n_samples = 1000
100 samples = qaoa_measure(params, p=p)
101 samples = np.array([samples for _ in range(n_samples)])
Note:-
The code demonstrates converting a QUBO problem into an Ising Hamiltonian and solving it with QAOA in
PennyLane. Key points:
• 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
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
How many 𝐶𝑋 gates are required to implement the following QUBO cost function:
Solution: To implement this QUBO cost function, we need to count the number of unique two-qubit interactions:
These interactions suggest 4 distinct 𝐶𝑋 gates are required, noting that repeated interactions don’t neces-
sarily increase gate count.
4
• 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
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
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
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
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.
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.
Note:-
Not all gate pairs commute. The non-commutativity of quantum gates is fundamental to quantum computing’s
power and complexity.
A quantum bit implemented using superconducting circuits, typically based on Josephson junctions, op-
erating at extremely low temperatures to maintain quantum coherence.
Aside
Why Are Quantum Computers Kept So Cold?
Typical operating temperatures are around 10-15 millikelvin, colder than outer space!
The deliberate offset of qubit operating frequencies to prevent unwanted interactions and frequency colli-
sions.
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
Key Takeaways
• Quantum compiler optimizations extend beyond simple gate manipulation
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)
• 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:
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
The longest path through the circuit’s DAG representation from input to output, which determines:
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.
The process of assigning logical qubits in a quantum algorithm to physical qubits on a quantum processor,
considering:
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
The process of determining how to move quantum information between non-adjacent qubits on a quantum
processor with limited connectivity, including:
• 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.
• 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
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.
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:
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.
• 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
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
classical error correction with quantum approaches, highlighting the unique challenges posed by quantum me-
chanics.
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.
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.
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.
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 .
• 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
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⟩
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.
• |0𝐿 ⟩ = |+⟩ ⊗𝑛
• |1𝐿 ⟩ = |−⟩ ⊗𝑛
𝑞 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.
𝑞 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
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:
D-Wave Systems
The most prominent implementation of quantum annealing hardware is by D-Wave Systems, which has progressed
through multiple generations:
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:
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.
• Portfolio optimization
• Traffic flow optimization
• Machine learning (training of Boltzmann machines)
• Drug discovery
• Material design
Recent Developments
Recent advances in quantum annealing include:
• Reverse annealing protocols that start from candidate solutions
• Pause-and-quench annealing schedules
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.
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:
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.
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.
• 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.
• 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.
• 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:
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
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.
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.
• 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
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 .
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.
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.
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 .
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
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
• 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
6.1 Cheatsheet
– 𝑆 = 𝑃(𝜋/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 |𝑎⟩