Welcome to pyMieDiff#
pyTorch implementation of Mie theory
pyMieDiff is a Mie scattering toolkit for layered spherical (nano-)particles in a homogeneous, isotropic environment.
The implementation is based on stable logarithmic derivative recurrences (following Peña and Pal, CPC 180, 2348 (2009)).
It is fully implemented in PyTorch. The outstanding feature compared to similar tools is the general support of torch’s automatic differentiation.
The source code is available on the github repository.
If you use pyMieDiff for your projects, please cite our paper (to be added):
Note
If you use pyMieDiff for your work, please cite our paper: (bibtex):
Oscar K. C. Jackson, Simone De Liberato, Otto L. Muskens, Peter R. Wiecha
PyMieDiff: A differentiable Mie scattering library
arXiv:2512.08614
download
Installation#
Install via pip:
$ pip install pymiediff
How to use#
Forward Mie evaluation:#
import torch
import pymiediff as pmd
# - setup the particle
mat_core = pmd.materials.MatDatabase("Si")
mat_shell = pmd.materials.MatDatabase("Ge")
p = pmd.Particle(
r_layers=[50.0, 80.0], # nm
mat_layers=[mat_core, mat_shell],
)
# - calculate efficiencies / cross section spectra
wl = torch.linspace(500, 1000, 50)
cs = p.get_cross_sections(k0=2 * torch.pi / wl)
plt.plot(cs["wavelength"], cs["q_ext"], label="$Q_{ext}$")
Autograd#
PyMieDiff fully supports native torch autograd:
# - gradient of scattering wrt wavelength
wl = torch.as_tensor(500.0)
wl.requires_grad = True
cs = p.get_cross_sections(k0=2 * torch.pi / wl)
cs["q_sca"].backward()
dQdWl = wl.grad
GPU support#
Simply pass the device argument to the particle class:
p = pmd.Particle(
r_layers=[50.0, 80.0], # nm
mat_layers=[mat_core, mat_shell],
device="cuda",
)
Note that GPU performance is heavily memory transfer bound, GPU starts to be of advantage only for several thousand concurrent vectorized evaluations.
Links#
documentation: https://uos-integrated-nanophotonics-group.github.io/MieDiff/index.html
github repository: https://github.com/UoS-Integrated-Nanophotonics-group/MieDiff
pyMieDiff documentation#
Contents: