Day 2 — Parameterized & Dynamic Circuits, Transpilation
Math Prep
Solve this BEFORE lesson.md. Day 2 is about circuits whose gates carry angle parameters and about rewriting circuits into hardware basis gates. The math you need: rotation gates as matrix exponentials, phase bookkeeping, and universal decomposition.
Requires: Day 1 math prep. Video back-up: Watrous Lesson 03 Quantum Circuits; notes in resource-artifactory/notes/video-notes/.
1. Rotation gates are matrix exponentials
For any Pauli (each satisfies ):
Plug in each Pauli and you get the Day-1 matrices. Two consequences you must internalize:
- The half angle. is the rotation angle on the Bloch sphere, but the matrix contains . So a Bloch-sphere rotation by around X is , i.e. X up to global phase.
- Period , not : (a global-phase flip), and only exactly. Parameterized-circuit sweep questions use this.
Composition along the same axis is addition: . Rotations about different axes do NOT commute: in general — that's why gate order matters and why assign_parameters order never matters (it's just substituting numbers) but circuit order does.
2. Phase bookkeeping: p vs rz, one more time
Alone: identical physics (global phase). Controlled: different gates! Controlling a unitary promotes its global phase to a relative phase on the control:
So cp(λ) ≠ controlled-rz(λ) — they differ by a p(λ/2) on the control. This is why Qiskit tracks qc.global_phase at all: the transpiler must keep it to make controlled/composed circuits exact.
3. Euler decomposition — why 3 parameters are enough
Any single-qubit unitary can be written (up to global phase) as three rotations:
which is exactly Qiskit's from Day 1. Equivalently with the hardware-native set:
This identity is the whole reason IBM hardware only needs {rz, sx, x} plus one entangler (cx/cz/ecr): any 1q gate = at most 2 physical pulses + virtual 's. And is "free" (virtual): it's implemented as a frame rotation in software, zero error, zero duration. That's why transpiled circuits are stuffed with rz and why optimization levels merge runs of 1q gates into at most rz-sx-rz-sx-rz.
4. Conjugation identities — the transpiler's rewrite rules
"Conjugating" by means . Memorize this table ( and conjugations move rotation axes):
| Identity | Meaning |
|---|---|
| , , | H swaps X↔Z axes |
| rewrite rx using rz | |
| S rotates X-axis to Y-axis | |
| CNOT direction flip | |
| CX ↔ CZ with 2 Hadamards on target | |
| 3 CNOTs (routing cost!) |
The CNOT-direction flip and the SWAP identity explain transpiler behavior on real topologies: if the coupling map only has , a cx(1,0) costs 4 extra H's; a gate between non-neighbors costs SWAPs = 3 CNOTs each.
5. Commutation — when the order doesn't matter
. Facts used in dynamic-circuit reasoning and optimization:
- Diagonal gates (
z, s, t, p, rz, cz, cp, rzz) all commute with each other. - -family on the control commutes through CX; -family on the target commutes through CX.
- Measurement in the Z basis commutes with Z-diagonal gates before it — that's why a
zright beforemeasureis dead code the optimizer deletes.
6. The deferred measurement principle (dynamic circuits)
Any circuit with a mid-circuit measurement + classically-controlled gate (if_test) is equivalent to one where the measurement is pushed to the end and the classical control becomes a quantum control:
measure q0 → if result: X on q1 ≡ CX(q0→q1) then measure q0.
That's the math behind Day 2's dynamic circuits and behind teleportation's "corrections."
PROBLEMS
P1. Expand into a matrix and confirm it matches Day 1's .
P2. Show . What measurement statistics distinguish the rx(2π) circuit from the identity circuit? What does this imply about Operator.equiv vs ==?
P3. Compute and name the resulting gate (up to global phase).
P4. Using , find the matrix by which controlled- and controlled- differ, and express it as a gate on the control qubit.
P5. Verify using and .
P6. A device's coupling map has only the edge (control 0, target 1). Count the total cx + h gates needed to implement cx(1,0).
P7. How many CNOTs does the transpiler insert to run a cx between qubits that are 2 hops apart (path 0–1–2, gate wanted between 0 and 2), if it SWAPs 0's state to 1 first and doesn't swap back?
P8. sweep: for ry(θ) acting on , give as a function of θ, and evaluate at .
ANSWERS
A1. , so . ✓ (All real — that's why ry is the go-to for real-amplitude ansätze.)
A2. . None — no measurement can distinguish from (global phase). Hence Operator(rx(2π)).equiv(Operator(id)) is True but == is False.
A3. — that is (equivalently ) up to the global phase .
A4. : the control- block gets an extra factor . So — the difference is a phase gate on the control qubit.
A5. . ∎
A6. cx(1,0) = H on both qubits, cx(0,1), H on both: 1 cx + 4 h.
A7. One SWAP (0↔1) = 3 CNOTs, then the desired cx on the now-adjacent pair = 1: 4 CNOTs total (and the logical→physical layout has changed — that's why the transpiled circuit carries a final layout, a concept in the lesson).
A8. . Values: : 0; : ; : 1; : 0. (Sweep questions: oscillates with period in θ even though the matrix period is .)
Self-check: you can state , explain why rz is "free" on IBM hardware, and produce the CX↔CZ and SWAP identities from memory.