Skip to content
Kartikey Purohit
← Course overview

Day 3 — Quantum Operations

Math Prep

Solve this BEFORE lesson.md. Day 3 is qiskit.quantum_info — the module that is the math. Everything here maps 1:1 onto a class you'll use: Pauli, SparsePauliOp, Statevector, Operator, DensityMatrix, partial_trace, state_fidelity.

Requires: Day 1–2 math prep. Video back-up: Watrous Lessons 01–02 and (deeper, optional) Lesson 09 Density Matrices; notes in resource-artifactory/notes/video-notes/.


1. Pauli algebra — the multiplication table

X2=Y2=Z2=I,XY=iZ,YZ=iX,ZX=iYX^2 = Y^2 = Z^2 = I,\qquad XY = iZ,\quad YZ = iX,\quad ZX = iY

Reversed order flips the sign: YX=−iZYX = -iZ, etc. So distinct Paulis anticommute: XY=−YXXY = -YX.

Every product of Paulis is again a Pauli times a phase from {±1,±i}\{\pm1, \pm i\} — that's why Pauli objects in Qiskit carry a phase and print things like -iY. Multi-qubit Paulis are tensor strings like Z⊗I⊗XZ\otimes I\otimes X = "ZIX" (little-endian trap: in the string "ZIX", the RIGHTMOST letter is qubit 0 — so X acts on q0, I on q1, Z on q2).

Commutation of Pauli strings: count the positions where the two strings differ and neither is I. Odd count ⇒ anticommute; even ⇒ commute. (Pauli.commutes does exactly this.)

2. Hermitian vs unitary — the two big families

Property Definition Role Qiskit
Hermitian A†=AA^\dagger = A observables; real eigenvalues SparsePauliOp, measurement operators
Unitary U†U=IU^\dagger U = I evolution/gates; eigenvalues eiφe^{i\varphi} on unit circle Operator, gates

Paulis are both (Hermitian AND unitary) — eigenvalues ±1\pm1. H is also both. S and T are unitary but NOT Hermitian (S†=S−1≠SS^\dagger = S^{-1} \ne S).

Eigen-facts to memorize (basis of measurement-in-a-basis questions):

Operator +1 eigenvector −1 eigenvector
ZZ ∥0⟩\|0\rangle ∥1⟩\|1\rangle
XX ∥+⟩\|+\rangle ∥−⟩\|-\rangle
YY ∥+i⟩=12(∥0⟩+i∥1⟩)\|{+i}\rangle = \tfrac{1}{\sqrt2}(\|0\rangle{+}i\|1\rangle) ∥−i⟩\|{-i}\rangle

3. Outer products and projectors

∣ψ⟩⟨ϕ∣|\psi\rangle\langle\phi| = column × row = a matrix. Key example:

∣0⟩⟨0∣=(1000),∣1⟩⟨1∣=(0001),Z=∣0⟩⟨0∣−∣1⟩⟨1∣|0\rangle\langle0| = \begin{pmatrix}1&0\\0&0\end{pmatrix},\quad |1\rangle\langle1| = \begin{pmatrix}0&0\\0&1\end{pmatrix},\quad Z = |0\rangle\langle0| - |1\rangle\langle1|

A projector satisfies Π2=Π=Π†\Pi^2 = \Pi = \Pi^\dagger. Measurement probability via projectors: P(x)=⟨ψ∣Πx∣ψ⟩P(x) = \langle\psi|\Pi_x|\psi\rangle — same Born rule, new clothes. Spectral theorem: every Hermitian A=∑jλjΠjA = \sum_j \lambda_j \Pi_j (eigenvalues × projectors), e.g. Z=(+1)∣0⟩⟨0∣+(−1)∣1⟩⟨1∣Z = (+1)|0\rangle\langle0| + (-1)|1\rangle\langle1|.

4. Expectation values — the number Estimator computes

⟨A⟩ψ=⟨ψ∣A∣ψ⟩=∑jλj P(outcome j)\langle A \rangle_\psi = \langle\psi|A|\psi\rangle = \sum_j \lambda_j \,P(\text{outcome } j)

Worked examples you should be able to do cold:

  • ⟨Z⟩∣0⟩=1\langle Z\rangle_{|0\rangle} = 1, ⟨Z⟩∣1⟩=−1\langle Z\rangle_{|1\rangle} = -1, ⟨Z⟩∣+⟩=0\langle Z\rangle_{|+\rangle} = 0, ⟨X⟩∣+⟩=1\langle X\rangle_{|+\rangle} = 1.
  • General 1-qubit state: ⟨Z⟩=∣α∣2−∣β∣2=P(0)−P(1)\langle Z\rangle = |\alpha|^2 - |\beta|^2 = P(0) - P(1). ⟨Z⟩ is just "probability difference."
  • Bell state ∣Φ+⟩|\Phi^+\rangle: ⟨Z⊗Z⟩=1\langle Z\otimes Z\rangle = 1 (outcomes always agree), ⟨Z⊗I⟩=0\langle Z \otimes I\rangle = 0 (each side alone is random), ⟨X⊗X⟩=1\langle X\otimes X\rangle = 1.

Linearity: ⟨2ZZ+3XI⟩=2⟨ZZ⟩+3⟨XI⟩\langle 2ZZ + 3XI\rangle = 2\langle ZZ\rangle + 3\langle XI\rangle — this is why SparsePauliOp Hamiltonians are evaluated term by term.

5. Density matrices — states as matrices

ρ=∣ψ⟩⟨ψ∣  (pure),ρ=∑kpk∣ψk⟩⟨ψk∣  (mixed)\rho = |\psi\rangle\langle\psi| \;\text{(pure)},\qquad \rho = \sum_k p_k |\psi_k\rangle\langle\psi_k| \;\text{(mixed)}

Properties: ρ†=ρ\rho^\dagger = \rho, ρ⪰0\rho \succeq 0, Tr(ρ)=1\mathrm{Tr}(\rho) = 1. Purity =Tr(ρ2)= \mathrm{Tr}(\rho^2): equals 1 iff pure; minimum 1/2n1/2^n for the maximally mixed state I/2nI/2^n.

  • ∣+⟩⟨+∣=12(1111)|+\rangle\langle+| = \tfrac12\begin{pmatrix}1&1\\1&1\end{pmatrix} — pure superposition: off-diagonals present (coherence).
  • 12I\tfrac12 I — 50/50 classical mixture: no off-diagonals, purity 12\tfrac12. Both give 50/50 Z-measurements; only ∣+⟩|+\rangle gives deterministic X-measurements. That's the entire pure-vs-mixed distinction.

Born rule and expectations in ρ-form: P(x)=Tr(Πxρ)P(x) = \mathrm{Tr}(\Pi_x \rho), ⟨A⟩=Tr(Aρ)\langle A\rangle = \mathrm{Tr}(A\rho).

6. Partial trace — the state of a subsystem

For ρAB\rho_{AB}, "trace out B" produces A's reduced state ρA=TrB(ρAB)\rho_A = \mathrm{Tr}_B(\rho_{AB}): keep the terms whose B-index matches in bra and ket, drop the rest.

The flagship fact: each qubit of a Bell state is maximally mixed:

TrB(∣Φ+⟩⟨Φ+∣)=12I\mathrm{Tr}_B\big(|\Phi^+\rangle\langle\Phi^+|\big) = \tfrac12 I

Entanglement of the pure whole ⇔ mixedness of the parts. (partial_trace(Statevector(bell), [0]) → DensityMatrix of 12I\tfrac12 I; purity 0.5.)

7. Fidelity — how close are two states

F(∣ψ⟩,∣ϕ⟩)=∣⟨ψ∣ϕ⟩∣2∈[0,1]F(|\psi\rangle, |\phi\rangle) = |\langle\psi|\phi\rangle|^2 \in [0,1]

(Qiskit's state_fidelity uses the squared-overlap convention: 1 = same state, 0 = orthogonal. Watrous's book uses the square root of this — beware when cross-reading.) Global phase drops out: F(∣ψ⟩,eiγ∣ψ⟩)=1F(|\psi\rangle, e^{i\gamma}|\psi\rangle) = 1. Example: F(∣0⟩,∣+⟩)=∣⟨0∣+⟩∣2=12F(|0\rangle, |+\rangle) = |\langle0|+\rangle|^2 = \tfrac12.


PROBLEMS

P1. Compute XZXZ and express it as a phase times a Pauli. Do XX and ZZ commute or anticommute?

P2. Do the Pauli strings "XX" and "ZZ" commute? "XI" and "ZZ"? (Use the differ-and-not-I counting rule.)

P3. Is TT Hermitian? Is it unitary? What are its eigenvalues?

P4. Write the projector onto ∣−⟩|-\rangle as a 2×2 matrix and verify Π2=Π\Pi^2 = \Pi.

P5. Compute ⟨X⟩\langle X\rangle for ∣ψ⟩=cos⁡θ2∣0⟩+sin⁡θ2∣1⟩|\psi\rangle = \cos\frac{\theta}{2}|0\rangle + \sin\frac{\theta}{2}|1\rangle (real amplitudes).

P6. For the Bell state ∣Φ+⟩|\Phi^+\rangle, compute ⟨Z⊗Z⟩\langle Z\otimes Z\rangle and ⟨Z⊗I⟩\langle Z\otimes I\rangle from the outcome probabilities.

P7. Write ρ\rho for the classical mixture "70% ∣0⟩|0\rangle, 30% ∣1⟩|1\rangle" and for the pure state 0.7∣0⟩+0.3∣1⟩\sqrt{0.7}|0\rangle + \sqrt{0.3}|1\rangle. Which matrix entries differ? Compute both purities.

P8. Show Trq0(∣Φ+⟩⟨Φ+∣)=12I\mathrm{Tr}_{q_0}(|\Phi^+\rangle\langle\Phi^+|) = \tfrac12 I by expanding ∣Φ+⟩⟨Φ+∣|\Phi^+\rangle\langle\Phi^+| and applying the keep-matching-B-indices rule.

P9. Compute state_fidelity between ∣+⟩|+\rangle and ∣+i⟩=12(∣0⟩+i∣1⟩)|{+i}\rangle = \tfrac{1}{\sqrt2}(|0\rangle + i|1\rangle).

P10. The exam asks: "Which is true of ρ=I/2\rho = I/2?" — (a) it's a pure superposition, (b) measuring in ANY basis gives 50/50, (c) it equals ∣+⟩⟨+∣|+\rangle\langle+|. Pick and justify.


ANSWERS

A1. XZ=(0−110)=−iYXZ = \begin{pmatrix}0&-1\\1&0\end{pmatrix} = -iY. And ZX=iY≠XZZX = iY \ne XZ ⇒ they anticommute (XZ=−ZXXZ = -ZX).

A2. "XX" vs "ZZ": differ at 2 positions ⇒ even ⇒ commute (both are symmetries of the Bell basis). "XI" vs "ZZ": differ at 1 non-identity position ⇒ odd ⇒ anticommute.

A3. T†=diag(1,e−iπ/4)≠TT^\dagger = \mathrm{diag}(1, e^{-i\pi/4}) \ne T ⇒ not Hermitian. T†T=IT^\dagger T = I ⇒ unitary. Eigenvalues: 11 and eiπ/4e^{i\pi/4} (it's diagonal).

A4. ∣−⟩⟨−∣=12(1−1−11)|-\rangle\langle-| = \tfrac12\begin{pmatrix}1&-1\\-1&1\end{pmatrix}. Squaring gives 12(1−1−11)\tfrac12\begin{pmatrix}1&-1\\-1&1\end{pmatrix} again. ✓

A5. ⟨ψ∣X∣ψ⟩=2cos⁡θ2sin⁡θ2=sin⁡θ\langle\psi|X|\psi\rangle = 2\cos\frac{\theta}{2}\sin\frac{\theta}{2} = \sin\theta. Sanity check at θ=π/2\theta=\pi/2: the state is ∣+⟩|+\rangle... no — at θ=π/2\theta = \pi/2 the state is cos⁡π4∣0⟩+sin⁡π4∣1⟩=∣+⟩\cos\frac{\pi}{4}|0\rangle + \sin\frac{\pi}{4}|1\rangle = |+\rangle and sin⁡(π/2)=1=⟨X⟩∣+⟩\sin(\pi/2) = 1 = \langle X\rangle_{|+\rangle}. ✓

A6. ZZZZ outcomes: ∣00⟩,∣11⟩|00\rangle, |11\rangle each prob 12\tfrac12, bits always equal ⇒ eigenvalue +1+1 always ⇒ ⟨ZZ⟩=1\langle ZZ\rangle = 1. Single qubit is uniformly random ⇒ ⟨Z⊗I⟩=12(+1)+12(−1)=0\langle Z\otimes I\rangle = \tfrac12(+1)+\tfrac12(-1) = 0.

A7. ρmix=(0.7000.3)\rho_{\text{mix}} = \begin{pmatrix}0.7&0\\0&0.3\end{pmatrix}; ρpure=(0.70.210.210.3)\rho_{\text{pure}} = \begin{pmatrix}0.7&\sqrt{0.21}\\\sqrt{0.21}&0.3\end{pmatrix}. Difference: the off-diagonal coherences (0.21≈0.458\sqrt{0.21}\approx0.458). Purities: mix 0.49+0.09=0.580.49+0.09 = 0.58; pure =1= 1 (check: 0.49+0.09+2⋅0.21=10.49+0.09+2\cdot0.21 = 1 ✓).

A8. ∣Φ+⟩⟨Φ+∣=12(∣00⟩⟨00∣+∣00⟩⟨11∣+∣11⟩⟨00∣+∣11⟩⟨11∣)|\Phi^+\rangle\langle\Phi^+| = \tfrac12(|00\rangle\langle00| + |00\rangle\langle11| + |11\rangle\langle00| + |11\rangle\langle11|). Tracing out q0 kills the cross terms (q0 bra ≠ q0 ket) and leaves 12(∣0⟩⟨0∣+∣1⟩⟨1∣)=12I\tfrac12(|0\rangle\langle0| + |1\rangle\langle1|) = \tfrac12 I on q1. ∎

A9. ⟨+∣+i⟩=12(1+i)\langle+|{+i}\rangle = \tfrac12(1 + i), so F=∣1+i2∣2=24=12F = \left|\tfrac{1+i}{2}\right|^2 = \tfrac{2}{4} = \tfrac12.

A10. (b). P(x)=Tr(ΠxI2)=12P(x) = \mathrm{Tr}(\Pi_x \tfrac{I}{2}) = \tfrac12 for any rank-1 projector, in every basis. (a),(c) false: I/2I/2 has purity 12\tfrac12 (mixed); ∣+⟩⟨+∣|+\rangle\langle+| has off-diagonals.


Self-check: you can multiply any two Paulis with the right phase, compute ⟨Pauli⟩ for the standard states instantly, tell pure from mixed by looking at a density matrix, and state why a Bell state's reduced state is I/2I/2.