Zuhal Karadavut
Theme

Simulation, numerics and systems

differentiable-optics

Can I write a wave-optics simulator in JAX that is right to round-off, and is its gradient worth having?

Answer

Yes to both, while the sampling conditions hold. Against the exact Gaussian beam the propagator is off by at most 8.43e-16 in float64 (relative L2 error). Designing a top-hat phase mask with jax.grad brings the RMS error inside the target to 0.0735, against 0.196 for Gerchberg-Saxton (medians over 10 starts, lower in 10 of 10). Gerchberg-Saxton still puts slightly more light into the target, 95.2 % against 93.1 %.

Top-hat design: RMS error inside the target, median over the starts (RMS error)
jax.grad (Adam)0.0735results/design.jsonGerchberg-Saxton0.196results/design.json

How it was measured

  • The angular spectrum method propagates a scalar field through free space; a split-step method handles a graded-index medium. Each part is checked against an exact answer.
  • The Gaussian-beam formula is itself only paraxial, so for the exact propagator I derived the first correction and checked it by quadrature in two different variables.
  • Where the sampling window is too small, the error equals what the periodic FFT predicts, so the failures are understood, not just observed.
  • The design runs both methods from the same random starts on the same targets, and pairs them per start.

Proof

Every file is pinned to the commit the numbers come from, so the links cannot drift.

Reproduce it

pip install -r requirements-dev.txt
python -m scripts.run_verification
python -m scripts.run_design
python scripts/make_tables.py

CI recomputes every case on each push and fails if the README and the result files disagree.

The repository on GitHub

Limits

  • Scalar, monochromatic waves only, with an ideal phase-only mask. No polarisation.
  • Gradient descent optimises the reported metrics directly and Gerchberg-Saxton does not, so the RMS comparison favours gradient descent by construction. The loss weights were fixed before the run.
  • CPU only. GPU throughput was not measured.

Built with

  • Python
  • JAX
  • NumPy
  • SciPy
  • Fourier optics