|q⟩ Bad Qubits

intermediate · Programming · Quantum Phase Estimation

Precision and Qubit Count

Every run of quantum phase estimation (QPE) returns a bit string of length nn, where nn is the number of counting qubits. More counting qubits produce a longer bit string, which means a finer-resolution estimate of the phase.

Phases as binary fractions

QPE treats the unknown phase ϕ[0,1)\phi \in [0, 1) as a binary fraction with nn digits. The register can hold any integer k{0,1,,2n1}k \in \{0, 1, \ldots, 2^n - 1\}, and the algorithm outputs the integer k^\hat{k} nearest to ϕ2n\phi \cdot 2^n:

ϕ^=k^2n,ϕϕ^12n+1.\hat{\phi} = \frac{\hat{k}}{2^n}, \qquad \left|\phi - \hat{\phi}\right| \leq \frac{1}{2^{n+1}}.

The spacing between representable values is 1/2n1/2^n, so the absolute precision is

δϕ=12n.\delta\phi = \frac{1}{2^n}.

Each additional counting qubit halves the representable spacing, adding one more binary digit to the output. This is the quantum analogue of extending a fixed-point number with an extra bit:

| nn | Precision δϕ\delta\phi | Distinct representable phases | |-----|------------------------|-------------------------------| | 1 | 1/2 | 2 | | 2 | 1/4 | 4 | | 3 | 1/8 | 8 | | 4 | 1/16 | 16 | | nn | 1/2n1/2^n | 2n2^n |

Exact vs approximate phases

When ϕ\phi is an exact nn-bit binary fraction — that is, k=ϕ2nk = \phi \cdot 2^n is an integer — QPE returns kk with probability 1. If ϕ\phi falls between two representable values, the probability spreads across the two nearest integers. For the closest integer the success probability is at least 4/π20.4054/\pi^2 \approx 0.405; the tail falls off rapidly for the others. Adding more counting qubits concentrates probability on the correct outcome.

How the circuit encodes precision

After the initial Hadamard layer, each counting qubit jj (where j=0,1,,n1j = 0, 1, \ldots, n-1) interacts with the target register via a controlled-U2jU^{2^j} gate. Because the target is an eigenstate with eigenvalue e2πiϕe^{2\pi i\phi}, the only effect is a phase kick onto the counting qubit:

+j  ctrl-U2j  0+e2πi2jϕ12.|+\rangle_j \;\xrightarrow{\text{ctrl-}U^{2^j}}\; \frac{|0\rangle + e^{2\pi i \cdot 2^j \phi}\,|1\rangle}{\sqrt{2}}.

After all nn kicks, the register holds the state QFTnk\text{QFT}_n|k\rangle where kϕ2nk \approx \phi \cdot 2^n. Applying the inverse QFT decodes this back to k|k\rangle, making the phase readable by measurement.

Each additional qubit doubles the spacing of the Fourier frequencies it can resolve, halving δϕ\delta\phi.

Try it

The starter code builds the 3-qubit QPE register for phase ϕ=3/8\phi = 3/8. The superposition step and the inverse QFT are provided. Qubit 2 still needs its phase-kick gate.

When your circuit is correct, the distribution grader will show all probability on outcome 011|011\rangle (decimal 3), confirming that 3 counting qubits resolve ϕ=3/8\phi = 3/8 exactly to 3 bits of precision.

Run your code to see the quantum state.

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