Exercises: Hybrid Architectures

These need pennylane and scikit-learn. Solutions to starred exercises are in Answers to Selected Exercises.

A standing rule for this chapter: every quantum-data result must state the qubit count and whether the state is classically writable. Case Study 1 is what happens otherwise.


Quantum data

35.1 ★ Build the transverse-field Ising Hamiltonian and find its ground state by exact diagonalization for $h = 0.2 \ldots 2.0$. Confirm the phase transition at $h = 1$ by plotting the magnetization.

35.2 ★ Compute the encoding cost Chapter 32 would charge for these states, per sample and over a full training run. Confirm the quantum-data cost is zero.

35.3 ★ Train the state classifier and report train and test accuracy on a split that holds out states near criticality.

35.4 ★★ Why is holding out the near-critical states the right split? What would a random split measure instead?

35.5 ★★ The model has 36 parameters and 28 training samples. Reduce the parameter count until train and test accuracy converge. What does that tell you?

35.6 ★★★ Repeat at 4, 6, 8, and 10 qubits. Does the quantum classifier's advantage over the classical baseline change with system size? Should it, at these sizes?


The baseline

35.7 ★ Give sklearn the same states as (a) full amplitudes and (b) measurement probabilities. Report test accuracy for LogisticRegression, SVC, and kNN on each.

35.8 ★ Which representation wins, and by how much? Why is that direction surprising?

35.9 ★★ How many real numbers is a 6-qubit state? A 20-qubit state? A 50-qubit state? At which point does the classical baseline become impossible to run?

35.10 ★★ Write quantum_data_verdict(n_qubits, ...) that refuses to call a result an advantage claim below the classical-simulation boundary. Justify the boundary you choose against Chapter 26 §26.2's memory measurement.

35.11 ★★★ Construct a quantum-data task where the classical baseline genuinely cannot be run at a size you can still simulate. Is that possible, or is it a contradiction?


Classical shadows

35.12 ★ Implement classical shadows with qml.classical_shadow and estimate the 17 observables. Compare against exact values.

35.13 ★ Compare shadows against direct estimation at the same shots per observable. Which looks better?

35.14 ★★ Now compare at the same total budget. Which is better, and by how much?

35.15 ★★ Explain the reversal using $1/\sqrt{N}$. Compute the splitting penalty for 17 observables and compare it against the measured shadow penalty.

35.16 ★★ At how many observables do the two methods break even? Find it by measurement.

35.17 ★★★ The shadow snapshot count grows with the locality of the observables. Measure this: compare 1-local, 2-local, and 4-local observables at fixed budget.

35.18 ★★★ Estimate a non-local observable (a product over all qubits) with shadows. What happens, and why does that limit the technique?


The loop in production

35.19 ★ Using Chapter 31's 7.10 μs circuit time, compute the wall-clock cost of a 24-parameter, 60-step optimization that round-trips every evaluation at 1 second of latency.

35.20 ★ What fraction of that wall-clock is the quantum computer actually computing?

35.21 ★★ How much does co-locating the classical update save? Model it by reducing the latency to 1 ms.

35.22 ★★ Chapters 33 and 34 both measured ~500× from batching. Where in a hybrid loop can batching be applied, and where can it not?

35.23 ★★★ Design the full production cost model for a deployed hybrid classifier: training shots, inference shots, queue latency, and calibration drift (Chapter 30). Which term dominates, and at what usage?


Project

35.24 ★★ (Project Checkpoint) Build vqelab/hybrid.py with encoding_cost_saved, classically_writable, quantum_data_verdict, shadow_advantage, and hybrid_round_trips. Write tests asserting:

  1. Quantum data saves every encoding gate — 57 per sample at 6 qubits, against zero.
  2. The saving grows exponentially with qubit count.
  3. Nonsense arguments are rejected.
  4. The saving reports whether it is checkable: 128 real numbers at 6 qubits, unwritable at 50.
  5. quantum_data_verdict returns CLASSICALLY_CHECKABLE below the boundary, naming the state's size and telling you to run the baseline.
  6. The verdict flips to ADVANTAGE_POSSIBLE above it.
  7. The boundary matches Chapter 26 §26.2's 30–35 qubit measurement.
  8. The classical baseline won at checkable scale (0.7857 vs 0.6429) — and the winner used probabilities, not full amplitudes.
  9. Shadows lose per observable (~2.5×) and win at equal budget (1.5–1.8×).
  10. The $\sqrt{n}$ splitting penalty explains the win.
  11. The advantage grows with the observable count.
  12. Over 99.9% of a naive hybrid loop's wall-clock is latency, not computation.
  13. Co-locating the classical update fixes it.
  14. No quantum model in Part VI beat a tuned classical baseline.

Tests 5, 8, 9 and 14 are the ones this chapter exists to encode.

35.25 ★★★ Extend the module with part_vi_scorecard() returning every quantum-versus-classical comparison in Chapters 32–35 with its error bar, and a single verdict.


Going further

35.26 ★★ Read Huang, Kueng, and Preskill on classical shadows. What is the formal sample-complexity bound, and how does it depend on the observables?

35.27 ★★★ Read Huang et al. on quantum advantage in learning from experiments. It argues for an exponential separation when the learner can access quantum data coherently. What exactly is being compared, and does the input problem apply?

35.28 ★★★ Part VI concluded that no quantum model beat a tuned classical baseline. Design the experiment that would change that conclusion: what data, what scale, what baseline, and what would count as a result?