|q⟩ Bad Qubits

intermediate · Programming · Quantum Phase Estimation

Controlled-U Powers

Quantum phase estimation (QPE) extracts the eigenphase of a unitary UU by entangling a register of control qubits with repeated applications of UU. Each control qubit kk (indexed 0,1,,n10, 1, \ldots, n-1) is coupled to the target through the powered unitary U2kU^{2^k}. Understanding how to build and apply these controlled powers is the central programming skill of QPE.

Eigenphases and powers

Suppose Uu=e2πiφuU|u\rangle = e^{2\pi i \varphi}|u\rangle where φ[0,1)\varphi \in [0,1) is the unknown phase. Applying UU mm times accumulates the phase multiplicatively:

Umu=e2πimφu.U^m |u\rangle = e^{2\pi i m \varphi}|u\rangle.

This is why QPE uses U2kU^{2^k}: control qubit kk picks up exactly the bit φk\varphi_k of the binary expansion φ=0.φ0φ1φn1\varphi = 0.\varphi_0\varphi_1\cdots\varphi_{n-1} through the phase kickback mechanism.

Building UmU^m in a circuit

The most direct way to realize UmU^m is to apply UU exactly mm times in sequence. Each application is an independent gate invocation on the same wires. For the controlled version, every one of those mm applications is conditioned on the same control qubit:

controlled-Um=(controlled-U)m.\text{controlled-}U^m = (\text{controlled-}U)^m.

Concretely, if your controlled gate is c.cp(lambda, ctrl, target), then controlled-U^m is obtained by calling that line mm times with the same arguments.

Example: S2=ZS^2 = Z

The SS gate is the quarter-turn phase gate S=P(π/2)S = P(\pi/2), with matrix

S=(100i).S = \begin{pmatrix} 1 & 0 \\ 0 & i \end{pmatrix}.

Squaring it:

S2=(100i)2=(1001)=Z.S^2 = \begin{pmatrix} 1 & 0 \\ 0 & i \end{pmatrix}^2 = \begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix} = Z.

So controlled-S2=CZ\text{controlled-}S^2 = CZ. You can verify this by applying the controlled-SS gate twice — the phase angles add: P(π/2)P(\pi/2) followed by P(π/2)P(\pi/2) gives P(π)=ZP(\pi) = Z.

In circuit notation with qubit 0 as the control and qubit 1 as the target, c.cp(pi/2, 0, 1) is the controlled-SS gate, and calling it twice implements controlled-S2=CZS^2 = CZ.

Try it

Build the controlled-S2S^2 operator on 2 qubits by applying the controlled-SS gate twice. The grader checks the full unitary matrix, so an empty circuit (or a single application) will fail.

Run your code to see the quantum state.

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