|q⟩ Bad Qubits

beginner · Programming · Single-Qubit Gates II: H, S, T & Phase

The General Phase Gate P(λ)

The general phase gate P(λ)P(\lambda) multiplies the 1|1\rangle component of a qubit by the complex number eiλe^{i\lambda} while leaving 0|0\rangle untouched:

P(λ)0=0,P(λ)1=eiλ1.P(\lambda)|0\rangle = |0\rangle, \qquad P(\lambda)|1\rangle = e^{i\lambda}|1\rangle.

Its matrix representation in the computational basis is

P(λ)=(100eiλ).P(\lambda) = \begin{pmatrix} 1 & 0 \\ 0 & e^{i\lambda} \end{pmatrix}.

This is a relative phase operation. A global phase — multiplying the entire state by eiϕe^{i\phi} — has no physical consequence, because probabilities depend only on amplitude magnitudes. But a relative phase between the 0|0\rangle and 1|1\rangle components changes the direction of the Bloch vector and can be detected by interference, making it physically meaningful.

Special cases you already know

Several gates you may have met are just P(λ)P(\lambda) at specific angles:

| Gate | λ\lambda | Effect on 1|1\rangle | |------|-----------|-----------------------| | ZZ | π\pi | eiπ=1e^{i\pi} = -1 | | SS | π/2\pi/2 | eiπ/2=ie^{i\pi/2} = i | | TT | π/4\pi/4 | eiπ/4e^{i\pi/4} |

In code, every one of these can equivalently be written as c.p(lambda, qubit) with the appropriate λ\lambda, so the circuit library exposes P as the general primitive.

Relative phase in a superposition

P(λ)P(\lambda) only changes something observable when the qubit is in a superposition. Starting from 0|0\rangle, apply the Hadamard to get +=12(0+1)|+\rangle = \tfrac{1}{\sqrt{2}}(|0\rangle + |1\rangle), then apply P(λ)P(\lambda):

P(λ)+=12(0+eiλ1).P(\lambda)|+\rangle = \frac{1}{\sqrt{2}}\big(|0\rangle + e^{i\lambda}|1\rangle\big).

For λ=π/2\lambda = \pi/2 in particular, the result is

P ⁣(π2)+=12(0+i1),P\!\left(\tfrac{\pi}{2}\right)|+\rangle = \frac{1}{\sqrt{2}}\big(|0\rangle + i|1\rangle\big),

which is the +i|+i\rangle state — the +y+y eigenstate of the Pauli YY operator. The measurement probabilities are still P(0)=P(1)=12P(0) = P(1) = \tfrac{1}{2}, but the Bloch vector now points along +y+y instead of +x+x. The phase is invisible to a single ZZ-basis measurement; it reveals itself only in an XX- or YY-basis measurement, or through interference in a larger circuit.

Try it

Starting from 0|0\rangle, create the state 12(0+i1)\tfrac{1}{\sqrt{2}}(|0\rangle + i|1\rangle) using HH followed by P(π/2)P(\pi/2). The grader compares your full statevector to the expected output.

Run your code to see the quantum state.

After running, inspect the State panel: the 0|0\rangle amplitude should read 0.707\approx 0.707 (real, imaginary 00) and the 1|1\rangle amplitude should read imaginary part 0.707\approx 0.707, confirming that the relative phase is eiπ/2=ie^{i\pi/2} = i.

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