B1018 of 55
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

B10 · Lesson 18 · Matrix mechanics lab

Spin operators, measurement, precession and Rabi oscillation as matrices in code

Lessons 15 to 17 put quantum mechanics in the language of vectors and operators. For a spin or a qubit the vectors have just two components and the operators are 2 × 2 matrices, so everything can be computed exactly with a few lines of NumPy: commutators, the probabilities of measuring along any axis, time evolution by a matrix exponential, and the Rabi oscillation that drives every qubit gate. In this lab you'll build those tools and check each against the formulas, then use the same machinery on a chain of coupled wells. Units are those where ħ = 1.

  • A two-level system is driven with Rabi frequency Ω and detuning Δ. The curve is the population of the upper level against time, from Rabi's formula.
  • On resonance the population swings fully between 0 and 1; off resonance it swings faster and never fully flips.
  • Step 4 reproduces this curve by exponentiating the 2 × 2 Hamiltonian, with no formula at all.

Predict

A spin points up along z and is measured along an axis tilted 60° toward x. What is the chance of getting "up" along that axis?

Name it

Spin as matrices

With ħ = 1, Si=12σi with the Pauli matrices

σx=(0110),σy=(0−ii0),σz=(100−1),

which obey [Sx,Sy]=iSz and its cyclic versions.

Measurement

The spin along a unit vector n is 𝐧⋅𝐒. Its eigenvectors are the possible outcomes, and the chance of each is the squared size of the state's overlap with it: np.linalg.eigh gives both eigenvalues and eigenvectors.

Time evolution

For a time-independent Hamiltonian, |ψ(t)⟩=e−iHt|ψ(0)⟩. With H=Vdiag(w)V† from eigh, e−iHt=Vdiag(e−iwt)V†. A spin in a field along z, H=ωSz, precesses about z at ω.

Rabi oscillation

In the frame rotating with the drive, a two-level system with Rabi frequency Ω and detuning Δ has H=12(ΔΩΩ−Δ), and exponentiating it reproduces Rabi's formula, P=Ω2Ω2+Δ2sin2⁡Ω2+Δ2t2.

Larger matrices

The same code handles N coupled wells: the tight-binding matrix with −t beside the diagonal has eigenvalues −2tcos⁡jπN+1, the beginnings of a band.

Worked example

A spin-½ points along +x and sits in a field that makes it precess about z at 1 cycle per unit time. What is ⟨S_x⟩ after a quarter and a half cycle?

Show the solution
  1. Evolve the state. With H=2πSz, evolve the state 12(1,1) by the matrix exponential.
  2. Read off ⟨S_x⟩. It's 0.5 at t = 0, 0 at t = 0.25 (the spin points along y) and −0.5 at t = 0.5.
  3. Compare with a classical moment. The expectation values precess exactly like a classical magnetic moment, which is Ehrenfest's theorem for spin: the averages obey the classical equations even though each measurement gives only ±½.

Answer ⟨S_x⟩ is 0 after a quarter cycle and −0.5 after a half cycle.

Worked example

A qubit is driven with Ω = Δ = 2π × 1 (frequencies in cycles per unit time). What is its upper population at t = 0.3, and what's the most it ever reaches?

Show the solution
  1. Exponentiate the Hamiltonian. Exponentiate this for t = 0.3, apply it to the state, and square the second component: H=12(ΔΩΩ−Δ) That gives 0.4722.
  2. Check with Rabi's formula. P=12sin2⁡(2×2π×0.32)=0.4722
  3. The most it reaches. With equal detuning and drive, the population never exceeds ½. Detuning tilts the rotation axis on the Bloch sphere away from the equator, so the state circles without reaching the south pole.

Answer the upper population is 0.4722 at t = 0.3, and it never exceeds ½.

Worked example

Eight identical wells in a row are coupled to their neighbors by t = 1. What are the lowest three levels?

Show the solution
  1. The levels. The matrix with −1 beside the diagonal has eigenvalues −2cos⁡jπ9 which are −1.879, −1.532 and −1.000 for j = 1, 2, 3.
  2. Check numerically. eigvalsh reproduces them to rounding.
  3. The band. All eight levels lie between −2 and +2, the band of width 4t of lesson 31. With more wells the levels fill the band densely: a crystal's band is the limit of this matrix as N grows.

Answer the lowest three levels are −1.879, −1.532 and −1.000.

Check

Step 1. Write spin_ops() returning the three spin matrices Sx,Sy,Sz (ħ = 1), and commutator(A, B).

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Check

Step 2. Write prob_up(state, n) returning the chance that a spin in state (a 2-component array) is found "up" along the unit vector n, using the eigenvectors of 𝐧⋅𝐒. spin_ops is included.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Check

Step 3. Write evolve(H, psi, t) returning e−iHtψ through the eigendecomposition of the Hermitian matrix H, and sx_mean(psi) returning ⟨S_x⟩. spin_ops is included.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Check

Step 4. Write rabi_numeric(W, D, t) that exponentiates the rotating-frame Hamiltonian 12(DWW−D) (W and D in rad per unit time) from the state (1, 0) and returns the upper population. evolve is included.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Check

Step 5. Write chain_levels(n, t) returning the sorted eigenvalues of n identical wells coupled to neighbors by t, the matrix with −t beside the diagonal.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Check

A spin up along z is measured along an axis tilted 60°. What is the chance of "up"?

Check

A two-level system is driven with Rabi frequency 1 and detuning 0.5 (same units). What is the largest upper population it reaches?

Explain why

Why does computing e−iHt through the eigenvectors of H give the exact time evolution?

Practice

Keep practicing

4 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.