_images/pymiediff_logo-dark.png _images/pymiediff_logo-light.png

Welcome to pyMieDiff#

pyTorch implementation of Mie theory

pyMieDiff is a Mie scattering toolkit for spherical core-shell (nano-)particles in a homogeneous, isotropic environment. It is implemented in PyTorch. The outstanding feature compared to similar tools is the general support of torch’s automatic differentiation.

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):

AUTHORS
TITLE
JOURNAL REF.

DOI: XXX, arXiv:XXX
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_core=50.0,  # nm
    r_shell=70.0,  # nm
    mat_core=mat_core,
    mat_shell=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_core=50.0,  # nm
    r_shell=70.0,  # nm
    mat_core=mat_core,
    mat_shell=mat_shell,
    device="cuda",
)

pyMieDiff documentation#