Quantum Computation & Cryptography · Lecture 18

Lecture 18
Density Matrices and Quantum Channels

Week 10  |  Block III begins: states we only partly know, halves of entangled pairs, and the mathematics of noise  |  reading: Watrous Ch. 9–10 (density matrices, channels)

Cartoon: the shuffled envelopesA stick figure holds a sealed envelope. Behind it, a machine has two chutes, one marked |0> with the note 3 in 4 and one marked |-i> with the note 1 in 4. A speech bubble says: I don't know which one I got, but I can still predict every experiment. |0>: 3 in 4|-i>: 1 in 4shuffle I don't know which oneI got, but I can stillpredict every experiment
a density matrix holds exactly what can be predicted about a qubit whose preparation is uncertain, or which is half of something larger
In this lecture
  1. Two reasons vectors are not enough
  2. Density matrices
  3. The Bloch ball
  4. The partial trace
  5. Quantum channels
  6. How far apart are two states?
  7. Try it in code
  8. Summary and exercises

Every result in Blocks I and II assumed perfect gates and perfectly known states. Real devices are noisy (Lecture 17's resource estimates were all about that), and we often know a state only statistically. This lecture introduces the language for both situations. By the end you should be able to build the density matrix of an ensemble and use it to predict measurements, decide whether a state is pure, locate it in the Bloch ball, compute a reduced state with the partial trace, apply a channel given its Kraus operators, and compute the trace distance and fidelity of two qubit states.

1 — Two reasons vectors are not enough

Classical ignorance. A source prepares \(|0\rangle\) with probability \(\tfrac34\) and \(|{-i}\rangle\) with probability \(\tfrac14\), and does not tell us which. No single vector \(|\psi\rangle\) describes what we hold: the probability of each outcome of any measurement is an average over the two possibilities, and that average is not the Born rule for any one state.

Entanglement. Alice holds one qubit of an entangled pair (Lecture 5). Her qubit on its own has no state vector at all, since the pair is not a product. Yet she can measure it, and her statistics must be described by something that refers to her qubit only.

Both situations are handled by one object, and the second turns out to be a special case of the first.

2 — Density matrices

definition 18.1 — density matrix of an ensemble

An ensemble is a list of states \(|\psi_k\rangle\) prepared with probabilities \(p_k\). Its density matrix is

$$\rho=\sum_kp_k\,|\psi_k\rangle\langle\psi_k| .$$

A pure state \(|\psi\rangle\) has density matrix \(|\psi\rangle\langle\psi|\). For \(|\psi\rangle=\alpha|0\rangle+\beta|1\rangle\) this is the matrix \(\begin{pmatrix}|\alpha|^2&\alpha\bar\beta\\ \bar\alpha\beta&|\beta|^2\end{pmatrix}\).

The point of \(\rho\) is that it predicts every measurement. If we measure in an orthonormal basis \(\{|b\rangle\}\), the outcome \(b\) has probability \(\sum_kp_k|\langle b|\psi_k\rangle|^2\) (average over the ensemble, Born rule within each member), and \(|\langle b|\psi_k\rangle|^2=\langle b|\psi_k\rangle\langle\psi_k|b\rangle\). Summing,

$$P(b)=\langle b|\rho|b\rangle=\operatorname{tr}\big(\rho\,|b\rangle\langle b|\big).$$

After a gate \(U\), each member becomes \(U|\psi_k\rangle\), so \(\rho\mapsto U\rho U^\dagger\). Since all predictions go through \(\rho\), two ensembles with the same density matrix cannot be told apart by any experiment: \(\rho\) is the state.

A source prepares \(|1\rangle\) with probability 0.6 and \(|{+i}\rangle\) with probability 0.4. The qubit is measured in the Y basis. What is the probability of the outcome \({+i}\)?

Average over the ensemble, Born rule within each member: \(P({+i})=0.6\,|\langle{+i}|1\rangle|^2+0.4\,|\langle{+i}|{+i}\rangle|^2\).
\(0.6\cdot\tfrac12+0.4\cdot1=0.7\). The same number is \(\langle{+i}|\rho|{+i}\rangle\) for the ensemble's \(\rho\).
proposition 18.1 — what a density matrix looks like

Every density matrix \(\rho\) is (a) Hermitian, (b) positive semidefinite, \(\langle v|\rho|v\rangle\ge0\) for all \(v\), and (c) of trace 1. Conversely, every matrix with (a)–(c) is the density matrix of some ensemble, for example of its eigenvectors weighted by its eigenvalues. Moreover \(\operatorname{tr}\rho^2\le1\), with equality exactly when \(\rho\) is pure.

(a) Each \(|\psi\rangle\langle\psi|\) is Hermitian and real combinations of Hermitian matrices are Hermitian. (b) \(\langle v|\rho|v\rangle=\sum_kp_k|\langle v|\psi_k\rangle|^2\ge0\). (c) \(\operatorname{tr}|\psi\rangle\langle\psi|=\langle\psi|\psi\rangle=1\), and the \(p_k\) sum to 1. Conversely, by the spectral theorem (Lecture 2) a Hermitian \(\rho\) equals \(\sum_j\lambda_j|e_j\rangle\langle e_j|\) with orthonormal \(|e_j\rangle\); (b) makes \(\lambda_j\ge0\) and (c) makes them sum to 1, so they are probabilities. Finally \(\operatorname{tr}\rho^2=\sum_j\lambda_j^2\le\sum_j\lambda_j=1\), with equality iff one \(\lambda_j\) is 1 and the rest 0, that is, iff \(\rho=|e_j\rangle\langle e_j|\) is pure.

The quantity \(\operatorname{tr}\rho^2\) is the purity. For a qubit it ranges from 1 (pure) down to \(\tfrac12\), reached only by \(I/2\), the maximally mixed state: a fair coin between \(|0\rangle\) and \(|1\rangle\), and equally between any two orthogonal states.

Which of these matrices is a density matrix?

Check all three conditions of Proposition 18.1. For a \(2\times2\) Hermitian matrix with trace 1, positivity is the same as a nonnegative determinant.
It is Hermitian, has trace 1, and its determinant \(0.24-0.09=0.15\) is positive, so both eigenvalues are positive.
example 18.1 — the shuffled source

Find \(\rho\) for the ensemble \(\{(\tfrac34,|0\rangle),(\tfrac14,|{-i}\rangle)\}\) of the cartoon, its purity and eigenvalues, and the probability of each outcome in the Z and Y bases.

With \(|{-i}\rangle\langle{-i}|=\tfrac12\begin{pmatrix}1&i\\ -i&1\end{pmatrix}\),

$$\rho=\frac34\begin{pmatrix}1&0\\[2pt] 0&0\end{pmatrix}+\frac18\begin{pmatrix}1&i\\[2pt] -i&1\end{pmatrix}=\begin{pmatrix}7/8&i/8\\[2pt] -i/8&1/8\end{pmatrix}.$$

Purity: \(\operatorname{tr}\rho^2=\tfrac{49}{64}+\tfrac1{64}+2\cdot\tfrac1{64}=\tfrac{13}{16}\lt1\), so the state is mixed. The eigenvalues solve \(\lambda^2-\lambda+\det\rho=0\) with \(\det\rho=\tfrac7{64}-\tfrac1{64}=\tfrac3{32}\): \(\lambda=\tfrac12\big(1\pm\tfrac{\sqrt{10}}4\big)\approx0.895,\,0.105\). Measurements: \(P(0)=\rho_{00}=\tfrac78\). In the Y basis, \(P({+i})=\langle{+i}|\rho|{+i}\rangle=\tfrac38\) and \(P({-i})=\tfrac58\). (Check by averaging: \(P({-i})=\tfrac34\cdot\tfrac12+\tfrac14\cdot1=\tfrac58\).)

The off-diagonal entries of a density matrix are called coherences. A quick check of the definitions before reading on:

For \(\rho=\begin{pmatrix}1/2&-1/2\\ -1/2&1/2\end{pmatrix}\), the purity is \(\operatorname{tr}\rho^2=\) , so the state is .

For a Hermitian matrix, \(\operatorname{tr}\rho^2\) is the sum of the squared sizes of all four entries.
\(\operatorname{tr}\rho^2=4\cdot\tfrac14=1\): this is \(|-\rangle\langle-|\). Equal diagonal entries do not make a state mixed; the coherences carry the relative phase.

3 — The Bloch ball

proposition 18.2 — every qubit state is a point of the ball

Every qubit density matrix can be written uniquely as

$$\rho=\tfrac12\big(I+xX+yY+zZ\big),$$ $$\vec r=(x,y,z)=\big(\operatorname{tr}\rho X,\ \operatorname{tr}\rho Y,\ \operatorname{tr}\rho Z\big),$$ $$|\vec r|\le1 .$$

The state is pure exactly when \(|\vec r|=1\) (on the sphere, matching Definition 3.3), its purity is \(\tfrac12(1+|\vec r|^2)\), and measuring along a unit vector \(\vec n\) gives \(+\) with probability \(\tfrac12(1+\vec r\cdot\vec n)\). The density matrix of an ensemble has the probability-weighted average of the members' Bloch vectors.

\(I,X,Y,Z\) form a basis of the \(2\times2\) Hermitian matrices, the coefficients are real for Hermitian \(\rho\), and \(\operatorname{tr}\rho=1\) fixes the coefficient of \(I\) at \(\tfrac12\). Since \(\operatorname{tr}(PQ)=2\delta_{PQ}\) for Paulis, \(\operatorname{tr}\rho X=x\), and so on. The eigenvalues of \(\vec r\cdot\vec\sigma\) are \(\pm|\vec r|\), so those of \(\rho\) are \(\tfrac12(1\pm|\vec r|)\): positivity is \(|\vec r|\le1\), and purity \(\sum\lambda^2=\tfrac12(1+|\vec r|^2)\). The projector onto \(+\vec n\) is \(\tfrac12(I+\vec n\cdot\vec\sigma)\), and \(\operatorname{tr}\big(\rho\,\tfrac12(I+\vec n\cdot\vec\sigma)\big)=\tfrac12(1+\vec r\cdot\vec n)\). Finally \(\rho\mapsto\vec r\) is linear, so mixtures average Bloch vectors.

Find the Bloch vector and the purity of \(\rho=\begin{pmatrix}0.7&0.2\\ 0.2&0.3\end{pmatrix}\).

Expand \(\tfrac12(I+xX+yY+zZ)\): the diagonal is \(\tfrac12(1\pm z)\) and \(\rho_{10}=\tfrac12(x+iy)\). Then purity \(=\tfrac12(1+|\vec r|^2)\).
\(z=0.7-0.3=0.4\), \(x=2\operatorname{Re}\rho_{10}=0.4\), \(y=0\); \(|\vec r|^2=0.32\) and the purity is \(0.66\): a point inside the ball.

Example 18.1 has \(\vec r=\tfrac34(0,0,1)+\tfrac14(0,-1,0)=(0,-\tfrac14,\tfrac34)\), of length \(\sqrt{10}/4\approx0.79\): inside the ball, on the chord from \(|0\rangle\) to \(|{-i}\rangle\), a quarter of the way along. Its purity \(\tfrac12(1+\tfrac{10}{16})=\tfrac{13}{16}\) agrees with the direct computation.

Mixed states inside the Bloch ballTwo disks, each a slice of the Bloch ball. Left, the y-z slice: the pure states |0> at the top and |-i> at the left end of the y axis are joined by a chord; the mixture with weights 3/4 and 1/4 sits on the chord a quarter of the way from |0>, at y = -1/4, z = 3/4, inside the ball, at distance 0.79 from the centre. Right, the x-z slice: chords from |0> to |1> and from |+> to |-> cross at the centre, the maximally mixed state I/2, which both equal-weight ensembles produce.y-z slice: Example 18.1x-z slice: two ensembles for I/2yz|0>|-i>|1>rhorho = 3/4 |0><0| + 1/4 |-i><-i|r = (0, -1/4, 3/4)xz|0>|1>|+>|->I/2half |0>, half |1>= half |+>, half |->
Left: Example 18.1 inside the ball. Right: the centre \(I/2\) is the midpoint of every diameter, so equal mixtures of any two orthogonal states give the same density matrix. Any point inside the ball lies on many chords, which is why many different ensembles share one density matrix: the state at the left is also an equal mixture of the two pure states \((\pm0.612,\,-0.25,\,0.75)\).

Tick every ensemble whose density matrix is \(I/2\).

The ensemble's Bloch vector is the weighted average of the members' Bloch vectors; \(I/2\) is the centre, \(\vec r=\vec 0\).
The first three are midpoints of diameters, and the three unit vectors \(120^\circ\) apart also average to \(\vec 0\). The last has unequal weights and averages to \((0,0,\tfrac12)\).

Mixing two pure states

Choose two pure states by their Bloch angles and the weight \(p\) of the first. The mixture's Bloch vector (rose) lies on the chord between them. Left panel: side view (x–z); right: top view (x–y). The readout gives the purity and eigenvalues; try to find two quite different pairs that give the same point.

4 — The partial trace

Now the second situation. Let two qubits be in a state \(\rho_{AB}\) (pure or not), with \(A\) the left factor and \(B\) the right. What state describes \(A\) alone?

definition 18.2 — partial trace

The reduced state of \(A\) is \(\rho_A=\operatorname{tr}_B\rho_{AB}\), defined on product operators by \(\operatorname{tr}_B(M\otimes N)=M\operatorname{tr}(N)\) and extended linearly. In components, \((\rho_A)_{ij}=\sum_k(\rho_{AB})_{ik,jk}\): sum over the matching indices of \(B\). For a pure two-qubit state with coefficient matrix \(C\) (Definition 5.6, rows indexed by \(A\)), \(\rho_A=CC^\dagger\) and \(\rho_B=(C^\dagger C)^{\mathsf T}\).

Two qubits are in \(\tfrac{\sqrt3}{2}|00\rangle+\tfrac12|11\rangle\) (kets \(|q_1q_0\rangle\)). Find the probability that measuring \(q_1\) alone gives 0, and the purity of \(\rho_{q_1}\).

The coefficient matrix is \(C=\mathrm{diag}(\tfrac{\sqrt3}2,\tfrac12)\) with rows indexed by \(q_1\); then \(\rho_{q_1}=CC^\dagger\).
\(\rho_{q_1}=\mathrm{diag}(\tfrac34,\tfrac14)\), so \(P(0)=\tfrac34\) and the purity is \(\tfrac9{16}+\tfrac1{16}=\tfrac58\): the state is entangled, so its halves are mixed.
proposition 18.3 — the reduced state is the right one

For every observable or measurement on \(A\) alone, \(\operatorname{tr}\big(\rho_{AB}(M\otimes I)\big)=\operatorname{tr}(\rho_AM)\). So \(\rho_A\) predicts everything that can be learned by experiments on \(A\), and nothing done to \(B\) alone (any gate, any measurement whose result is not communicated) changes it.

The first identity is the definition, checked on products: \(\operatorname{tr}\big((P\otimes Q)(M\otimes I)\big)=\operatorname{tr}(PM)\operatorname{tr}(Q)=\operatorname{tr}\big(\operatorname{tr}_B(P\otimes Q)M\big)\), then linearity. For the second, a gate \(I\otimes U\) on \(B\) changes \(\rho_{AB}\) to \((I\otimes U)\rho_{AB}(I\otimes U^\dagger)\), and the cyclicity of the trace over \(B\) removes \(U\). A measurement on \(B\) with unknown outcome replaces \(\rho_{AB}\) by \(\sum_b(I\otimes\Pi_b)\rho_{AB}(I\otimes\Pi_b)\), and \(\sum_b\Pi_b=I\) gives the same \(\rho_A\).

In the same state \(\tfrac{\sqrt3}{2}|00\rangle+\tfrac12|11\rangle\), Bob measures \(q_0\) in the X basis and does not tell Alice the outcome. Alice's probability of getting 0 from \(q_1\) is now .

Proposition 18.3: a measurement on \(B\) whose result is not communicated does not change \(\rho_A\).
\(\rho_{q_1}\) is unchanged, so \(P(0)=\tfrac34\) still. Only when Bob sends his outcome can Alice condition on it, and that message travels no faster than light.
example 18.2 — half of a partly entangled pair

Let \(|\psi\rangle=\tfrac1{\sqrt3}\big(|00\rangle+|01\rangle+|11\rangle\big)\), kets \(|q_1q_0\rangle\). Find the reduced state of each qubit, its purity and its eigenvalues.

The coefficient matrix is \(C=\tfrac1{\sqrt3}\begin{pmatrix}1&1\\ 0&1\end{pmatrix}\) (rows: \(q_1\)). Then

$$\rho_{q_1}=CC^\dagger=\frac13\begin{pmatrix}2&1\\[2pt] 1&1\end{pmatrix},\qquad \rho_{q_0}=(C^\dagger C)^{\mathsf T}=\frac13\begin{pmatrix}1&1\\[2pt] 1&2\end{pmatrix}.$$

Both have trace 1, determinant \(\tfrac19\) and purity \(\tfrac{4+1+1+1}{9}=\tfrac79\), and eigenvalues \(\tfrac{3\pm\sqrt5}{6}\approx0.873,\ 0.127\). These are the squares of the Schmidt coefficients of \(|\psi\rangle\) (Lecture 5): for a pure state of two parts, the two reduced states always have the same eigenvalues, and they are pure exactly when the state is a product. The less pure the halves, the more entangled the whole.

No signalling, made precise. Proposition 18.3 is the reason entanglement cannot transmit information. In teleportation (Lecture 8), before Alice's two bits arrive, Bob's qubit is in one of four states \(P|\psi\rangle\), \(P\in\{I,X,Z,XZ\}\), each with probability \(\tfrac14\), so his density matrix is \(\tfrac14\sum_PP\rho P^\dagger\). This average is \(I/2\) for every qubit state (HW10 Problem 1 asks you to show it): Bob holds a maximally mixed qubit, independent of \(|\psi\rangle\), until the classical bits tell him which correction to apply.

5 — Quantum channels

Noise is anything that happens to a qubit that is not a known unitary: a random gate error, leakage of information to the environment, energy loss. The most general physically allowed transformation of a state has a simple form.

definition 18.3 — quantum channel (Kraus form)

A channel is a map

$$\Phi(\rho)=\sum_kK_k\,\rho\,K_k^\dagger\qquad\text{with}\qquad \sum_kK_k^\dagger K_k=I .$$

The matrices \(K_k\) are its Kraus operators. The condition on the right guarantees that \(\Phi(\rho)\) has trace 1; \(\Phi(\rho)\) is automatically Hermitian and positive semidefinite.

One way to read the formula: with probability \(\operatorname{tr}(K_k\rho K_k^\dagger)\) the event \(k\) happens and the state becomes \(K_k\rho K_k^\dagger\) (normalised), and we do not learn which event happened. A unitary is a channel with one Kraus operator. "Measure in the standard basis and forget the result" has Kraus operators \(|0\rangle\langle0|\) and \(|1\rangle\langle1|\), and it kills the coherences.

Four channels describe most single-qubit noise. Each sends the Bloch ball into itself, and since \(\Phi\) is linear, it acts on Bloch vectors as an affine map \(\vec r\mapsto M\vec r+\vec c\): the ball becomes an ellipsoid.

The phase-flip channel with \(p=0.2\) acts on \(|+\rangle\). The result is then measured in the X basis. What is \(P(+)\)?

\(|+\rangle\) has \(\vec r=(1,0,0)\), and the phase flip multiplies \(x\) by \(1-2p\). Then \(P(+)=\tfrac12(1+x)\) (Proposition 18.2).
\(x=1-0.4=0.6\), so \(P(+)=0.8\). Before the channel the outcome \(+\) was certain; dephasing destroys exactly this kind of information.
What four channels do to the Bloch ball (x-z slice)Four panels, each showing the x-z slice of the Bloch ball as a dashed unit circle and its image under a channel as a filled shape, computed by applying the Kraus operators to states on the circle. Bit flip with p = 0.3: an ellipse keeping the x axis and squeezing z to 0.4. Phase flip with p = 0.3: an ellipse keeping z and squeezing x to 0.4. Depolarizing with p = 0.3: a circle of radius 0.7. Amplitude damping with gamma = 0.5: an ellipse of half-height 0.5 and half-width 0.71 whose top touches the north pole |0>, centred at z = 0.5.bit flip 0.3zxphase flip 0.3zxdepolarizing 0.3zxamp. damping 0.5zxdashed: pure states (the sphere); green: where the channel sends them
The x–z slice of the Bloch ball (dashed) and its image under each channel, computed by applying the Kraus operators to states on the circle (figs_L18.py). Bit flip keeps the x axis and squeezes the others; phase flip keeps the z axis; the depolarizing channel shrinks the ball; amplitude damping squeezes it and pushes it toward \(|0\rangle\) (blue dot).

Channel explorer

Pick a channel and its strength. The panel shows the image of the x–z slice of the ball, computed from the channel's action on Bloch vectors, and where one chosen pure state (rose) goes. Apply the channel repeatedly with "apply again" to watch the state converge.

idea — noise is entanglement with the environment

Every channel arises by letting the qubit interact unitarily with an environment that starts in a fixed state and then forgetting (tracing out) the environment; this is Stinespring's theorem. The simplest case: a CNOT from the qubit onto an environment qubit in \(|0\rangle\) copies the \(Z\) value into the environment. Tracing out the environment leaves the qubit with its populations intact and its coherences gone: the phase-flip channel with \(p=\tfrac12\). The second code box in Section 7 does exactly this. Decoherence is not the qubit "getting tired"; it is information about the qubit leaking into things we do not control, which is why isolating qubits is the central engineering problem.

6 — How far apart are two states?

definition 18.4 — trace distance and fidelity

The trace distance is \(D(\rho,\sigma)=\tfrac12\sum_j|\lambda_j|\), the eigenvalues \(\lambda_j\) being those of \(\rho-\sigma\). The fidelity is \(F(\rho,\sigma)=\big(\operatorname{tr}\sqrt{\sqrt\rho\,\sigma\sqrt\rho}\big)^2\); if \(\sigma=|\psi\rangle\langle\psi|\) is pure, \(F=\langle\psi|\rho|\psi\rangle\).

proposition 18.4 — distances for qubits, and what they mean

For qubit states with Bloch vectors \(\vec r\) and \(\vec s\):

$$D(\rho,\sigma)=\tfrac12|\vec r-\vec s|,\qquad F(\rho,\sigma)=\tfrac12\Big(1+\vec r\cdot\vec s+\sqrt{(1-|\vec r|^2)(1-|\vec s|^2)}\Big).$$

Operationally: given one copy of a state that is \(\rho\) or \(\sigma\) with equal probability, the best possible measurement guesses correctly with probability \(\tfrac12+\tfrac12D(\rho,\sigma)\) (Helstrom). No channel can increase the trace distance: \(D(\Phi(\rho),\Phi(\sigma))\le D(\rho,\sigma)\).

Proof sketch. \(\rho-\sigma=\tfrac12(\vec r-\vec s)\cdot\vec\sigma\) has eigenvalues \(\pm\tfrac12|\vec r-\vec s|\). The fidelity formula is a \(2\times2\) computation (checked numerically in verify_L18.py). For Helstrom's bound and contractivity, see Watrous Ch. 9 or Nielsen–Chuang §9.2.

Let \(\rho=\mathrm{diag}(\tfrac14,\tfrac34)\) and \(\sigma=|1\rangle\langle1|\). Find \(D(\rho,\sigma)\) and the best probability of guessing correctly, from one copy, which of the two (equally likely) you hold.

Bloch vectors: \(\vec r=(0,0,-\tfrac12)\) and \(\vec s=(0,0,-1)\). Use \(D=\tfrac12|\vec r-\vec s|\) and Helstrom's \(\tfrac12+\tfrac12D\).
\(D=\tfrac12\cdot\tfrac12=\tfrac14\), and the best guess is right with probability \(\tfrac12+\tfrac18=\tfrac58\): the two states are hard to tell apart.
example 18.3 — how far is the shuffled source from |0⟩?

Compute \(D\) and \(F\) between Example 18.1's \(\rho\) and \(|0\rangle\langle0|\), and \(D\) between \(\rho\) and \(I/2\).

\(\vec r=(0,-\tfrac14,\tfrac34)\) and \(\vec s=(0,0,1)\): \(D=\tfrac12\big|(0,-\tfrac14,-\tfrac14)\big|=\tfrac{\sqrt2}{8}\approx0.177\). Since \(|0\rangle\) is pure, \(F=\langle0|\rho|0\rangle=\tfrac78\). So the best single-shot test tells \(\rho\) from \(|0\rangle\) only with probability \(\tfrac12+\tfrac12\cdot0.177\approx0.588\). From the centre: \(D(\rho,I/2)=\tfrac12|\vec r|=\tfrac{\sqrt{10}}8\approx0.395\).

Both quantities are used constantly from here on: fidelity is how hardware papers report the quality of a gate or a prepared state (Lecture 19), and trace distance is how cryptographers bound what an eavesdropper can learn (Lecture 20).

7 — Try it in code

tool — density matrices and partial traces (qiskit.quantum_info, tested with qiskit 2.5)
import numpy as np
from qiskit.quantum_info import DensityMatrix, Statevector, SparsePauliOp, partial_trace

zero = Statevector([1, 0])
minus_i = Statevector([1, -1j]) / np.sqrt(2)
rho = 0.75 * DensityMatrix(zero) + 0.25 * DensityMatrix(minus_i)      # Example 18.1
print(np.round(rho.data, 4))
print("purity tr(rho^2) =", round(float(rho.purity().real), 4), "  is it a valid state?", rho.is_valid())
print("Bloch vector:", [round(float(rho.expectation_value(SparsePauliOp(P)).real), 4) + 0.0 for P in "XYZ"])
print("eigenvalues:", np.round(np.linalg.eigvalsh(rho.data), 4))

psi = Statevector(np.array([1, 1, 0, 1]) / np.sqrt(3))                 # Example 18.2, kets |q1 q0>
rho_q1 = partial_trace(psi, [0])                                       # trace out qubit 0, keep qubit 1
rho_q0 = partial_trace(psi, [1])                                       # trace out qubit 1, keep qubit 0
print("rho_q1 * 3 =", np.round(3 * rho_q1.data.real, 4).tolist(), "  rho_q0 * 3 =", np.round(3 * rho_q0.data.real, 4).tolist())
print("purity of each half:", round(float(rho_q1.purity().real), 4), round(float(rho_q0.purity().real), 4))
[[0.875+0.j    0.   +0.125j]
 [0.   -0.125j 0.125+0.j   ]]
purity tr(rho^2) = 0.8125   is it a valid state? True
Bloch vector: [0.0, -0.25, 0.75]
eigenvalues: [0.1047 0.8953]
rho_q1 * 3 = [[2.0, 1.0], [1.0, 1.0]]   rho_q0 * 3 = [[1.0, 1.0], [1.0, 2.0]]
purity of each half: 0.7778 0.7778

Examples 18.1 and 18.2. DensityMatrix accepts a Statevector and supports weighted sums; partial_trace(state, qargs) traces out the listed qubits (here qubit 0, the right-hand digit, in the first call), keeping the rest.

tool — channels, fidelity, and decoherence by an environment
import numpy as np
from qiskit import QuantumCircuit
from qiskit.quantum_info import DensityMatrix, Statevector, Kraus, SparsePauliOp, partial_trace, state_fidelity

I2 = np.eye(2); X = np.array([[0, 1], [1, 0]]); Z = np.diag([1, -1])
p = 0.3
bit_flip = Kraus([np.sqrt(1 - p) * I2, np.sqrt(p) * X])
phase_flip = Kraus([np.sqrt(1 - p) * I2, np.sqrt(p) * Z])
bloch = lambda r: [round(float(r.expectation_value(SparsePauliOp(P)).real), 3) + 0.0 for P in "XYZ"]

plus_i = DensityMatrix(Statevector([1, 1j]) / np.sqrt(2))              # Bloch vector (0, 1, 0)
for name, ch in (("bit flip", bit_flip), ("phase flip", phase_flip)):
    out = plus_i.evolve(ch)
    print(f"{name:10s}: Bloch {bloch(out)}, fidelity with |+i> {state_fidelity(out, plus_i):.3f}")

# decoherence as entanglement with an environment: CNOT from the qubit (q0) onto a fresh environment qubit (q1)
qc = QuantumCircuit(2)
qc.ry(2 * np.arccos(np.sqrt(0.8)), 0)                               # system: sqrt(0.8)|0> + sqrt(0.2)|1>, Bloch (0.8, 0, 0.6)
qc.cx(0, 1)                                                          # the environment "learns" the Z value
sys = partial_trace(Statevector.from_instruction(qc), [1])           # forget the environment
print("system after the environment looked:", np.round(sys.data.real, 3).tolist(), " Bloch", bloch(sys))
bit flip  : Bloch [0.0, 0.4, 0.0], fidelity with |+i> 0.700
phase flip: Bloch [0.0, 0.4, 0.0], fidelity with |+i> 0.700
system after the environment looked: [[0.8, 0.0], [0.0, 0.2]]  Bloch [0.0, 0.0, 0.6]

Both flips shorten the \(y\) component of \(|{+i}\rangle\) from 1 to \(1-2p=0.4\), so the fidelity drops to \(\tfrac12(1+0.4)=0.7\). The last line is the idea box of Section 5: after the CNOT, the qubit's Bloch vector \((0.8,0,0.6)\) has lost its \(x\) component, exactly as a phase flip with \(p=\tfrac12\) would do.

8 — Summary and exercises

summary

Next time: noise on real hardware (\(T_1\), \(T_2\), readout error) and error mitigation, and the launch of Lab 5. HW9 (Lectures 17–18) is due at the start of Week 11.

exercises 18
  1. Is \(\rho=\begin{pmatrix}1/2&1/2\\ 1/2&1/2\end{pmatrix}\) pure? Is \(\begin{pmatrix}1/2&i/4\\ -i/4&1/2\end{pmatrix}\)? Give the Bloch vector of each.
  2. Find an ensemble of two equally likely pure states whose density matrix is Example 18.1's \(\rho\). (Use Figure 1's chord idea.)
  3. The W state is \(\tfrac{1}{\sqrt3}(|001\rangle+|010\rangle+|100\rangle)\). Find the reduced state of qubit 2 (the leftmost) by grouping terms. Is it pure?
  4. Apply the bit-flip channel with \(p=0.3\) to \(|{+i}\rangle\) and to \(|+\rangle\). Which state is unaffected, and why?
  5. Compute the trace distance between \(|0\rangle\) and \(|+\rangle\), and the best probability of telling them apart with one copy.
  6. Show that "measure in the standard basis and forget the outcome" is the phase-flip channel with \(p=\tfrac12\).
  1. The first is \(|+\rangle\langle+|\), pure, \(\vec r=(1,0,0)\). The second has \(x=2\operatorname{Re}\rho_{10}=0\), \(y=2\operatorname{Im}\rho_{10}=-\tfrac12\), \(z=0\): \(\vec r=(0,-\tfrac12,0)\), mixed, purity \(\tfrac12(1+\tfrac14)=\tfrac58\).
  2. Write \(\vec r=(0,-\tfrac14,\tfrac34)\) as the midpoint of two points of the sphere: \(\vec r\pm\vec t\) with \(\vec t\perp\vec r\) and \(|\vec r|^2+|\vec t|^2=1\), for example \(\vec t=(\sqrt{6}/4,0,0)\approx(0.612,0,0)\). The ensemble \(\{(\tfrac12,\vec r+\vec t),(\tfrac12,\vec r-\vec t)\}\) (as pure states on the sphere) has the same \(\rho\); there are infinitely many such choices (any \(\vec t\perp\vec r\) of that length).
  3. Grouping by the leftmost qubit: \(\tfrac1{\sqrt3}\big(|0\rangle(|01\rangle+|10\rangle)+|1\rangle|00\rangle\big)\). The two branches are orthogonal, with weights \(\tfrac23\) and \(\tfrac13\), so \(\rho_2=\mathrm{diag}(\tfrac23,\tfrac13)\): mixed, purity \(\tfrac59\).
  4. \(|{+i}\rangle\) has \(\vec r=(0,1,0)\) and becomes \((0,0.4,0)\). \(|+\rangle\) has \(\vec r=(1,0,0)\) and is unchanged: it is an eigenvector of \(X\) (\(X|+\rangle=|+\rangle\)), so a bit flip does nothing to it.
  5. \(\vec r=(0,0,1)\), \(\vec s=(1,0,0)\): \(D=\tfrac12\sqrt2\approx0.707\), best success \(\tfrac12+\tfrac{\sqrt2}{4}\approx0.854\). (Measure along the bisector of the two Bloch vectors; this is the CHSH angle of Lecture 8 again.)
  6. Kraus operators \(|0\rangle\langle0|\) and \(|1\rangle\langle1|\) give \(\begin{pmatrix}\rho_{00}&0\\ 0&\rho_{11}\end{pmatrix}\). The phase flip with \(p=\tfrac12\) gives \(\tfrac12\rho+\tfrac12Z\rho Z\), and \(Z\rho Z\) negates the off-diagonal entries, so the average keeps the diagonal and kills the rest: the same matrix.

Reading and sources

all numbers and figures in these notes are computed in python (verify_L18.py) and follow the page theme