|q⟩ Bad Qubits

advanced · Programming · Quantum Software Engineering & Resource Estimation

Resource Estimation

Before committing months of effort to a quantum algorithm, you want an answer to a blunt question: how big and how long? Resource estimation produces that answer — a count of qubits, gates, circuit depth, and (under a fault-tolerant model) physical resources and runtime. It is the quantum analogue of complexity analysis, but with constants that matter, because a factor of ten can be the difference between "runs tonight" and "runs in a decade".

Two regimes of estimate

A resource estimate lives in one of two regimes:

This lesson works the concrete count for the cleanest example: Grover's search.

Counting Grover's iterations

Grover's algorithm searches an unstructured database of N=2nN = 2^n items, with one marked item, by repeating a two-step Grover iterate: apply the oracle (which flips the phase of the marked state) then the diffusion operator (which reflects about the mean). Each iterate rotates the state vector by a fixed angle θ\theta in the two-dimensional plane spanned by the marked and unmarked states, where

sinθ=1N,θ1N for large N.\sin\theta = \frac{1}{\sqrt{N}}, \qquad \theta \approx \frac{1}{\sqrt{N}} \text{ for large } N.

Starting from the uniform superposition (already at angle θ/2\theta/2 from the unmarked axis), we want to rotate as close as possible to the marked axis at π/2\pi/2. The optimal number of iterations is

k=π4N.k = \left\lfloor \frac{\pi}{4}\sqrt{N} \right\rfloor.

This is the famous quadratic speedup: O(N)O(\sqrt{N}) oracle calls instead of the classical O(N)O(N).

Qubits, gates, and depth

A complete Grover estimate has three numbers:

Why the floor, and why it can be off by one

The exact optimum is a real number (π/4)N1/2(\pi/4)\sqrt{N} - 1/2; rounding to the nearest integer maximises success probability. Using the floor of (π/4)N(\pi/4)\sqrt{N} is the standard, slightly conservative choice and is exact when NN is large. The residual angle error means Grover's success probability is very close to but not exactly 1 — a subtlety a good resource estimate notes rather than hides.

Try it

Compute the optimal Grover iteration count for an n=10n = 10 qubit search (N=210=1024N = 2^{10} = 1024 items, one marked) and return it as an integer. The grader checks the value and that it is a whole number.

Run your code to see the quantum state.

Sign in on the full site to ask questions and join the discussion.