Exercises: Amazon Braket

All of these run on LocalSimulatorno AWS account required. Exercises marked ☁️ would need credentials and incur charges; they are written so you can reason about them without running them. Solutions to starred exercises are in Answers to Selected Exercises.


Warm-up

17.1 ★ Build a Bell state with Braket's fluent API, print the circuit, and run it for 1000 shots. Then rewrite it as a single chained expression and confirm the results match.

17.2 Compare Braket's Circuit().h(0).cnot(0,1) with the Qiskit and Cirq versions from Chapters 2 and 14. Which returns a new object, which mutates, and which returns the same object for chaining?

17.3 ★ Run Chapter 14's endianness test in Braket: apply X to qubit 0 of a two-qubit register and report the state-vector index. Add Braket to the three-framework table.

17.4 Request all four result types (probability, state_vector, expectation, amplitude) on the same Bell circuit at shots=0. Which of these has no direct equivalent in Qiskit's primitives?

17.5 ★ Run the same circuit on braket_sv and braket_dm. What warning does Braket emit, and what Chapter 11 measurement justifies it?


Connectivity

17.6 ★ Write star_ghz(n) and chain_ghz(n). Confirm they produce the same final state for $n = 4$ using state_vector().

17.7 ★ Compute the interaction graph and maximum interaction degree of both circuits at $n = 8$. Which can be embedded in a degree-3 lattice without routing, and why?

17.8 ★★ Reproduce §17.4's table: transpile star_ghz(n) to FakeSherbrooke for $n = 4, 6, 8, 10, 12$ and report two-qubit gate count, depth, and overhead.

17.9 ★★ Do the same for chain_ghz(n). Confirm the overhead is 1.00× at every size and explain why in terms of interaction degree.

17.10 ★★ Transpile star_ghz(12) to a line, a ring, a 2-D grid, and all-to-all. Rank the topologies by two-qubit gate count. How much does the extra connectivity of a grid over a line actually buy?

17.11 ★★ Implement breakeven_error_rate(overhead, error_rate) and tabulate the break-even for overheads of 1, 2, 3, 5, and 10 at $\varepsilon_{\text{sc}} = 0.0075$. At what overhead does the break-even exceed 5%?

17.12 ★★★ §17.4 used a star circuit because it is the worst case. Construct a circuit whose interaction graph is a random graph with average degree 4, and measure its overhead on FakeSherbrooke at $n = 8, 12, 16$. Is the overhead closer to the star or the chain?

17.13 ★★★ Chapter 16's StronglyEntanglingLayers is described as "hardware-efficient." Extract its interaction graph for 8 wires and compute its overhead on FakeSherbrooke. Is the name deserved?


Native gates

17.14 ★ Apply MS(0, 0, θ) to $|00\rangle$ for $\theta = \pi/4, \pi/2, \pi$ and report the state vector each time. At which angle is the state maximally entangled?

17.15 ★★ Build a Bell state using only MS, GPi, and GPi2. Verify the measurement probabilities match a standard H + CNOT construction. Do the state vectors match exactly, and if not, why does that not matter?

17.16 ★★ List all 41 Braket gates and classify each as (a) universal/abstract, (b) superconducting- native, (c) trapped-ion-native, or (d) other. Which gates appear in more than one category?

17.17 ★★ Build a circuit inside a verbatim box. Confirm the instruction count includes the box markers. Then try to put a non-native gate inside one and record what happens.

17.18 ★★★ §17.5 warns that inside a verbatim box you are the compiler. Construct a case where a hand-written verbatim decomposition is worse than what the transpiler produces, and quantify the difference.


Noise and modalities

17.19 ★ Reproduce §17.3's depolarizing sweep for $p = 0, 0.02, 0.05, 0.10$ and compare each error fraction to $4p/3$.

17.20 ★★ Reproduce Chapter 11's two-axis signature table in Braket for depolarizing, bit flip, phase flip, amplitude damping, and phase damping. Confirm phase damping is invisible, then design the measurement that does detect it.

17.21 ★★ Chapter 11 measured phase damping invisible in Aer, Chapter 14 in Cirq, and §17.3 here. Write one sentence explaining why this is not a coincidence about software.

17.22 ★★ Build the modality comparison table from §17.6 as a data structure, and write best_modality(circuit_shape, workload_type) returning a recommendation. Test it on: a nearest- neighbour chain run once; a star circuit run once; a star circuit inside a 500-iteration variational loop.

17.23 ★★★ Chapter 16 §16.4 established a gradient costs $2n+1$ circuit executions per iteration. Assuming superconducting gates at 100 ns and ion gates at 10 μs, compute the wall-clock time for a 50-parameter, 200-iteration VQE with a 30-gate circuit on each modality. At what circuit depth does the ion's connectivity advantage stop compensating for its speed?


Project

17.24 ★★ (Project Checkpoint) Build vqelab/topology.py with interaction_graph(), interaction_degree(), connectivity_overhead(), breakeven_error_rate(), and recommend_modality(). Write tests asserting:

  1. The interaction graph of a chain is exactly the nearest-neighbour pairs.
  2. A chain has max interaction degree 2; a star on $n$ qubits has degree $n-1$.
  3. A nearest-neighbour circuit has overhead 1.00× on a line, at several sizes.
  4. A star circuit's overhead is above 1.0 and grows with qubit count.
  5. A star costs more than a chain on the same topology.
  6. breakeven_error_rate(1.0, e) == e.
  7. Break-even loosens monotonically with overhead, exceeding 2% at 3.18×.
  8. An overhead below 1 raises ValueError.
  9. A chain gets a "superconducting" recommendation; a star gets "trapped ion."
  10. Every recommendation cites a number, not just an opinion.

Test 10 is the one that encodes Case Study 2's lesson.

17.25 ★★★ Extend topology.py with suggest_reshaping(circuit), which looks for an equivalent circuit with lower maximum interaction degree. Start with the star-to-chain GHZ transformation and verify the output state is unchanged. What class of circuits admits such a rewrite?


Going further

17.26 ★★★ ☁️ Braket supports analog Hamiltonian simulation on neutral atoms via AnalogHamiltonianSimulation. Read the documentation and write (without running) a program that prepares an Ising ground state on a 1-D chain of atoms. What is expressible in AHS that is not expressible as a gate circuit, and vice versa?

17.27 ★★★ Case Study 1 argues that circuit structure is a hardware decision in disguise. Take one algorithm from Part IV's preview — Grover's diffuser, or the QFT — extract its interaction graph, and determine which modality suits it. Defend your answer with an overhead measurement.

17.28 ★★★ Chapter 12 built device_health(), best_layout(), and preflight() for superconducting hardware. Which of the three would still be meaningful on a trapped-ion device, and what would each need to become? Write the ion-trap version of whichever survives.