Stern-Gerlach Numerical Simulation

A numerical solver for the Stern-Gerlach experiment, simulating the quantum spin-dependent splitting of an electron wavepacket in an inhomogeneous magnetic field.

Animated simulation showing an electron wavepacket splitting into spin-up and spin-down components as it passes through an inhomogeneous magnetic field
Probability density of a spinor wavepacket propagating through an inhomogeneous magnetic field. The wavepacket splits into spin-up and spin-down components along the field gradient direction.

Method

The simulation uses a split-operator Fourier method to evolve a two-component spinor wavefunction on a 200×200 spatial grid. A Gaussian wavepacket is initialized in an equal superposition of spin-up and spin-down states and propagated through a magnetic field with a strong gradient in the transverse direction.

Key simulation parameters:

  • Grid: 200 × 200 points at 1 nm resolution
  • Time step: 0.4 fs (2800 total steps)
  • Base field: 1.5 T with a gradient of 8 × 109 T/m
  • Wavepacket spread: 5 nm (Gaussian σ)

At each time step, the potential energy operator (incorporating the Zeeman interaction via the Pauli σz matrix) is applied in position space, and the kinetic energy operator is applied in momentum space via FFT. The spin-dependent force from the magnetic field gradient causes the two spin components to separate spatially over time — the hallmark of the Stern-Gerlach effect.

Implementation

The solver is implemented in Python using PyTorch for tensor operations and Matplotlib for visualization. The simulation was generated through a dialog with OpenAI's o1 model. The original chat transcript is available here. The code can be found on my GitHub repo below.