|q⟩ Bad Qubits

intermediate · Programming · Noise, Decoherence & Density-Matrix Simulation

The Phase-Flip Channel

Real quantum hardware is never perfectly isolated. The environment continuously disturbs qubit phases, a process called dephasing. The phase-flip channel is the simplest mathematical model of this effect.

Kraus operators and the phase-flip channel

A quantum channel is a completely positive, trace-preserving (CPTP) map. One natural representation uses Kraus operators {Ki}\{K_i\}, which satisfy iKiKi=I\sum_i K_i^\dagger K_i = I. The action on a density matrix ρ\rho is

E(ρ)=iKiρKi.\mathcal{E}(\rho) = \sum_i K_i \rho K_i^\dagger.

For the phase-flip channel with error probability p[0,12]p \in [0, \tfrac{1}{2}] the two Kraus operators are

K0=1pI,K1=pZ.K_0 = \sqrt{1-p}\,I, \qquad K_1 = \sqrt{p}\,Z.

Substituting and expanding gives

E(ρ)=(1p)IρI+pZρZ=(1p)ρ+pZρZ.\mathcal{E}(\rho) = (1-p)\,I\rho I^\dagger + p\,Z\rho Z^\dagger = (1-p)\,\rho + p\,Z\rho Z.

With probability 1p1-p nothing happens; with probability pp the qubit suffers a ZZ error (a phase flip). You can verify the trace-preservation condition directly: (1p)II+pZZ=(1p)I+pI=I(1-p)I^\dagger I + p Z^\dagger Z = (1-p)I + pI = I.

What does a Z error do?

The ZZ gate is diagonal in the computational basis:

Z=(1001).Z = \begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix}.

It leaves 0|0\rangle unchanged and maps 11|1\rangle \to -|1\rangle. For a general state α0+β1\alpha|0\rangle + \beta|1\rangle the result is α0β1\alpha|0\rangle - \beta|1\rangle. There is no change to measurement probabilities in the ZZ basis, but the relative phase between 0|0\rangle and 1|1\rangle flips sign.

This is catastrophic for a qubit stored in the XX basis. The equal-superposition state

+=12(0+1)|{+}\rangle = \tfrac{1}{\sqrt{2}}\bigl(|0\rangle + |1\rangle\bigr)

becomes

Z+=12(01)=.Z|{+}\rangle = \tfrac{1}{\sqrt{2}}\bigl(|0\rangle - |1\rangle\bigr) = |{-}\rangle.

The two states +|{+}\rangle and |{-}\rangle are orthogonal — they are perfectly distinguishable in the XX basis, so a single phase flip is detectable and correctable in principle.

Dephasing destroys off-diagonal coherence

Working in the density-matrix picture makes the destruction of coherence explicit. Write the pure state ++|{+}\rangle\langle{+}| in matrix form:

++=12(1111).|{+}\rangle\langle{+}| = \frac{1}{2}\begin{pmatrix} 1 & 1 \\ 1 & 1 \end{pmatrix}.

Applying the channel with arbitrary pp:

E ⁣(++)=12(112p12p1).\mathcal{E}\!\left(|{+}\rangle\langle{+}|\right) = \frac{1}{2}\begin{pmatrix} 1 & 1-2p \\ 1-2p & 1 \end{pmatrix}.

The diagonal entries (populations) are unchanged, but the off-diagonal entries (coherences) are multiplied by (12p)(1-2p). At p=12p = \tfrac{1}{2} the coherences vanish entirely and the qubit is maximally mixed, 12I\tfrac{1}{2}I. This is the hallmark of decoherence: the system retains its energy but loses all quantum superposition.

Connection to real hardware

On a physical device dephasing accumulates continuously. The characteristic timescale is T2T_2 (or its Ramsey counterpart T2T_2^*). In the discrete model studied here, pp increases with the time a qubit spends idle. Keeping gate sequences short — or encoding information in decoherence-free subspaces — is the standard mitigation strategy.

Try it

The exercise below asks you to simulate a single phase-flip event acting on +|{+}\rangle. Build the 1-qubit circuit that prepares +|{+}\rangle and then applies the ZZ error, leaving the qubit in |{-}\rangle. The grader compares the full statevector, so the order matters.

Run your code to see the quantum state.

After running your circuit, inspect the statevector: the amplitude of 0|0\rangle should be +120.707+\tfrac{1}{\sqrt{2}} \approx 0.707 and the amplitude of 1|1\rangle should be 120.707-\tfrac{1}{\sqrt{2}} \approx -0.707, confirming the phase flip.

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