Exercises: Dynamic Circuits
Teleportation is the centerpiece. Build it, then verify it properly — that second part is where most treatments stop short and where the actual skill is.
Difficulty: ⭐ warm-up · ⭐⭐ standard · ⭐⭐⭐ deeper.
Solutions: worked answers to the daggered (†) and odd-numbered problems are in
appendices/answers-to-selected.md; runnable code in
code/exercise-solutions.py.
Part A — Warm-ups ⭐
9.1 † What does a dynamic circuit add that a static one cannot express? Does it change what is computable?
9.2 Write the modern syntax for "apply X to qubit 1 if classical bit 0 came out 1." What was the removed predecessor called?
9.3 † Teleportation uses one shared entangled pair and how many classical bits? State the exact exchange rate in one line.
9.4 Why does teleportation not violate the no-cloning theorem?
9.5 † Superdense coding sends two classical bits using one transmitted qubit. What is the total qubit traffic, and what does the protocol actually buy?
Part B — Building and Verifying ⭐⭐
9.6 † Build the mid-circuit-measurement circuit from §9.1, draw it, and run it. Explain the counts. Where have you seen this circuit before?
9.7 † Implement teleportation. Verify it by comparing the teleported qubit's expectation value to the original's in all three Bloch bases ($Z$, $X$, $Y$). Report the worst disagreement and the sampling error at your shot count. Are they consistent? Then explain, in two sentences, why verifying in $Z$ alone would have been nearly worthless.
9.8 Tally which of the four corrections Bob had to apply, across many shots. What fraction does each occur with? Explain how this fact — and only this fact — settles the "faster than light" question.
9.9 † Implement superdense coding for all four messages. Report what Alice sent and what Bob measured. Two of the four appear reversed — explain exactly why, naming the two interacting conventions. What testing rule does this illustrate?
Part C — Reuse and Cost ⭐⭐⭐
9.10 † Use reset to get $n$ independent coin flips from a single qubit, for $n = 2, 3, 4$.
Confirm you get $2^n$ outcomes at roughly uniform probability. What resource did you trade for what?
9.11 † Transpile three circuits for FakeSherbrooke and compare ISA depth and two-qubit gate
count: a static 3-qubit GHZ, teleportation, and teleportation with barriers between its four stages.
Report all three. What accounts for each increase?
9.12 Run teleportation on the noisy backend and compare the teleported state's $Z$ distribution to the ideal. Report the degradation. Is it consistent with the noise budget for a circuit of this depth and two-qubit gate count? (Chapter 2's Case Study 2 method.)
9.13 † The chapter claims the largest cost of a dynamic circuit is invisible to depth().
Explain what that cost is, why it does not appear in the gate count, and what question you should ask
instead when judging whether a dynamic circuit is worth it.
Part D — Deeper ⭐⭐⭐
9.14 Build teleportation without the conditional corrections — that is, stop after Alice's Bell measurement. Measure Bob's qubit in all three bases and report the results. What state is it in? Why does this confirm that the classical bits are doing real work?
9.15 † Implement entanglement swapping: two separate Bell pairs (qubits 0–1 and 2–3), then a Bell measurement on qubits 1 and 2, leaving 0 and 3 entangled without those two qubits ever having interacted. Verify the final entanglement with the witness from Chapter 4's Case Study 2.
9.16 Write a repeat-until-success loop with a bounded number of attempts, for an operation that succeeds with probability $p$. Compute the failure probability as a function of the attempt limit, and choose a limit for a target failure rate of $10^{-3}$ at $p = 0.5$.
9.17 † Superdense coding assumes Alice and Bob already share a Bell pair. Write the full protocol including distribution, count every qubit transmission, and compare against simply sending two classical bits. Under what operational circumstances is superdense coding genuinely advantageous?
9.18 Construct a circuit where qubit reuse via reset genuinely helps: one whose simultaneous
qubit requirement is much lower than its total. Measure the qubit count and depth with and without
reuse, and state the trade in one sentence.
Part E — Project ⭐⭐
9.19 † Implement the Chapter 9 🧱 Project Checkpoint: add measure_with_reset() and
why_not_mid_circuit() to vqelab/measure.py.
9.20 Run why_not_mid_circuit and report the depth ratio. Then write the two-sentence conclusion
you would put in the project's notes, so that the next person to propose mid-circuit measurement for
VQE gets a measurement rather than an opinion.
9.21 ⭐⭐⭐ The checkpoint's conclusion — "VQE ansätze keep every qubit entangled, so there is nothing to reuse" — is an argument, not a proof. Construct an ansatz for which it is false: one where some qubits genuinely finish early. Does such an ansatz have any use? What does its existence tell you about the generality of the checkpoint's conclusion?