Skip to main content

pymiediff logo

pyMieDiff

pyTorch implementation of Mie theory

pyMieDiff is a Mie scattering toolkit for layered spherical (nano-)particles in a homogeneous, isotropic environment. It is a pure PyTorch implementation of stable, logarithmic derivative based Mie series (following Peña and Pal, CPC 180, 2348 (2009)). The outstanding feature, compared to similar tools, is the general support of torch's automatic differentiation, fully vectorization and full GPU compatibility.

The source code is available on the github repository. For details, please see the online documentation.

If you use pyMieDiff for your projects, please cite our paper (arxiv:2512.08614).

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

Installing / Requirements

pip install pymiediff

pymiediff is tested under linux and windows with python versions 3.10 to 3.13. It requires following python packages

  • pytorch (v2.0+)
  • scipy (v1.9+)

Optional dependencies:

  • matplotlib (plotting)
  • pyyaml (tabulated permittivity data from refractiveindex.info)

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.

Features

List of features

  • multilayer spherical particles
  • scattering and extinction cross sections
  • angular scattering
  • scattered and internal near-fields
  • pure python / pytorch
  • full support of torch's automatic differentiation
  • GPU support
  • fully vectorized

Package Layout

Main package incudes

  • Particle class:
    • definition of multi-shell particles and high-level interface to main functionalities
  • multishell submodule:
    • Mie coefficients and observables for multishell particles.
  • special submodule:
    • Contains PyTorch compatible Spherical Bessel and Hankel functions and angular functions pi and tau.
  • materials subpackage:
    • PyTorch compatible materials classes for permittivity interpolation, based on the refractiveindex.info yaml format.

Contributing

If you'd like to contribute, please fork the repository and use a feature branch. Pull requests are warmly welcome.

Licensing

The code in this project is licensed under the GNU GPLv3.

Metadata

Release files for pymiediff 0.13

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pymiediff 0.13
File Size Uploaded Provenance Actions
pymiediff-0.13.tar.gz 126.6 kB Without provenance Details for pymiediff-0.13.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pymiediff 0.13
File Interpreter ABI Platform Actions
pymiediff-0.13-py3-none-any.whl Python 3 none any Details for pymiediff-0.13-py3-none-any.whl

Total release size: 232.7 kB

Release files / pymiediff-0.13.tar.gz

Download URL pymiediff-0.13.tar.gz
Size 126.6 kB
Tags Source
SHA-256 checksum
How to use checksums
7f5db516abd2760436daf4e61971dab708961426f426f29d846dafe2c0385723
BLAKE2b-256 checksum
How to use checksums
7584125ea21d84064cf7e316206b4ea76a231752794066692455c9dc93a0e6d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3

Release files / pymiediff-0.13-py3-none-any.whl

Download URL pymiediff-0.13-py3-none-any.whl
Size 106.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7f8cfc227f672428bb239359f00fb96d21f2d9e6ba990be98f53bf9026fafcdf
BLAKE2b-256 checksum
How to use checksums
44b053fc6047b7742634e4db7153d6f0f42d06fb8c08fa2b0efbefeb658ddcdb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3

Security for pymiediff 0.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page