|q⟩ Bad Qubits

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

The Bit-Flip Channel

When a qubit travels through a real device it may be accidentally flipped by the environment. The bit-flip channel captures this mathematically: with probability pp the Pauli-XX gate acts on the qubit, and with probability 1−p1-p nothing happens.

Density matrices for mixed states

A pure state ∣ψ⟩|\psi\rangle is described by a ket. A probabilistic mixture requires a density matrix

ρ=∑ipi∣ψi⟩⟨ψi∣,∑ipi=1,pi≥0.\rho = \sum_i p_i |\psi_i\rangle\langle\psi_i|, \quad \sum_i p_i = 1, \quad p_i \geq 0.

The 2×22\times 2 density matrix of a single qubit is Hermitian, positive semi-definite, and has unit trace. Pure states satisfy ρ2=ρ\rho^2 = \rho; mixed states satisfy tr(ρ2)<1\mathrm{tr}(\rho^2) \lt 1.

Kraus representation

A quantum channel (a completely positive, trace-preserving map) can always be written in the Kraus form

E(ρ)=∑kKk ρ Kk†,∑kKk†Kk=I.\mathcal{E}(\rho) = \sum_k K_k \,\rho\, K_k^\dagger, \quad \sum_k K_k^\dagger K_k = I.

The bit-flip channel has two Kraus operators

K0=1−p I,K1=p X.K_0 = \sqrt{1-p}\,I, \qquad K_1 = \sqrt{p}\,X.

You can verify the completeness relation: K0†K0+K1†K1=(1−p)I+pI=IK_0^\dagger K_0 + K_1^\dagger K_1 = (1-p)I + p I = I. The channel is therefore trace-preserving for any p∈[0,1]p \in [0,1].

Applying the channel to ∣0⟩|0\rangle

Start with the pure state ρin=∣0⟩⟨0∣\rho_{\mathrm{in}} = |0\rangle\langle 0|. Plugging into the Kraus sum:

E(ρin)=(1−p) I ∣0⟩⟨0∣ I+p X ∣0⟩⟨0∣ X=(1−p) ∣0⟩⟨0∣+p ∣1⟩⟨1∣.\mathcal{E}(\rho_{\mathrm{in}}) = (1-p)\,I\,|0\rangle\langle 0|\,I + p\,X\,|0\rangle\langle 0|\,X = (1-p)\,|0\rangle\langle 0| + p\,|1\rangle\langle 1|.

This is a mixture of ∣0⟩|0\rangle and ∣1⟩|1\rangle with classical weights (1−p)(1-p) and pp. In matrix form:

ρout=(1−p00p).\rho_{\mathrm{out}} = \begin{pmatrix} 1-p & 0 \\ 0 & p \end{pmatrix}.

The diagonal entries are the probabilities of the two outcomes. Measuring this state in the computational basis gives

P(measure 0)=⟨0∣ρout∣0⟩=1−p,P(measure 1)=⟨1∣ρout∣1⟩=p.P(\text{measure } 0) = \langle 0|\rho_{\mathrm{out}}|0\rangle = 1 - p, \qquad P(\text{measure } 1) = \langle 1|\rho_{\mathrm{out}}|1\rangle = p.

Purity loss

Before the channel the state is pure: tr(ρin2)=1\mathrm{tr}(\rho_{\mathrm{in}}^2) = 1. After it

tr(ρout2)=(1−p)2+p2=1−2p(1−p).\mathrm{tr}(\rho_{\mathrm{out}}^2) = (1-p)^2 + p^2 = 1 - 2p(1-p).

This is strictly less than 1 for 0<p<10 \lt p \lt 1, confirming that noise has turned the pure state into a mixed state. The purity is minimised at p=1/2p = 1/2, where it equals 1/21/2.

Try it

The bit-flip channel with p=0.3p = 0.3 is applied to ∣0⟩|0\rangle. Compute the probability of measuring ∣1⟩|1\rangle and return it.

Run your code to see the quantum state.

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