|q⟩ Bad Qubits

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

Mixed States and Density Matrices

A pure state ψ|\psi\rangle carries all the information about a quantum system; you know the exact state vector. Real hardware, however, suffers noise: a qubit may have been prepared incorrectly, interacted with its environment, or relaxed before you could use it. In those cases you only know that the qubit is in state ψi|\psi_i\rangle with probability pip_i. This is a mixed state, and the right tool to describe it is the density matrix.

From state vectors to density matrices

For a pure state ψ|\psi\rangle the density matrix is the outer product

ρ=ψψ.\rho = |\psi\rangle\langle\psi|.

For a mixed state — a classical probability distribution over pure states — it is the weighted average

ρ=ipiψiψi,ipi=1,  pi0.\rho = \sum_i p_i\, |\psi_i\rangle\langle\psi_i|, \qquad \sum_i p_i = 1,\; p_i \ge 0.

Every valid density matrix is Hermitian (ρ=ρ\rho^\dagger = \rho), positive semi-definite (ϕρϕ0\langle\phi|\rho|\phi\rangle \ge 0 for all ϕ|\phi\rangle), and has unit trace (tr(ρ)=1\text{tr}(\rho) = 1).

A one-qubit example

Suppose a noisy source emits 0|0\rangle with probability p0=0.7p_0 = 0.7 and 1|1\rangle with probability p1=0.3p_1 = 0.3. The density matrix is

ρ=0.700+0.311=(0.7000.3).\rho = 0.7\,|0\rangle\langle 0| + 0.3\,|1\rangle\langle 1| = \begin{pmatrix} 0.7 & 0 \\ 0 & 0.3 \end{pmatrix}.

The diagonal entries are the probabilities of each basis state. There are no off-diagonal terms because this is a classical mixture — no quantum coherence between 0|0\rangle and 1|1\rangle. Compare this with the equal-superposition pure state +=(0+1)/2|{+}\rangle = (|0\rangle + |1\rangle)/\sqrt{2}, whose density matrix is

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

The off-diagonal entries (coherences) are a hallmark of genuine quantum superposition. Decoherence is the process by which those off-diagonal entries decay toward zero, turning the pure ρ+\rho_{+} into a diagonal mixed state.

Purity: how mixed is the state?

The purity of a state is

γ=tr(ρ2),1dγ1,\gamma = \text{tr}(\rho^2), \qquad \frac{1}{d} \le \gamma \le 1,

where dd is the dimension (d=2d = 2 for a qubit). γ=1\gamma = 1 if and only if ρ\rho is pure. The maximally mixed state ρ=I/d\rho = I/d has the minimum purity γ=1/d\gamma = 1/d.

For a diagonal density matrix with entries p0p_0 and p1p_1 (so p0+p1=1p_0 + p_1 = 1),

tr(ρ2)=p02+p12.\text{tr}(\rho^2) = p_0^2 + p_1^2.

Substituting p0=0.7p_0 = 0.7, p1=0.3p_1 = 0.3:

γ=0.49+0.09=0.58.\gamma = 0.49 + 0.09 = 0.58.

This is strictly less than 1 (not pure) and greater than 1/21/2 (not maximally mixed) — exactly what we expect for a moderately noisy qubit.

Measurement from the density matrix

The probability of measuring outcome bb is

P(b)=tr ⁣(bbρ)=bρb=ρbb,P(b) = \text{tr}\!\left(\,|b\rangle\langle b|\,\rho\right) = \langle b|\rho|b\rangle = \rho_{bb},

just the corresponding diagonal entry. For the noisy qubit above, P(0)=0.7P(0) = 0.7 and P(1)=0.3P(1) = 0.3.

Try it

A qubit is prepared as a classical mixture: 0|0\rangle with probability 0.7 and 1|1\rangle with probability 0.3. Compute and return the purity tr(ρ2)\text{tr}(\rho^2) of this mixed state.

Run your code to see the quantum state.

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