Skip to content

DiffTMM

DiffTMM is a differentiable Transfer Matrix Method (TMM) solver for multi-layer thin films, built on PyTorch. It models how light reflects and transmits through a stack of optical coatings — and because the whole calculation is differentiable, you can run gradient-based inverse design to recover layer thicknesses or optimize a coating for a target spectral response.

DiffTMM supports two main use cases:

  • Forward simulation — compute the Fresnel coefficients (ts, tp, rs, rp) of a film stack across angle and wavelength, on GPU and in batch.
  • Inverse design — optimize layer thicknesses (and stack geometry) end-to-end with PyTorch autograd to match measured or target optical properties.

DiffTMM computes the Fresnel coefficients of a multi-layer thin-film stack in a fully differentiable manner:

Incident angle, wavelength → [ DiffTMM ] → Fresnel coefficients (ts, tp, rs, rp)

Why DiffTMM

The transfer matrix method is the standard tool for multi-layer thin-film optics, but classic implementations are CPU-only and non-differentiable. DiffTMM reimplements TMM in PyTorch so the entire pipeline is GPU-accelerated, batched, and autograd-friendly.

Feature NumPy TMM DiffTMM
Differentiable (autograd) No Yes
GPU acceleration No (CPU only) Yes (CUDA)
Batch processing No (sequential) Yes (vectorized)
Anisotropic materials No Yes (4×4 transfer matrix)
Speed (batch = 16) 1× baseline ~190× (isotropic 2×2), ~134× (anisotropic 4×4)

Benchmarks are measured against the reference NumPy library sbyrnes321/tmm, which DiffTMM also uses to validate accuracy — see the Benchmarks page.

Solvers

DiffTMM ships three solvers that share the same Solver(...).simulate(theta, wvln) interface:

Solver Method Use it for
IsotropicFilmSolver 2×2 transfer matrix Isotropic stacks — fastest path (~190×)
FilmSolver (alias AnisotropicFilmSolver) 4×4 transfer matrix Anisotropic / birefringent media (also handles isotropic)
IncoherentIsotropicFilmSolver 2×2 + incoherent layers Stacks with thick substrates (≫ coherence length)

Refractive indices can be plain numbers, complex values (with loss), or real material names ("N-BK7", "SiO2", "Ag", …) resolved to wavelength-dependent dispersion from bundled catalogs.

See the Citation page for how to cite DiffTMM.

Getting Started

  • Setup


    Install DiffTMM and run your first thin-film simulation.

    Set up DiffTMM

  • Quickstart


    Forward simulation and inverse design in a few lines of code.

    Get started

  • Architecture


    How the solvers, functional core, and materials fit together.

    Understand the design

  • API Reference


    Full class and function documentation for the solvers and materials.

    Browse the API

  • Examples


    Forward simulation, inverse design, real materials, and benchmarks.

    See examples