⬡ Week 2

Entanglement, Interference
& Qiskit

Bell states, quantum teleportation, the no-cloning theorem, the algorithmic paradigm of superposition→interference→measurement, and hands-on Qiskit coding on real IBM quantum hardware.

01

Bell States & Entanglement

Entanglement is the most distinctly non-classical feature of quantum mechanics. When two qubits are entangled, measuring one instantly determines the outcome of measuring the other — regardless of the physical distance between them. Einstein called this "spooky action at a distance" and considered it evidence that quantum mechanics must be incomplete; Bell's theorem (1964) and subsequent experiments definitively proved him wrong.

The Four Bell States

The Bell states (or EPR pairs) are the four maximally entangled two-qubit states forming an orthonormal basis for $\mathbb{C}^4$:

$$\ket{\Phi^+} = \frac{1}{\sqrt{2}}(\ket{00}+\ket{11}), \quad \ket{\Phi^-} = \frac{1}{\sqrt{2}}(\ket{00}-\ket{11})$$ $$\ket{\Psi^+} = \frac{1}{\sqrt{2}}(\ket{01}+\ket{10}), \quad \ket{\Psi^-} = \frac{1}{\sqrt{2}}(\ket{01}-\ket{10})$$

"Maximally entangled" means that measuring either qubit alone gives a completely random result ($P(\ket{0}) = P(\ket{1}) = \frac{1}{2}$), yet the two outcomes are perfectly correlated (or anti-correlated). The reduced density matrix for either qubit is $\frac{1}{2}\mathbb{I}$ — the maximally mixed state.

Generation Circuit

All four Bell states can be generated from computational basis inputs using the circuit: H on qubit 1, then CNOT with qubit 1 as control:

$$\ket{00} \xrightarrow{H\otimes I} \frac{1}{\sqrt{2}}(\ket{0}+\ket{1})\ket{0} \xrightarrow{\text{CNOT}} \frac{1}{\sqrt{2}}(\ket{00}+\ket{11}) = \ket{\Phi^+}$$
Input $\ket{q_1 q_2}$ After $H\otimes I$ After CNOT Bell State
$\ket{00}$ $\frac{1}{\sqrt{2}}(\ket{0}+\ket{1})\ket{0}$ $\frac{1}{\sqrt{2}}(\ket{00}+\ket{11})$ $\ket{\Phi^+}$
$\ket{10}$ $\frac{1}{\sqrt{2}}(\ket{0}-\ket{1})\ket{0}$ $\frac{1}{\sqrt{2}}(\ket{00}-\ket{11})$ $\ket{\Phi^-}$
$\ket{01}$ $\frac{1}{\sqrt{2}}(\ket{0}+\ket{1})\ket{1}$ $\frac{1}{\sqrt{2}}(\ket{01}+\ket{10})$ $\ket{\Psi^+}$
$\ket{11}$ $\frac{1}{\sqrt{2}}(\ket{0}-\ket{1})\ket{1}$ $\frac{1}{\sqrt{2}}(\ket{01}-\ket{10})$ $\ket{\Psi^-}$
Detailed derivation: how the $\ket{10}$ input generates $\ket{\Phi^-}$

Start with $\ket{10}$. First, $H$ acts on qubit 1 (the first qubit). Since $H\ket{1} = \frac{1}{\sqrt{2}}(\ket{0}-\ket{1})$: $$\ket{10} \xrightarrow{H\otimes I} \frac{1}{\sqrt{2}}(\ket{0}-\ket{1})\ket{0} = \frac{1}{\sqrt{2}}(\ket{00}-\ket{10})$$

Now apply CNOT (control = qubit 1, target = qubit 2) to each basis state individually:

  • $\text{CNOT}\ket{00} = \ket{00}$ (control is 0, no flip)
  • $\text{CNOT}\ket{10} = \ket{11}$ (control is 1, target flips)

By linearity: $$\frac{1}{\sqrt{2}}(\ket{00}-\ket{10}) \xrightarrow{\text{CNOT}} \frac{1}{\sqrt{2}}(\ket{00}-\ket{11}) = \ket{\Phi^-}$$ The negative sign from $H\ket{1}$ has been preserved through the CNOT, giving us a minus sign between the two terms.

Bell State Explorer
Select a state · Click a basis vector to simulate measurement collapse

Bell Measurement

The Bell measurement is the reverse of the Bell state preparation circuit — CNOT followed by H on the first qubit, then measure both:

$$\ket{\Phi^+} \xrightarrow{\text{CNOT}} \frac{1}{\sqrt{2}}(\ket{00}+\ket{10}) \xrightarrow{H\otimes I} \ket{00}$$

Let's verify this step by step. Starting from $\ket{\Phi^+} = \frac{1}{\sqrt{2}}(\ket{00}+\ket{11})$:

  • Apply CNOT (control q1, target q2): $\ket{00} \to \ket{00}$, $\ket{11} \to \ket{10}$, so state becomes $\frac{1}{\sqrt{2}}(\ket{00}+\ket{10}) = \frac{1}{\sqrt{2}}(\ket{0}+\ket{1})\ket{0} = \ket{+}\ket{0}$
  • Apply $H$ to q1: $H\ket{+} = \ket{0}$, so state becomes $\ket{0}\ket{0} = \ket{00}$. Measuring: outcome $00$ with certainty. ✓

Each Bell state maps to a unique computational basis outcome:

Input Bell State After CNOT After H⊗I Measurement outcome
$\ket{\Phi^+} = \frac{\ket{00}+\ket{11}}{\sqrt{2}}$ $\ket{+}\ket{0}$ $\ket{00}$ $00$
$\ket{\Phi^-} = \frac{\ket{00}-\ket{11}}{\sqrt{2}}$ $\ket{-}\ket{0}$ $\ket{10}$ $10$
$\ket{\Psi^+} = \frac{\ket{01}+\ket{10}}{\sqrt{2}}$ $\ket{+}\ket{1}$ $\ket{01}$ $01$
$\ket{\Psi^-} = \frac{\ket{01}-\ket{10}}{\sqrt{2}}$ $\ket{-}\ket{1}$ $\ket{11}$ $11$

Each Bell state maps to a unique computational basis outcome, allowing Alice to "identify" which Bell state she measured. This is critical in the teleportation protocol.

💡 Entanglement Correlations are Basis-Independent

A common misconception: "Bell state correlations only appear in the $Z$-basis." In reality, correlations persist in every measurement basis. For $\ket{\Phi^+}$, write it in the $X$-basis: $$\ket{\Phi^+} = \frac{1}{\sqrt{2}}(\ket{00}+\ket{11}) = \frac{1}{2}\big[(\ket{+}+\ket{-})(\ket{+}+\ket{-}) + (\ket{+}-\ket{-})(\ket{+}-\ket{-})\big] = \frac{1}{\sqrt{2}}(\ket{++}+\ket{--})$$ So measuring in the $X$-basis also gives perfectly correlated outcomes — both $++$ or both $--$, each with probability $\frac{1}{2}$. You'll never see $+-$ or $-+$. This basis-independent correlation is what Bell's inequality quantifies, and what makes entanglement fundamentally non-classical.

💡 Bell's Inequality Violation

Bell's theorem (1964) proves that no local hidden variable theory can reproduce all quantum predictions. The CHSH inequality $|S| \leq 2$ is violated by entangled states (quantum mechanics predicts $|S| \leq 2\sqrt{2} \approx 2.83$). Aspect et al. (1982) and subsequent experiments confirm the quantum prediction, ruling out local realism. Entanglement is not an artifact of ignorance — it is a genuine feature of reality.

The Density Matrix and "State City" Visualization

So far we've described quantum states as ket vectors $\ket{\psi}$. But there's an equivalent (and sometimes more powerful) representation: the density matrix (or density operator) $\rho$. For a pure state $\ket{\psi}$, the density matrix is simply the outer product:

$$\boxed{\rho = \ket{\psi}\bra{\psi}}$$ Density matrix of a pure state

This is a matrix whose entries encode everything about the state. For an $n$-qubit system, $\rho$ is a $2^n \times 2^n$ matrix. The diagonal entries $\rho_{ii} = |\alpha_i|^2$ are the populations (probabilities of each basis state), and the off-diagonal entries $\rho_{ij} = \alpha_i \alpha_j^*$ are the coherences — they capture quantum superposition and interference. A state with nonzero off-diagonal entries is in a genuine superposition; a state with only diagonal entries is a classical mixture.

🧪 Example — Density Matrix of a GHZ State

The 3-qubit GHZ state is $\ket{\text{GHZ}} = \frac{1}{\sqrt{2}}(\ket{000} + \ket{111})$. Its density matrix is: $$\rho = \ket{\text{GHZ}}\bra{\text{GHZ}} = \frac{1}{2}\big(\ket{000}\bra{000} + \ket{000}\bra{111} + \ket{111}\bra{000} + \ket{111}\bra{111}\big)$$

As an $8 \times 8$ matrix, this has exactly four nonzero entries, all with amplitude $\frac{1}{2}$:

  • Two diagonal peaks: $\rho_{000,000} = \frac{1}{2}$ and $\rho_{111,111} = \frac{1}{2}$ — the populations (50% probability of $\ket{000}$, 50% for $\ket{111}$)
  • Two off-diagonal peaks: $\rho_{000,111} = \frac{1}{2}$ and $\rho_{111,000} = \frac{1}{2}$ — the coherences (proof that this is a genuine superposition, not a classical coin-flip)

All other entries are zero.

💡 The "State City" Visualization

In Qiskit, the plot_state_city function draws the density matrix as a 3D bar chart — imagine the $2^n \times 2^n$ matrix as a city grid, where each entry is a "building" whose height represents its magnitude. Two separate plots show the real and imaginary parts. For a GHZ state:

  • The real-part city shows exactly 4 bars of height $0.5$: two diagonal ($|000\rangle\langle000|$, $|111\rangle\langle111|$) and two off-diagonal ($|000\rangle\langle111|$, $|111\rangle\langle000|$)
  • The imaginary-part city is completely flat (all amplitudes are real for the GHZ state)

Why it matters: If you prepare a GHZ state on noisy hardware and see the off-diagonal bars shrinking, that's decoherence in action — the environment is destroying the coherences, turning your quantum superposition into a classical mixture. The statevector simulator (not the shot-based QASM simulator) must be used to visualize the density matrix, since it provides exact amplitudes.

Density Matrix Heatmap
Select a state to visualize its populations (diagonal) and coherences (off-diagonal)
Pure States
Mixed States
Qiskit "State City" 3D Rendering (Real Part)
Population
Coherence
(Drag to Rotate · Scroll to Zoom)
Select a state to see details...
CHSH Game Explorer
Play the game to see the quantum advantage
02

Quantum Teleportation

Quantum teleportation is one of the most remarkable quantum protocols. It allows Alice to transmit an unknown quantum state to Bob using only: (1) a pre-shared entangled Bell pair, and (2) two bits of classical communication.

⚠ What Teleportation Is NOT
  • Not FTL communication: Bob must receive Alice's 2 classical bits (via a classical channel, limited by the speed of light) before he can recover $\ket{\psi}$. Until those bits arrive, his qubit is in a maximally mixed state — useless.
  • Not matter teleportation: No physical particle travels from Alice to Bob. What moves is quantum information (the state $\ket{\psi}$), not the carrier.
  • Not copying: Alice's original qubit is destroyed — it collapses to a definite classical state upon measurement. This is required by the No-Cloning Theorem: if Alice's qubit survived intact, Bob would have a second copy, which is forbidden.
  • Not state-aware: Alice need not know $\alpha$ or $\beta$ — the protocol works for any state, including states Alice has never measured or characterised.

Despite its name, teleportation does not transmit matter or allow faster-than-light communication — the classical bits must travel at most at the speed of light. What is transmitted is the quantum state (information), not the particle itself.

💡 The Setup

Alice has an unknown qubit $\ket{\psi} = \alpha\ket{0}+\beta\ket{1}$ (she doesn't know $\alpha$ or $\beta$). She and Bob share a Bell pair $\ket{\Phi^+}_{AB}$. Alice holds qubits 1 (her message qubit) and 2 (her half of the Bell pair); Bob holds qubit 3 (his half of the Bell pair). The total initial state is: $$\ket{\psi}_1 \otimes \ket{\Phi^+}_{23} = (\alpha\ket{0}+\beta\ket{1})_1 \otimes \frac{1}{\sqrt{2}}(\ket{00}+\ket{11})_{23}$$

Full Protocol Derivation

To see how teleportation works, let's track the composite 3-qubit state through every transformation. We have three qubits: Alice's unknown message qubit (1), and the Bell pair shared between Alice (2) and Bob (3).

Step 0: The Initial Configuration

The unknown state to be teleported is $\ket{\psi}_1 = \alpha\ket{0} + \beta\ket{1}$. Alice and Bob share the Bell pair $\ket{\Phi^+}_{23} = \frac{1}{\sqrt{2}}(\ket{00} + \ket{11})$. The initial global state $\ket{\Psi_0}$ is the tensor product of these two independent states:

$$\ket{\Psi_0} = \ket{\psi}_1 \otimes \ket{\Phi^+}_{23} = (\alpha\ket{0} + \beta\ket{1}) \otimes \frac{1}{\sqrt{2}}(\ket{00} + \ket{11})$$

Performing the multiplication (tensor product) explicitly gives 4 terms:

$$\ket{\Psi_0} = \frac{1}{\sqrt{2}} \Big[ \alpha\ket{0}(\ket{00} + \ket{11}) + \beta\ket{1}(\ket{00} + \ket{11}) \Big] = \frac{1}{\sqrt{2}} \left[ \alpha\ket{000} + \alpha\ket{011} + \beta\ket{100} + \beta\ket{111} \right]_{123}$$

Step 1: Alice's First Interaction (CNOT)

Alice applies a CNOT gate with qubit 1 (her message) as the control and qubit 2 (her share of the Bell pair) as the target. This operation entangles the unknown state with the shared resource:

$$\ket{\Psi_1} = \text{CNOT}_{12}\ket{\Psi_0} = \frac{1}{\sqrt{2}} \left[ \alpha\ket{000} + \alpha\ket{011} + \beta\ket{110} + \beta\ket{101} \right]_{123}$$

Note: In the last two terms, where qubit 1 is $\ket{1}$, the second qubit has been flipped ($0 \to 1$ and $1 \to 0$).

Step 2: Rotating the Basis (Hadamard)

Alice now applies a Hadamard gate to qubit 1. This effectively transforms her local basis from $\{|0\rangle, |1\rangle\}$ to the "sign" basis $\{|+\rangle, |-\rangle\}$. Using $H\ket{0} = \frac{1}{\sqrt{2}}(\ket{0}+\ket{1})$ and $H\ket{1} = \frac{1}{\sqrt{2}}(\ket{0}-\ket{1})$, we substitute these into $\ket{\Psi_1}$:

$$\ket{\Psi_2} = \frac{1}{2} \Big[ \alpha(\ket{0}+\ket{1})\ket{00} + \alpha(\ket{0}+\ket{1})\ket{11} + \beta(\ket{0}-\ket{1})\ket{10} + \beta(\ket{0}-\ket{1})\ket{01} \Big]$$

Let's distribute the terms to see the individual configurations:

$$\ket{\Psi_2} = \frac{1}{2} \left[ \alpha\ket{000} + \alpha\ket{100} + \alpha\ket{011} + \alpha\ket{111} + \beta\ket{010} - \beta\ket{110} + \beta\ket{001} - \beta\ket{101} \right]$$

Step 3: The "Magic" of Rearrangement

Now comes the crucial step: we regroup the 8 terms by what Alice's two qubits ($\ket{q_1 q_2}$) look like, so we can see what Bob ends up with in each case. Let's do this one group at a time.

Collect all terms where Alice's qubits are $\ket{00}$ (i.e., the first two qubits are both $\ket{0}$):

$$\alpha\ket{\mathbf{00}0} + \beta\ket{\mathbf{00}1} = \ket{00}\otimes(\alpha\ket{0}+\beta\ket{1}) = \ket{00}\otimes\ket{\psi}$$

Collect all terms where Alice's qubits are $\ket{01}$:

$$\alpha\ket{\mathbf{01}1} + \beta\ket{\mathbf{01}0} = \ket{01}\otimes(\alpha\ket{1}+\beta\ket{0}) = \ket{01}\otimes X\ket{\psi}$$

Collect all terms where Alice's qubits are $\ket{10}$:

$$\alpha\ket{\mathbf{10}0} - \beta\ket{\mathbf{10}1} = \ket{10}\otimes(\alpha\ket{0}-\beta\ket{1}) = \ket{10}\otimes Z\ket{\psi}$$

Collect all terms where Alice's qubits are $\ket{11}$:

$$\alpha\ket{\mathbf{11}1} - \beta\ket{\mathbf{11}0} = \ket{11}\otimes(\alpha\ket{1}-\beta\ket{0}) = \ket{11}\otimes XZ\ket{\psi}$$

Putting all four groups together gives the beautifully structured result:

$$\begin{aligned} \ket{\Psi_2} = \frac{1}{2} \Big[ \quad &\ket{00} (\alpha\ket{0} + \beta\ket{1}) \\ +\ &\ket{01} (\alpha\ket{1} + \beta\ket{0}) \\ +\ &\ket{10} (\alpha\ket{0} - \beta\ket{1}) \\ +\ &\ket{11} (\alpha\ket{1} - \beta\ket{0}) \quad \Big] \end{aligned}$$

Observe how the coefficients $\alpha$ and $\beta$ have been transferred to Bob's qubit! However, they are potentially scrambled by Pauli matrices ($X, Z$).

Step 4: Measurement and Recovery

Alice measures her two qubits. This collapses the global state into one of four equally likely outcomes. She then communicates her 2-bit result (00, 01, 10, or 11) to Bob classically. Bob uses this information to "unscramble" his qubit:

Alice Measures Bob's Collapsed State Relation to $\ket{\psi}$ Bob's Correction
$\ket{00}$ $\alpha\ket{0}+\beta\ket{1}$ $\ket{\psi}$ $I$ (No action)
$\ket{01}$ $\alpha\ket{1}+\beta\ket{0}$ $X\ket{\psi}$ $X$ (Bit flip)
$\ket{10}$ $\alpha\ket{0}-\beta\ket{1}$ $Z\ket{\psi}$ $Z$ (Phase flip)
$\ket{11}$ $\alpha\ket{1}-\beta\ket{0}$ $XZ\ket{\psi}$ $ZX$ (Both)
💡 The "Socks and Shoes" Analogy: Why $(XZ)^{-1} = ZX$?

When Alice measures $\ket{11}$, Bob's qubit is accidentally scrambled into the state $XZ\ket{\psi}$. To undo this and recover the clean $\ket{\psi}$, Bob needs the inverse of $XZ$.

Why wouldn't he just apply $XZ$ again? Think of $Z$ as "putting on your socks", and $X$ as "putting on your shoes". Applying $XZ$ means: socks first, then shoes.

To undo this process, you can't take off your socks while wearing your shoes! You must take off your shoes ($X$) first, and then your socks ($Z$).

$$(XZ)^{-1} = Z^{-1}X^{-1} = ZX$$

This is why matrix inverses reverse the order! Let's verify by doing the math from right to left: $$ZX \cdot XZ\ket{\psi} = Z(\underbrace{XX}_{I})Z\ket{\psi} = \underbrace{ZZ}_{I}\ket{\psi} = \ket{\psi}\;\checkmark$$

No-Cloning Intact: When Alice measures her qubit, the original $\ket{\psi}_1$ is destroyed. Bob creates the replica only after receiving the classical information. No information traveled faster than light!

Teleportation Circuit

The complete teleportation circuit involves three qubits, five gates (CNOT, H, two measurements), and two classical-controlled corrections (indicated by double lines in circuit diagrams). The circuit perfectly illustrates entanglement as a resource: the Bell pair shared in advance is the fuel that enables the quantum information transfer.

03

The No-Cloning Theorem

⚡ No-Cloning Theorem (Wootters & Zurek, 1982)

It is impossible to create a perfect copy of an arbitrary unknown quantum state. That is, there exists no unitary $U$ such that for all $\ket{\psi}$: $$U(\ket{\psi}\ket{0}) = \ket{\psi}\ket{\psi}$$

The "Photocopier Paradox" (Proof by Linearity)

To understand why, imagine a magic quantum photocopier (a unitary machine $U$) that works perfectly on basic states. If you give it a "Black" paper ($\ket{0}$), it prints two Black papers. If you give it a "White" paper ($\ket{1}$), it prints two White papers.

$$U(\ket{0}\ket{0}) = \ket{0}\ket{0} \quad \text{and} \quad U(\ket{1}\ket{0}) = \ket{1}\ket{1}$$

Now, you feed it a "Gray" paper — a superposition: $\ket{\psi} = \frac{1}{\sqrt{2}}(\ket{0}+\ket{1})$. What should happen?

What we WANT (A true clone): We want two identical Gray papers at the end.
Math: $$\ket{\psi}\ket{\psi} = \frac{1}{\sqrt{2}}(\ket{0}+\ket{1}) \otimes \frac{1}{\sqrt{2}}(\ket{0}+\ket{1}) = \frac{1}{2}(\ket{00}+\ket{01}+\ket{10}+\ket{11})$$

What MUST happen (By Quantum Linearity): Quantum mechanics forces the machine to process the inside of the superposition independently. It acts on the $\ket{0}$ part and the $\ket{1}$ part separately, and sums the result:
Math: $$U(\ket{\psi}\ket{0}) = \frac{1}{\sqrt{2}}\Big( U\ket{0}\ket{0} + U\ket{1}\ket{0} \Big) = \frac{1}{\sqrt{2}}(\ket{00}+\ket{11})$$

The Contradiction: The mathematical rules of quantum linearity gave us an entangled state (either both Black or both White), not two independent Gray papers! $$\frac{1}{\sqrt{2}}(\ket{00}+\ket{11}) \neq \frac{1}{2}(\ket{00}+\ket{01}+\ket{10}+\ket{11})$$

Because these two results are fundamentally different, a "perfect copy machine" $U$ cannot exist without breaking the very laws of quantum mechanics. $\square$

💡 Consequences

No-cloning is simultaneously a limitation and a resource:

  • Security: Quantum key distribution (QKD) is secure because an eavesdropper cannot copy qubits without disturbing them
  • Consistency: No-cloning is why teleportation destroys the original — you can't have your quantum cake and eat it too
  • QEC: Error correction must work without copying states — it uses entanglement and syndrome measurements instead
04

Quantum Interference

Interference is the mechanism by which quantum computers achieve their speedups. Just as waves in water can reinforce (constructive interference) or cancel (destructive interference), probability amplitudes can add together or cancel out.

The key difference from classical probability: classical probabilities add as $p(\text{outcome}) = p(\text{path 1}) + p(\text{path 2})$ (always non-negative). Quantum amplitudes add as $\psi = \psi_1 + \psi_2$, and only then $p = |\psi|^2$ — so negative or complex amplitudes can cancel!

$$p = |\psi_1 + \psi_2|^2 = |\psi_1|^2 + |\psi_2|^2 + 2\,\text{Re}(\psi_1^*\psi_2)$$

The cross term $2\,\text{Re}(\psi_1^*\psi_2)$ is the interference term. When $\psi_1^*\psi_2 > 0$ (same phase): constructive interference — probability enhanced. When $\psi_1^*\psi_2 < 0$ (opposite phase): destructive interference — probability suppressed.

Wave Interference Visualizer
ψ₁   ψ₂   ψ₁ + ψ₂
Phase Δφ

Double-Slit Analogy

The quantum double-slit experiment perfectly illustrates interference. A single electron fired at a barrier with two slits produces an interference pattern on the detection screen — even when electrons are sent one at a time. Each electron seems to "go through both slits simultaneously," with its probability amplitude following both paths and interfering with itself.

If you try to detect which slit the electron went through (measure its path), the interference pattern vanishes and you see two classical bands. The act of measurement destroys the superposition and hence the interference. This is the measurement problem at the heart of quantum mechanics.

In quantum algorithms: the algorithm is designed so that amplitudes for "wrong answers" interfere destructively (cancel out), while amplitudes for "right answers" interfere constructively (reinforce). At the end, measuring yields the correct answer with high probability.

Phase Kickback — The Engine of Quantum Algorithms

Phase kickback is the central mechanism powering nearly every quantum algorithm you'll encounter (Deutsch–Jozsa, Bernstein–Vazirani, Grover's, Shor's). It deserves a careful derivation.

⚡ Phase Kickback Theorem

Given a quantum oracle $U_f$ defined by $U_f\ket{x}\ket{y} = \ket{x}\ket{y \oplus f(x)}$, if the ancilla qubit is prepared in the state $\ket{-} = \frac{1}{\sqrt{2}}(\ket{0}-\ket{1})$, then: $$\boxed{U_f\ket{x}\ket{-} = (-1)^{f(x)}\ket{x}\ket{-}}$$ The phase $(-1)^{f(x)}$ "kicks back" from the ancilla onto the data register. The ancilla state is unchanged.

Full derivation of phase kickback

Let's trace exactly how the minus sign travels from the oracle back to the data register.

Step 1: Expand the ancilla
Substitute the definition of $\ket{-}$ into the starting state: $$U_f\ket{x}\ket{-} = U_f \left( \ket{x} \otimes \frac{\ket{0}-\ket{1}}{\sqrt{2}} \right)$$

Step 2: Apply the Oracle (XOR addition)
The oracle applies $\oplus f(x)$ to the terms inside the ancilla: $$= \ket{x} \otimes \frac{\ket{0\oplus f(x)} - \ket{1\oplus f(x)}}{\sqrt{2}}$$

Step 3: Analyze the Cases
Now we evaluate the two possible outcomes for the function $f(x)$:

  • If $f(x) = 0$:
    The numerator becomes $\ket{0} - \ket{1}$.
    State is unchanged: $(+1)\cdot\ket{x}\ket{-}$
  • If $f(x) = 1$:
    The numerator becomes $\ket{1} - \ket{0}$, which is the exact negative of our starting state.
    We pull the minus sign out front: $(-\ket{0} + \ket{1}) = -(\ket{0} - \ket{1})$.
    State flips sign: $(-1)\cdot\ket{x}\ket{-}$

The Conclusion: In both cases, the ancilla returns to its original $\ket{-}$ state unharmed (it acts as a catalyst). Meanwhile, the function's output $f(x)$ is permanently stamped into the phase of $\ket{x}$.

Phase Kickback Demonstration
Observe how the phase moves to the control qubit
05

The Quantum Algorithm Design Paradigm

Nearly all quantum algorithms follow the same three-phase structure. Understanding this paradigm is key to understanding why quantum algorithms work.

1. Superposition
Apply $H^{\otimes n}$ to $\ket{0}^{\otimes n}$ to create equal superposition of all $2^n$ inputs simultaneously
2. Oracle + Interference
Apply problem-specific oracle to mark answer states, then use interference to amplify right answers and suppress wrong ones
⦿
3. Measurement
Measure in computational basis — the correct answer has been amplified and is obtained with high probability
$$\ket{0}^{\otimes n} \xrightarrow{H^{\otimes n}} \frac{1}{\sqrt{2^n}}\sum_{x=0}^{2^n-1}\ket{x} \xrightarrow{U_f + \text{interference}} \sum_{x}c_x\ket{x} \xrightarrow{\text{measure}} \ket{x^*} \text{ with high prob.}$$

The quantum speedup comes not from evaluating $f$ on all inputs simultaneously (you still only get one classical output when you measure), but from engineering interference so that the desired answer has enhanced amplitude. This requires careful algorithm design: "quantum parallelism" alone isn't enough — you must add the interference step.

⚠ Common Misconception

Quantum computers do not simply "try all inputs at once." After creating the superposition $\sum_x \ket{x}$, measuring immediately gives a uniformly random $x$ — no speedup. The magic is in the oracle + interference step that sculpts the amplitude distribution before measurement.

06

Qiskit & IBM Quantum Platform

Qiskit is IBM's open-source quantum software development kit (SDK), the most widely used quantum programming framework in the world. It allows you to build, simulate, and run quantum circuits on real IBM quantum processors via the cloud.

Key Components

QISKIT-TERRA
Core: QuantumCircuit, gates, transpilation, optimization
QISKIT-AER
High-performance simulators with noise models
QISKIT RUNTIME
SamplerV2, EstimatorV2 — primitives for running circuits on hardware
IBM QUANTUM
Cloud platform with 100+ real quantum processors, from 5 to 127+ qubits
💡 Simulator Types in Qiskit Aer — Which One to Use?

Qiskit Aer provides several simulation backends, each suited to a different task. Choosing the right simulator is essential for correctly visualising and verifying your circuits:

Simulator What it does Max qubits (typical) Use when you need
Statevector Stores the full $2^n$-dimensional state vector. Gives exact amplitudes, phases, and density matrices. No measurement collapse. ~30–35 Bloch sphere plots, state city visualisation, debugging exact amplitudes
QASM (shot-based) Samples measurement outcomes stochastically, like real hardware. Returns bitstring counts (histograms). ~30–35 Histogram plots, testing algorithms with finite shots, mimicking real hardware (without noise)
Clifford Uses the stabilizer formalism — exponentially efficient for circuits containing only Clifford gates (H, S, CNOT, X, Y, Z and Pauli measurements). ~several thousand Large-scale QEC simulations, entanglement verification, randomised benchmarking (Clifford-only circuits)
Matrix Product State (MPS) Tensor-network simulator efficient for circuits with limited entanglement (low bond dimension). Can handle more qubits than statevector for weakly-entangled states. ~50–100 1D physics simulations, shallow circuits, states with area-law entanglement

Rule of thumb: Use statevector when you need to inspect the quantum state itself (Bloch sphere, density matrix, Q-sphere). Use qasm_simulator when you want histogram outputs like real hardware. IBM Quantum Composer and Lab use OpenQASM 3.0 for circuit descriptions (the human-readable assembly language for quantum circuits).

💡 SamplerV2 vs EstimatorV2 — Which Primitive to Use?

Qiskit Runtime provides two core execution primitives, and choosing the right one matters for both performance and correctness:

SamplerV2
Returns measurement outcome counts (bitstrings and their frequencies). Use when you want to see the probability distribution over computational basis states — e.g. for teleportation verification, Grover search, QAOA sampling. Analogous to actually measuring the quantum state.
EstimatorV2
Returns expectation values $\langle\psi|O|\psi\rangle$ for given observables $O$ (Pauli strings). Use when you need energy or other expectation values — e.g. VQE, QAOA cost evaluation. More efficient than sampling when you only need a scalar quantity, not the full distribution.

Rule of thumb: use SamplerV2 for combinatorial/search algorithms and EstimatorV2 for variational algorithms.

💡 Dynamic Circuits and Classical Feedback (if_test)

Classical quantum circuits execute gates then measure at the end. Dynamic circuits allow future quantum gates to depend on mid-circuit measurement outcomes — a quantum if statement. This is implemented in Qiskit via if_test:

with qc.if_test((classical_register, 1)):
    qc.x(target_qubit)   # applies X only if bit = 1

Dynamic circuits are essential for teleportation (Bob's correction depends on Alice's measurement), quantum error correction (corrections depend on syndrome measurements), and quantum-classical hybrid protocols. They require hardware with fast classical control electronics — IBM's Eagle and Heron processors both support them. The latency of classical feedback (typically ~1 μs) must be shorter than the qubit's $T_2$ time, which is why hardware improvements in classical control are as important as improving qubit coherence.

💡 The IBM Quantum Patterns Workflow

IBM recommends four structured steps for all quantum programs:

  1. Map: Describe your problem as a quantum circuit and define the observables or outcomes of interest. This is the algorithm design phase — choose gates, circuit structure, and measurement strategy.
  2. Optimize (Transpile): Compile the ideal circuit to the backend's native gate set and qubit connectivity via generate_preset_pass_manager. Higher optimization_level produces shorter circuits (less noise) at the cost of longer compilation time.
  3. Execute: Submit the ISA (Instruction Set Architecture) circuit to the backend via SamplerV2 or EstimatorV2. The circuit runs on hardware, and results are returned asynchronously.
  4. Post-process: Extract counts with .get_counts(), compute expectation values, apply error mitigation, and analyse or plot the results.

Code Examples

Creating a Bell State

from qiskit import QuantumCircuit
from qiskit_aer import AerSimulator

# Create 2-qubit circuit with 2 classical bits
qc = QuantumCircuit(2, 2)

# Step 1: Hadamard on qubit 0 → superposition
qc.h(0)

# Step 2: CNOT (control=0, target=1) → entanglement
qc.cx(0, 1)

# Measure both qubits
qc.measure([0, 1], [0, 1])

# Simulate with Aer
simulator = AerSimulator()
job = simulator.run(qc, shots=1000)
counts = job.result().get_counts()
# Expected: {'00': ~500, '11': ~500} — never '01' or '10'
print(counts)

Running on Real Hardware (IBM Quantum)

from qiskit_ibm_runtime import QiskitRuntimeService, SamplerV2
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager

# Authenticate with IBM Quantum
service = QiskitRuntimeService(channel="ibm_quantum", token="YOUR_TOKEN")

# Choose a backend (real quantum computer)
backend = service.least_busy(operational=True, simulator=False)

# Transpile circuit to backend's native gates + topology
pm = generate_preset_pass_manager(optimization_level=1, backend=backend)
isa_circuit = pm.run(qc)  # ISA = Instruction Set Architecture

# Run using SamplerV2 primitive
sampler = SamplerV2(mode=backend)
job = sampler.run([isa_circuit], shots=1024)
result = job.result()
print(result[0].data.meas.get_counts())

Teleportation in Qiskit

from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister

# Registers: q0=message qubit, q1=Alice's EPR half, q2=Bob's EPR half
q = QuantumRegister(3, 'q')
c = ClassicalRegister(2, 'c')
qc = QuantumCircuit(q, c)

# Prepare message qubit in state |ψ⟩ (e.g. |+⟩)
qc.h(0)

# Create EPR pair between q1 and q2
qc.h(1)
qc.cx(1, 2)
qc.barrier()

# Alice's operations: CNOT then H
qc.cx(0, 1)
qc.h(0)
qc.barrier()

# Alice measures, sends classical bits to Bob
qc.measure([0, 1], [0, 1])

# Bob's corrections (classically controlled)
qc.x(2).c_if(c[1], 1)  # Apply X if c[1] = 1
qc.z(2).c_if(c[0], 1)  # Apply Z if c[0] = 1

# Bob now holds |ψ⟩ = |+⟩ on qubit 2

Noise Models and the Aer Simulator

Real quantum hardware is noisy — gates have errors, qubits decohere, and measurements are imperfect. The Aer simulator can model this with noise models derived from real hardware calibration data:

from qiskit_aer.noise import NoiseModel
from qiskit_ibm_runtime.fake_provider import FakeNairobi

# Get noise model from a fake (calibration-based) backend
fake_backend = FakeNairobi()
noise_model = NoiseModel.from_backend(fake_backend)

# Simulate with noise
noisy_sim = AerSimulator(noise_model=noise_model)
noisy_job = noisy_sim.run(qc, shots=1000)
# Results will show leakage into '01' and '10' due to gate errors

Noise manifests as non-zero probabilities for outcomes that should be impossible (like measuring $\ket{01}$ in a Bell state). This motivates quantum error correction (Week 4) and error mitigation techniques.