Quiz: PennyLane

Answers with explanations at the end.


1. What is a QNode, and what happens to the circuit object you would build in Qiskit?

2. Why does PennyLane use wires rather than qubits?

3. Chapter 8's parameter-ordering bug cannot happen in PennyLane. Give the reason, and name the two other frameworks in this book where it also cannot happen and why.

4. Write the parameter-shift rule for a Pauli-generated rotation.

5. Why is the parameter-shift rule exact rather than approximate?

6. Finite differences on the same circuit gave errors of $1.07\times10^{-3}$ at $h = 10^{-1}$, $1.98\times10^{-11}$ at $h = 10^{-5}$, and $8.04\times10^{-9}$ at $h = 10^{-9}$. Explain the shape of that curve.

7. Why does the parameter-shift rule's $\pi/2$ shift make it suitable for hardware in a way finite differences are not?

8. How many circuit executions does one gradient cost for $n$ parameters? Derive the formula.

9. A 100-parameter ansatz is optimized for 200 iterations at 4096 shots. Compute the total shot count.

10. A circuit has 64 parameters spread over 4 wires, and the observable is PauliZ(0). PennyLane reports 33 executions rather than 129. Why, and what diagnostic use does this have?

11. A four-parameter ansatz stalls 0.166 above the exact ground state. Give the two diagnostics you should run before concluding the ansatz is too small.

12. The same ansatz reached the exact answer under Adam. It also reached it under GradientDescent(0.25) with 200 steps, but not under GradientDescent(0.05) with 200 steps. What was the original failure, and why is the instinctive fix wrong?

13. Adding parameters to fix an optimizer problem makes three things worse. Name them.

14. State the measured decay of gradient variance with qubit count, and what it is in factor-per- qubit terms.

15. Resolving a gradient of magnitude $g$ requires roughly how many shots? Apply it at 50 qubits, where $|g| \approx 3\times10^{-8}$.

16. Why is a barren plateau a problem of information rather than of optimizer quality?

17. Does reducing the ansatz depth escape the barren plateau? Support your answer with the measured numbers.

18. A gradient measurement returns values of $10^{-17}$ with variance $10^{-33}$, decaying exponentially with qubit count and fitting cleanly. Why is this not a barren plateau?

19. Give the three causes of a zero gradient and the one-line test that distinguishes them.

20. Case Study 1's artifact was monotonic, exponential, and well-fitted. What general lesson does that support?


Answers

1. A QNode is a quantum function bound to a device — the @qml.qnode(dev) decorator turns a Python function into something that runs a circuit and can be differentiated. There is no circuit object; the function body is the circuit, re-executed on each call.

2. Because PennyLane also supports continuous-variable devices, where the computational unit is a bosonic mode rather than a qubit. "Wire" is the neutral term covering both.

3. In PennyLane, parameters are plain Python function arguments, so there is no separate binding step and no ordering to get wrong. In Cirq, ParamResolver binds sympy symbols through a dict, which has no order. In Q#, parameters are function arguments checked against a declared signature. Qiskit's bug arises specifically from binding a positional list against a lexicographically sorted list of parameter names.

4. $\dfrac{\partial f}{\partial\theta} = \dfrac{f(\theta + \pi/2) - f(\theta - \pi/2)}{2}$

5. Because for $U(\theta) = e^{-i\theta P/2}$ with $P^2 = I$, the expectation value is exactly $f(\theta) = A\cos\theta + B\sin\theta$ — a pure sinusoid, a consequence of $P$ having eigenvalues $\pm1$. Two samples a quarter period apart determine a sinusoid's derivative exactly, with no truncation.

6. A sweet spot with degradation on both sides. At large $h$, truncation error dominates — the difference quotient is a poor approximation to the derivative. At small $h$, floating-point cancellation dominates — you subtract two nearly identical numbers and lose significant digits. The minimum near $h = 10^{-5}$ is where the two effects balance.

7. Because $\pi/2$ is a large shift, so the two evaluations differ substantially and their difference is not swamped by noise. On hardware, every evaluation carries shot noise of order $1/\sqrt{N}$; a finite difference divides that noise by a small $h$, amplifying it enormously, while the parameter-shift rule divides by 2.

8. $2n + 1$ — two shifted evaluations per parameter (at $+\pi/2$ and $-\pi/2$), plus one forward pass for the function value itself. Verified: 16 parameters → 33 executions.

9. $(2 \times 100 + 1) \times 200 \times 4096 = 201 \times 200 \times 4096 = 164{,}659{,}200$ — roughly $1.6\times10^8$ shots.

10. Only the 16 parameters on wire 0 can affect $\langle Z_0\rangle$; PennyLane determines this from the circuit structure and evaluates shifts only for those ($2\times16+1 = 33$). Diagnostic use: unexpected zeros in your gradient mean parameters are not connected to your observable — usually an ansatz bug.

11. (a) Is the trace still descending at the final step? If yes, you ran out of iterations — a stopping-criterion bug. (b) Change the optimizer. If a different optimizer closes the gap, capacity was never the constraint. Only after both come back clean is "too small" supported.

12. The original failure was simply too few steps — the run was stopped mid-descent. The instinctive fix is to reduce the step size on the assumption of overshooting, but the problem was insufficient distance travelled, so a smaller step travels less: at 0.05 it is still 0.155 away after 200 steps, worse than 0.25 was.

13. (a) The gradient bill grows — $2n+1$ executions per iteration, so 4→18 parameters is 9→37 executions. (b) The landscape gets flatter — larger ansätze are wider, moving toward the barren plateau. (c) The answer gets slightly worse — 6.66e-16 for 4 parameters against 6.32e-08 for 18, because more parameters means more directions to drift in.

14. $\text{Var}[\text{grad}] \sim \exp(-0.676\,n)$, which is ×0.5086 per qubit added — halving roughly every 1.03 qubits, and a 224× drop from 2 to 10 qubits. Within 2% of exactly one half, matching the textbook $\mathcal{O}(2^{-n})$ result.

15. $N \sim 1/g^2$ (from the $1/\sqrt N$ standard error on an expectation value). At $|g| = 3\times10^{-8}$: $N \approx 1.1\times10^{15}$ shots — per parameter, per iteration.

16. Because the optimizer is not making poor choices among visible options; it has no signal at all. Every direction looks flat to within the resolution its shot budget can achieve, so there is no information to act on. A better search strategy cannot help when the landscape carries no gradient information — which is why more shots and better optimizers both fail.

17. No. One, two, and six layers fall by 14.7×, 20.5×, and 15.0× respectively over the same four added qubits — a comparable factor in every case. A shallower ansatz raises the overall variance somewhat (a one-layer ansatz starts about 5× higher) but the decay with width is unchanged. You buy a constant factor, not a change in scaling.

18. Because $10^{-17}$ is machine epsilon, not a small measurement. A genuine barren plateau at two qubits is impossible — the landscape is tiny and gradients are $\mathcal{O}(0.1)$. The sampled parameter was the first $R_Z$ of Rot acting on $|0\rangle$, which contributes only a global phase, so its derivative is identically zero; the $10^{-17}$ is floating-point residue in the parameter-shift subtraction.

19. Structurally zero (exactly ~1e-17 at every parameter value and size), disconnected from the observable (exactly zero, gates on unmeasured wires), and a genuine barren plateau (small but nonzero, varying between draws, shrinking with width). The test: resample the parameters and look again. A structural zero stays at 1e-17; a plateau gradient is a random variable that happens to be small.

20. A convincing fit is not evidence of a correct measurement. The artifact was monotonic, exponential, cleanly fitted — in fact more internally consistent than the real signal, because floating-point noise is smoother than physics. Qualitative agreement with what you expected to find is the weakest possible confirmation, and it is exactly the situation in which a wrong result gets published.