Exercises: Running on Real Hardware
All of these run on fake backends — no credentials, no queue. Solutions to starred exercises are in Answers to Selected Exercises.
Warm-up
12.1 ★ Print the median two-qubit gate error, median readout error, median $T_1$, and median $T_2$
for FakeSherbrooke, FakeTorino, FakeKyiv, and FakeOsaka. Which device would you choose for a
circuit with 200 two-qubit gates? Which for a circuit with 4 two-qubit gates and 100 measurements?
Justify each in one sentence.
12.2 FakeTorino reports cz where the others report ecr. Transpile the same 5-qubit GHZ
circuit to FakeSherbrooke and to FakeTorino at optimization level 3 and compare the two-qubit gate
counts. Does the different native gate change the count, the depth, both, or neither?
12.3 ★ For FakeSherbrooke, compute the ratio of maximum to minimum readout error, two-qubit gate
error, $T_1$, and $T_2$ across all qubits. Which metric is the most variable? Compare that ratio to
the spread across the four devices in 12.1.
12.4 List every qubit on FakeSherbrooke with $T_2 < 20$ μs. How many are there, and do any of
them also appear in the bad-readout list from §12.2?
Reading calibration data
12.5 ★ Write worst_qubits(backend, k) returning the $k$ qubits with the highest readout error,
and worst_pairs(backend, k) returning the $k$ two-qubit links with the highest gate error. Run both
on all four fake backends. Does every device have dead links, or is FakeSherbrooke unusual?
12.6 §12.2 found nine ECR pairs with error $\geq 0.99$. For each, check whether the reverse direction is also present in the target and what its error is. Are dead links always symmetric?
12.7 ★★ For every qubit on FakeSherbrooke, compute $P(1|0)$ and $P(0|1)$ from
prob_meas1_prep0 and prob_meas0_prep1, and verify that readout_error equals their average to
within $10^{-6}$. Then compute the asymmetry ratio $\max/\min$ of the two directions for each
qubit. How many qubits are more than 10× asymmetric? Plot a histogram of the ratio.
12.8 ★★ Chapter 2's Case Study 2 found that the readout asymmetry on a real device ran opposite
to the textbook expectation (that $1 \to 0$ errors dominate, because $|1\rangle$ decays toward
$|0\rangle$). Using the full $P(1|0)$ and $P(0|1)$ data from 12.7, count how many of
FakeSherbrooke's 127 qubits have $P(1|0) > P(0|1)$ and how many the reverse. Which direction
dominates on this device? Does the textbook expectation hold on average?
12.9 Qubit 92 has $P(1|0) = 0.0127$ and $P(0|1) = 0.6685$. Design a two-qubit circuit whose
correct answer is always 00 and one whose correct answer is always 11. Run both with qubit 92 in
the layout. Predict the two correct fractions before running, then check.
Choosing qubits
12.10 ★ Implement score_chain from §12.3 and use it to rank all connected 3-qubit paths on
FakeSherbrooke. Report the best, the median, and the worst, with their scores.
12.11 ★★ Run a 3-qubit GHZ circuit on the best, median, and worst triples from 12.10 and report
the correct fraction for each. Does the ranking hold? Now repeat with optimization_level=3 instead
of 1 — does the transpiler's own noise-aware layout selection close the gap?
12.12 ★★ The scoring function weights each link by $3\times$ its gate error. Try weights of 1, 3, and 10, and also try multiplying success probabilities $\prod(1-e_i)$ instead of summing errors. For each variant, check whether the top-ranked and bottom-ranked 3-qubit paths change. What does this tell you about how much the exact form of the score matters?
12.13 ★★ Extend score_chain to handle a ring rather than a chain (a path where the last qubit
must also connect back to the first). How many 4-qubit rings exist on FakeSherbrooke? What is the
best one?
12.14 ★★★ best_layout currently enumerates all simple paths, which grows quickly. Time it for
$n = 3, 5, 7, 9$. At what $n$ does it become impractical? Implement a greedy alternative (start from
the best single qubit, extend by the best available neighbor) and compare both the quality of the
result and the runtime at $n = 9$.
12.15 ★★ Write a preflight function that checks both readout directions, as in §12.3. Verify
that it rejects qubit 84 and that a simple threshold on the averaged readout_error > 0.6 does
not. Explain in two sentences why the averaged threshold fails.
Jobs and execution
12.16 Submit a circuit to a fake backend via SamplerV2, print job.job_id() and job.status()
before calling job.result(), and confirm the status changes. Write the job id, backend name, layout,
and date to a JSON-lines ledger.
12.17 ★ Write retrieve(job_id) that loads your ledger, finds the matching entry, and prints
everything you recorded alongside the counts. What is the minimum set of fields you need in order to
interpret a result four weeks later? Defend each one.
12.18 ★★ Time three approaches to running 20 small circuits on a fake backend: (a) 20 separate
sampler.run calls with one circuit each, (b) one sampler.run call with all 20 pubs, (c) 20 calls
inside a batch. Which is fastest locally? Explain why the ranking would differ on real hardware with a
queue.
The decision procedure
12.19 ★★ Implement §12.7 as a function diagnose(circuit, backend, layout) that returns one of
"BUG", "NOISE", "STRUCTURAL", or "UNKNOWN". Test it on: (a) a correct GHZ on a good layout,
(b) a correct GHZ on [83, 84, 85], (c) a GHZ with the second cx replaced by cz. Confirm you
reproduce Case Study 2's verdicts.
12.20 ★★ Build the error budget for a 5-qubit GHZ on the best 5-qubit chain: count the ECR gates in the transpiled circuit, multiply out $(1-e)$ for each gate and each measurement, and predict the correct fraction. Then run it. How close is the prediction? Repeat at $n = 3, 4, 5, 6, 7$ and plot predicted against measured.
12.21 ★★★ Case Study 2's Run B has an error budget predicting 0.0000 and a measured value of 0.2844 — the measurement is better than predicted, which §12.7 step 4 lists as a symptom of accidentally running a simulator. Explain what actually produced 0.2844. Then rewrite step 4 so that it does not mislead in this case, and confirm your rewrite still gives the right answer for Runs A and C.
12.22 ★★ Construct a circuit that fails on hardware for a reason the procedure classifies as
STRUCTURAL but which is really a bug — that is, defeat the procedure. Then propose an additional
check that catches your example. (Hint: consider apply_layout and observables, Chapter 7 §7.6.)
12.23 ★★ Take Case Study 2's Run C histogram. Without running anything, determine from the bit pattern alone which qubit was not entangled. Then verify by simulating the buggy circuit noiselessly.
Project
12.24 ★★ (Project Checkpoint) Extend vqelab/backends.py to v3 with device_health(),
best_layout(), preflight(), and readout_directions(), and extend the provenance record with the
job id, layout, layout score, and date. Then write tests asserting that:
device_healthfinds qubit 6 and qubit 84 onFakeSherbrooke.- The within-device gate error ratio exceeds 100.
- Qubit 84 has $P(1|0) = 1$ and $P(0|1) = 0$.
readout_errorequals the average of both directions for several qubits.best_layout(backend, n)always passes its own preflight, for $n = 2, 3, 5$.preflightrejects[83, 84, 85]with aSTUCKmessage.preflightrejects a disconnected layout.
Test 5 is the important one — it is the property that makes the function safe to call blindly.
12.25 ★★★ Add estimate_queue_position() and estimate_cost() to backends.py, using the
shots × circuits × iterations arithmetic from §12.8 and Chapter 7 §7.9. Use them to answer: how many
QPU-seconds would a 200-iteration VQE with 4 observable terms and 4096 shots consume? Compare to
running the same thing with 1024 shots and 50 iterations. Which produces a better energy estimate per
second of QPU time? (Chapter 14 revisits this properly.)
Going further
12.26 ★★★ §12.2 shows a static calibration snapshot. Real devices drift. Using FakeSherbrooke's
property timestamps (each entry carries a datetime), determine the spread of calibration dates in
this snapshot. Are all qubits calibrated at the same time? What does that imply about treating the
snapshot as a coherent description of the device at one instant?
12.27 ★★★ Reproduce Case Study 1's finding on a different device. Check all four fake backends for qubits whose $\max(P(1|0), P(0|1)) > 0.9$. Is a stuck qubit unusual, or does every snapshot have one?
12.28 ★★★ Case Study 1 found that AerSimulator.from_backend and SamplerV2(mode=backend)
disagree about qubit 84. Determine empirically how many of FakeSherbrooke's 127 qubits the two paths
disagree about by more than 5 percentage points in $P(1)$ from $|0\rangle$. Is this a corner case or a
systematic difference?