Exercises: The Quantum Programming Landscape

This is a survey chapter, so most of these exercises are about reading and judgment rather than code — with one important exception in Part B, which you can run before you have installed anything quantum at all.

Difficulty: ⭐ warm-up · ⭐⭐ standard · ⭐⭐⭐ deeper. Solutions: worked answers to the daggered (†) and odd-numbered problems are in appendices/answers-to-selected.md. Runnable solutions are in code/exercise-solutions.py. Try each problem before you look.


Part A — Warm-ups ⭐

1.1 † In one sentence each, state what a quantum computer returns when you run a program on it, and why that means assert result == expected is not merely a bad test but a category error.

1.2 Name the five major quantum programming frameworks covered in this book and, for each, the company or organization behind it.

1.3 † OpenQASM is described in this chapter as "not a framework." What is it instead, and what is the classical thing it is most analogous to?

1.4 The chapter says an $n$-qubit state requires $2^n$ complex amplitudes to describe. How many amplitudes does a 12-qubit state require? At 16 bytes per complex amplitude, how many megabytes is that?

1.5 † Explain, in two sentences, why the no-cloning theorem means you cannot checkpoint a quantum computation.

1.6 What does NISQ stand for, and which two properties of current hardware does the term capture?

1.7 † The chapter lists three shapes of question a quantum program can answer. Name all three, and give the name of one algorithm from the book's table of contents that asks each.

1.8 Why does the chapter recommend learning Qiskit first, given that it also says Qiskit's API has churned harder than any other framework's?


Part B — Run Something ⭐⭐

These need only Python and NumPy. If you have not installed anything yet, that is fine — install Qiskit in Chapter 2 and come back if you prefer.

1.9 † Write the exponential-wall script from §1.4 yourself, without copying it. It should print, for $n = 1$ to $n = 55$, the number of complex amplitudes in an $n$-qubit statevector and the memory required at 16 bytes each. Then answer:

a. What is the largest $n$ that fits in 16 GiB? b. What is the largest $n$ that fits in 1 PiB (a very large supercomputer)? c. By how many orders of magnitude does the memory grow when you go from 50 to 60 qubits?

1.10 Modify your script to also print, for each $n$, how long it would take to write out the statevector once at a sustained 10 GB/s. At what $n$ does a single write exceed one hour? Exceed the age of the universe (about $4.4 \times 10^{17}$ seconds)?

1.11 † The chapter states that a circuit with 1,000 two-qubit gates at 0.3% error per gate "completes with no gate error only about 5% of the time." Check it, then generalize. Assuming errors are independent, compute the probability that no gate errs, for gate counts of 10, 100, 1,000, and 10,000, at per-gate error rates of 0.1%, 0.3%, and 1%. Present it as a table. Which cell in your table best describes today's best hardware running a useful algorithm?

1.12 Using your table from 1.11: if you need a 50% chance of an error-free run, roughly how many two-qubit gates can you afford at a 0.3% error rate? Now solve it symbolically — for a target success probability $p$ and error rate $\epsilon$, give a formula for the maximum gate count.

1.13 † Write a function shots_needed(epsilon) that returns the approximate number of shots required to estimate a probability to within $\pm\epsilon$, using the $1/\epsilon^2$ scaling from §1.4. Print the result for $\epsilon = 0.1, 0.01, 0.001, 0.0001$. If one shot takes 100 microseconds of quantum processor time, how much QPU time does each precision level cost? Which one exceeds a typical monthly free-tier allowance?


Part C — Judgment and Analysis ⭐⭐⭐

1.14 † Below are five statements of the kind you will encounter in press coverage. For each, apply the five-question test from §1.5's 🔬 Honest Assessment callout and state (a) which question is most relevant, and (b) what specific follow-up you would ask.

a. "Our 1,200-qubit processor is the world's most powerful quantum computer." b. "We demonstrated a quantum speedup on a real-world logistics problem." c. "Our quantum machine learning model achieved 94% accuracy on the dataset." d. "We factored a 48-bit number using our quantum annealer." e. "Quantum computers will break all encryption within five years."

1.15 The chapter argues that the five frameworks exist because the hardware has not converged. Construct the strongest counterargument you can — a case that framework proliferation is caused mainly by something other than hardware diversity. Then say which explanation you find more persuasive and why.

1.16 † The chapter's classical analogy maps the quantum transpiler onto a classical compiler backend, then immediately identifies a defect in the analogy. Restate the defect precisely, and then find one more place where the analogy breaks down that the chapter does not mention.

1.17 Read the §1.2 code samples for the same Bell state in Qiskit, Cirq, PennyLane, Q#, Braket, and OpenQASM. Without knowing any of these frameworks yet, list three concrete syntactic or structural differences you can observe, and for each, guess what design decision it reflects. (Save your answer. Revisit it after Chapter 18 — the comparison of your naive reading against your informed one is instructive.)

1.18 † The chapter says entanglement is "where the power comes from" and also "where the bugs come from." Explain how both can be true, referring specifically to the role of uncomputation.

1.19 Suppose a vendor tells your organization that their quantum service will optimize your delivery routing. Using only material from this chapter, write a five-question response email. Be professional; the goal is to establish what is actually being claimed, not to embarrass anyone.

1.20 † The chapter claims quantum programming skills are "durable" because they concern the computational model rather than any device. Identify two skills taught in this book that you think would become obsolete if fault-tolerant quantum computers arrived tomorrow, and two that would become more valuable. Justify each.


Part D — Project ⭐⭐

1.21 † Complete the Chapter 1 🧱 Project Checkpoint. Create a project directory with a README.md stating the goal, the success criterion (within 1.6 mHa of −1.137 Ha), and the falsification condition, in your own words.

1.22 Add a section to your project README called Open Questions and write down at least three things you do not yet understand about the goal. Examples of the right shape: "What is a Hartree?" "What does 'variational' mean here?" "Why H₂ and not something bigger?"

Revisit this list at the end of Chapter 24 and again at the end of Chapter 36. Cross off what you have answered and add what you have discovered. A project journal that records confusion is more useful later than one that records only conclusions — you will need it when you write up your results, and you will need it in the interview Chapter 40 describes.

1.23 ⭐⭐⭐ Write one paragraph in your README predicting how close to the target you will get on real hardware — before you know anything about noise. Commit it. This is a calibration exercise: at the end of the book, compare your prediction to the outcome. Most readers, at this point, predict far too optimistically, and noticing that about yourself is worth more than getting it right.