---
title: Quantum dynamics lab
heading: Relaxation, Ramsey fringes, Landau–Zener sweeps, golden-rule decay and Bell correlations, simulated
eyebrow: B10 · Lesson 47 · Quantum dynamics lab
xp: 50
---

::: hook
Lessons 26 to 44 gave formulas for how quantum systems change: Bloch-vector relaxation with $T_1$ and $T_2$, Ramsey fringes, the Landau–Zener jump, the golden rule's exponential decay, and the singlet's correlations. Each formula rests on assumptions, such as an infinitely long sweep or a perfectly flat continuum. In this lab you'll simulate each process directly and see the formulas emerge, and where they bend: a decay that isn't exponential at first, a sweep that hasn't finished. Units are ħ = 1.
:::

::: play
- A Ramsey experiment: two π/2 pulses separated by a wait T, with the drive detuned by Δ. The curve is the population of the upper state against T, with fringes fading as the coherence decays with time $T_2$.
- Raise the detuning: the fringes crowd together, one per $\frac{2\pi}{\Delta}$. Shorten $T_2$: they fade sooner.
- The readout gives the fringe period. Step 2 simulates the pulses and the wait with matrices.
:::

```sim plot
view: graph
x: T = 0..20
y: P = 0..1
slider: D = 0.2..3 step 0.1 = 1
slider: T2 = 2..50 step 1 = 10
plot: 0.5*(1 + cos(D*T)*exp(-T/T2)) | label: upper-state population | samples: 800
readout: fringe period = 2*pi/D | digits: 4
```

::: predict
## A level decays into a broad continuum at rate Γ by the golden rule. Is its survival probability exactly $e^{-\Gamma t}$ from the start?

- [ ] Yes, at all times
- [x] No: at very short times it falls more slowly, quadratically, before settling into the exponential
- [ ] No: it falls linearly forever
- [ ] It doesn't decay at all

::: reveal
No. At the very start the amplitude leaks out as $1 - \frac{(Vt)^2}{2}$ or so, quadratically, because it takes time for the population to explore the continuum. Only after a time comparable to the inverse of the continuum's width does the decay settle into the golden rule's exponential. That early stage is what the quantum Zeno effect of lesson 16 exploits.
:::
:::

::: nameit
## What to simulate

- **Relaxation:** the Bloch equations $\dot r_{x,y} = -\frac{r_{x,y}}{T_2}$ and $\dot r_z = -\frac{r_z - 1}{T_1}$ (with $r_z$ = +1 the ground state), stepped in time.
- **Ramsey:** a π/2 rotation about x, free precession $e^{-i\Delta\sigma_zT/2}$, and another π/2 rotation; the upper population is $\cos^2\frac{\Delta T}{2}$ for ideal pulses.
- **Landau–Zener:** $H = \begin{pmatrix} vt/2 & V \\ V & -vt/2 \end{pmatrix}$ stepped with the exact propagator of each short interval, $\cos\omega\Delta t - i\frac{\sin\omega\Delta t}{\omega}H$ with $\omega = \sqrt{(vt/2)^2 + V^2}$.
- **Golden rule:** one level coupled by V to M levels spaced δ, diagonalized exactly; the survival probability approaches $e^{-\Gamma t}$ with $\Gamma = \frac{2\pi V^2}{\delta}$.
- **Bell correlations:** $E(a, b) = -\cos(a - b)$ for the singlet, combined into $S = |E(a_1, b_1) - E(a_1, b_2) + E(a_2, b_1) + E(a_2, b_2)|$.

## The exact two-level propagator

For any Hamiltonian of the form $\begin{pmatrix} a & V \\ V & -a \end{pmatrix}$, $e^{-iH\Delta t} = \cos\omega\Delta t\,I - i\frac{\sin\omega\Delta t}{\omega}H$ with $\omega = \sqrt{a^2 + V^2}$. Using it for each short step, with H evaluated at the step's middle, is far faster than calling a general matrix exponential.
:::

::: example
## A qubit with $T_1$ = 50 and $T_2$ = 30 starts on the equator of the Bloch sphere. What do the Bloch equations give at t = 20?

::: solution
1. **Horizontal component.** It decays as
   $$e^{-20/30} = 0.513$$
2. **Vertical component.** $r_z$ climbs from 0 toward 1 as
   $$1 - e^{-20/50} = 0.330$$
3. **Compare with the simulation.** Stepping the equations with Δt = 0.001 gives 0.51341 and 0.32968, matching to four digits.
4. **The path.** The vector shrinks and swings toward the north pole along a curve, not a straight line, because its two parts decay at different rates.

**Answer:** at t = 20 the horizontal component is 0.513 and $r_z$ is 0.330.
:::
:::

::: example
## A Landau–Zener sweep has V = 0.5 and v = 1. What jump probability does a simulation from t = −300 to 300 give, compared with the formula?

::: solution
1. **The formula.**
   $$\begin{aligned} P &= e^{-2\pi V^2/v} \\ &= e^{-\pi/2} \\ &= 0.208 \end{aligned}$$
2. **The simulation.** With the exact propagator over steps of 0.002, it gives 0.205.
3. **Where the difference comes from.** The difference of about 1.5% is the sweep's finite length: the populations keep oscillating slightly, decaying as $\frac1t$, long after the crossing. Running longer shrinks it, which is how you tell a truncation error from a mistake.

**Answer:** the simulation gives 0.205, against 0.208 from the formula.
:::
:::

::: example
## One level couples with V = 0.02 to 801 levels spaced 0.01 apart. How does its survival compare with the golden rule at t = 2 and t = 5?

::: solution
1. **Golden-rule rate.**
   $$\begin{aligned} \Gamma &= \frac{2\pi V^2}{\delta} \\ &= 0.251 \end{aligned}$$
2. **At t = 5.** The exact survival is 0.290, against $e^{-\Gamma t} = 0.285$.
3. **At t = 2.** It's 0.627 against 0.605.
4. **Why early times differ.** The early survival is higher because the decay starts quadratically; the exponential takes over once the level has had time to resolve the continuum's structure.
5. **Very long times.** Both numbers would drift further when the population returns from the finite set of levels, after about $\frac{2\pi}{\delta} = 630$.

**Answer:** the survival is 0.627 at t = 2 and 0.290 at t = 5, against the golden rule's 0.605 and 0.285.
:::
:::

::: check
kind: python

## Step 1. Write `bloch(T1, T2, t, dt)` that steps the Bloch equations by Euler's method from $\mathbf r$ = (1, 0, 0) and returns $(r_x, r_z)$ at time t.

```python starter
import numpy as np

def bloch(T1, T2, t, dt):
    return 1.0, 0.0

print(bloch(50, 30, 20, 1e-3))
```

```python solution
import numpy as np

def bloch(T1, T2, t, dt):
    rx, rz = 1.0, 0.0
    for _ in range(int(round(t / dt))):
        rx, rz = rx - dt * rx / T2, rz - dt * (rz - 1) / T1
    return rx, rz

print(bloch(50, 30, 20, 1e-3))
```

```python tests
import numpy as np
rx, rz = bloch(50, 30, 20, 1e-3)
assert abs(rx - np.exp(-20 / 30)) < 1e-4 and abs(rz - (1 - np.exp(-20 / 50))) < 1e-4, f"Expect 0.5134 and 0.3297; got {rx:.5f}, {rz:.5f}."
```

::: right
Right. Each component relaxes on its own clock, $T_2$ for coherence and $T_1$ for population.
:::
:::

::: check
kind: python

## Step 2. Write `ramsey(D, T)` that applies a π/2 rotation about x, free precession $\text{diag}(e^{-iDT/2}, e^{iDT/2})$, and another π/2 rotation to the state (1, 0), returning the upper population.

```python starter
import numpy as np

def ramsey(D, T):
    return 0.5

print(ramsey(2 * np.pi * 0.1, 2.0))
```

```python solution
import numpy as np

def ramsey(D, T):
    def Rx(th):
        return np.array([[np.cos(th / 2), -1j * np.sin(th / 2)], [-1j * np.sin(th / 2), np.cos(th / 2)]])
    U = np.diag([np.exp(-0.5j * D * T), np.exp(0.5j * D * T)])
    psi = Rx(np.pi / 2) @ U @ Rx(np.pi / 2) @ np.array([1, 0])
    return float(abs(psi[1])**2)

print(ramsey(2 * np.pi * 0.1, 2.0))
```

```python tests
import numpy as np
for D, T in ((2 * np.pi * 0.1, 2.0), (1.3, 0.7), (0.0, 5.0)):
    assert abs(ramsey(D, T) - np.cos(D * T / 2)**2) < 1e-12, f"For D = {D:.3f}, T = {T}: expect cos²(DT/2) = {np.cos(D * T / 2)**2:.6f}."
```

::: right
Right. With no detuning the two π/2 pulses add to a full π flip; detuning makes the population oscillate with the wait.
:::
:::

::: check
kind: python

## Step 3. Write `lz_sim(V, v, T, dt)` that steps the Landau–Zener Hamiltonian from −T to T with the exact two-level propagator at each step's midpoint, starting in the first diabatic state, and returns the probability of still being in it.

```python starter
import numpy as np

def lz_sim(V, v, T, dt):
    return 0.5

print(lz_sim(0.5, 1.0, 300.0, 0.002))
```

```python solution
import numpy as np

def lz_sim(V, v, T, dt):
    psi = np.array([1, 0], dtype=complex)
    n = int(round(2 * T / dt))
    for i in range(n):
        a = v * (-T + (i + 0.5) * dt) / 2
        w = np.sqrt(a * a + V * V)
        c, s = np.cos(w * dt), np.sin(w * dt) / w
        U = np.array([[c - 1j * s * a, -1j * s * V], [-1j * s * V, c + 1j * s * a]])
        psi = U @ psi
    return float(abs(psi[0])**2)

print(lz_sim(0.5, 1.0, 300.0, 0.002))
```

```python tests
import numpy as np
p = lz_sim(0.5, 1.0, 300.0, 0.002)
assert abs(p - np.exp(-np.pi / 2)) < 0.01, f"Expect close to e^(-π/2) = 0.2079; got {p:.4f}."
q = lz_sim(0.1, 1.0, 300.0, 0.002)
assert abs(q - np.exp(-2 * np.pi * 0.01)) < 0.01, "A weak coupling lets most of the state jump."
```

::: right
Right. The simulation lands within about 1% of the formula, the remainder being the finite sweep's slowly decaying wiggles.
:::
:::

::: check
kind: python

## Step 4. Write `golden(V, delta, M, t)` that builds one level coupled by V to M levels at energies $(j - M//2)\delta$, diagonalizes it, and returns the first level's survival probability at time t.

```python starter
import numpy as np

def golden(V, delta, M, t):
    return np.exp(-2 * np.pi * V * V / delta * t)

print(golden(0.02, 0.01, 801, 5.0))
```

```python solution
import numpy as np

def golden(V, delta, M, t):
    E = (np.arange(M) - M // 2) * delta
    H = np.zeros((M + 1, M + 1))
    H[1:, 1:] = np.diag(E)
    H[0, 1:] = V
    H[1:, 0] = V
    w, vecs = np.linalg.eigh(H)
    c = vecs[0, :]
    return float(abs(np.sum(np.abs(c)**2 * np.exp(-1j * w * t)))**2)

print(golden(0.02, 0.01, 801, 5.0))
```

```python tests
import numpy as np
s = golden(0.02, 0.01, 801, 5.0)
G = 2 * np.pi * 0.02**2 / 0.01
assert abs(s - 0.28987) < 1e-3, f"The exact survival at t = 5 is 0.2899; got {s:.5f}."
assert abs(s - np.exp(-G * 5)) < 0.01, "It should be within 0.01 of the golden rule's e^(-Γt) = 0.2846."
```

::: right
Right. The golden rule describes the decay well once it's under way; the early quadratic start is what's left over.
:::
:::

::: check
kind: python

## Step 5. Write `chsh(a1, a2, b1, b2)` for the singlet ($E = -\cos(a - b)$) and `best_chsh()` that searches Alice's second angle a2 and Bob's angles b1, b2 over a grid of 90 values each from 0 to π (Alice's first angle fixed at 0) and returns the largest S.

```python starter
import numpy as np

def chsh(a1, a2, b1, b2):
    return 2.0

def best_chsh():
    return 2.0

print(best_chsh())
```

```python solution
import numpy as np

def chsh(a1, a2, b1, b2):
    E = lambda a, b: -np.cos(a - b)
    return abs(E(a1, b1) - E(a1, b2) + E(a2, b1) + E(a2, b2))

def best_chsh():
    g = np.linspace(0, np.pi, 90, endpoint=False)
    A2, B1, B2 = np.meshgrid(g, g, g, indexing='ij')
    return float(np.max(chsh(0.0, A2, B1, B2)))

print(best_chsh())
```

```python tests
import numpy as np
assert abs(chsh(0, np.pi / 2, np.pi / 4, 3 * np.pi / 4) - 2 * np.sqrt(2)) < 1e-12, "The standard angles give 2√2."
b = best_chsh()
assert 2.82 < b <= 2 * np.sqrt(2) + 1e-12, f"No angles beat 2√2 = 2.828; the search should find it; got {b:.5f}."
```

::: right
Right. The search confirms Tsirelson's bound: quantum correlations reach 2√2 and no further, while local hidden variables stop at 2.
:::
:::

::: check
given: D = 0.5 | 2 | 6.28
answer: 2*pi/D
tolerance: 0.5%

## A Ramsey experiment is detuned by Δ = {D} rad per unit time. How far apart are its fringes in wait time?

::: right
Right. One fringe per $\frac{2\pi}{\Delta}$.
:::

::: misses
- [pi/D] The population $\cos^2\frac{\Delta T}{2}$ repeats every $\frac{2\pi}{\Delta}$.
- [any] The phase must advance by 2π.
:::
:::

::: check
given: V = 0.01 | 0.05; d = 0.001 | 0.01
answer: 2*pi*V^2/d
tolerance: 0.5%

## A level couples with V = {V} to a continuum of levels spaced {d} apart (ħ = 1). What is its golden-rule decay rate?

::: right
Right. $\Gamma = 2\pi|V|^2\rho$ with $\rho = \frac1\delta$.
:::

::: misses
- [2*pi*V/d] The rate goes as $V^2$.
- [any] $\Gamma = \frac{2\pi V^2}{\delta}$.
:::
:::

::: explain
## Why does a decaying level's survival fall quadratically at first, before the golden rule's exponential takes over?

::: model
At the very start, the level's amplitude has only just begun leaking into the continuum, and every final state receives a little amplitude growing in proportion to time, all in step. The probability lost is the square of that amplitude, so it grows as $t^2$. As time goes on, the final states with different energies drift out of phase with the initial level at different rates, and only those within a narrow energy window, of width about $\frac\hbar t$, keep receiving amplitude coherently. That narrowing window turns the quadratic growth into a steady rate, proportional to the density of states at the right energy: the golden rule. The crossover happens after a time of order $\hbar$ divided by the continuum's width.
:::
:::

::: practice

::: check
given: T1 = 20 | 100; t = 5 | 50
answer: 1 - exp(-t/T1)
tolerance: 0.5%

## Starting on the equator, how far up toward the ground state has a Bloch vector relaxed after {t} with $T_1$ = {T1}?

::: misses
- [any] $r_z = 1 - e^{-t/T_1}$.
:::
:::

::: check
given: V = 0.2 | 0.5; v = 0.5 | 2
answer: exp(-2*pi*V^2/v)
tolerance: 0.5%

## Landau–Zener jump probability for V = {V} and sweep rate v = {v} (ħ = 1)?

::: misses
- [any] $e^{-2\pi V^2/v}$.
:::
:::
:::
