Skip to main content

PyMieSim logo

Badge

Status

Python versions

Python

Documentation

Documentation Status

Scientific article

Scientific article

Continuous integration

Unittest Status

Test coverage

Unittest coverage

Google Colab

Google Colab

PyPI package

PyPI version

PyPI downloads

PyPI downloads

Anaconda package

Anaconda version

Anaconda downloads

Anaconda downloads

Latest Anaconda release

Latest release date

PyMieSim

PyMieSim is an open-source Python package for fast and flexible Mie scattering simulations. It supports spherical, cylindrical and core–shell particles and provides helper classes for custom sources and detectors. The project targets both quick single-scatterer studies and large parametric experiments.

Try the live webapp

Run Mie scattering simulations in your browser—no installation required.

Launch the PyMieSimX webapp in your browser

Launch the PyMieSimX webapp to configure optical setups, run parameter sweeps, explore individual particles, and download your results as CSV files. The hosted service brings PyMieSim to a graphical interface, making it easy to try simulations before installing the Python package. The interface is developed in PyMieSimX.

Features

  • Solvers for spheres, cylinders and core–shell geometries.

  • Built-in models for plane wave and Gaussian sources.

  • Multiple detector types including photodiodes and coherent modes.

  • Simple data analysis with pandas DataFrame outputs.

Installation

PyMieSim is available on PyPI and Anaconda. Install it with:

pip install PyMieSim
conda install PyMieSim  --channels MartinPdeS

This installs a pre-built wheel when one is available for your operating system, architecture, and Python version. Wheels are the recommended option for using PyMieSim because they include the compiled C++ and Fortran extensions.

Verify the installation with the same Python interpreter that you will use for your simulations:

python -c "import PyMieSim; print(PyMieSim.__version__)"

Named optical materials use PyOptik’s provenance-preserving RefractiveIndex.INFO catalog. Initialize its local snapshot once before using constructors such as SellmeierMaterial("BK7") or TabulatedMaterial("silver"):

python -m PyOptik setup

Building from source is intended for development or platforms without a matching wheel. It requires a C++20 compiler, Fortran, CMake, pybind11, and OpenMP; see troubleshooting if the compiled extension cannot be imported.

First simulation

Create a source, a scatterer, and a Simulation. Physical quantities use the built-in ureg unit registry, while refractive indices are dimensionless real or complex values.

from PyMieSim import (
    Gaussian,
    PolarizationState,
    Simulation,
    Sphere,
    ureg,
)

source = Gaussian(
    wavelength=633 * ureg.nanometer,
    polarization=PolarizationState(angle=0 * ureg.degree),
    optical_power=1e-3 * ureg.watt,
    numerical_aperture=0.2,
)

scatterer = Sphere(
    diameter=200 * ureg.nanometer,
    material=1.5 + 0.01j,
    medium=1.0,
)

simulation = Simulation(scatterer=scatterer, source=source)
qsca = simulation.run("Qsca")
print(qsca)

This prints a dimensionless scattering efficiency, approximately:

0.2080989068292113 dimensionless

Inspect the measures supported by the configured simulation with:

print(simulation.available_measures)

For explicit measure and unit metadata, request a typed result:

result = simulation.run("Qsca", as_result=True)
print(result.measure, result.quantity, result.units)

Units and material conventions

Always attach units to wavelengths, lengths, powers, and angles:

633 * ureg.nanometer
200 * ureg.nanometer
1e-3 * ureg.watt
0 * ureg.degree

Refractive indices are dimensionless. A complex index such as 1.5 + 0.01j represents an absorbing material under PyMieSim’s optical convention. Built-in and tabulated materials have supported wavelength ranges; use load_material and validate_wavelength when working with real material data.

Parameter sweeps

Use Experiment when you want to evaluate several wavelengths, particle sizes, or material parameters. Results retain named dimensions and coordinates, and can be converted to NumPy or pandas explicitly.

import numpy as np
from PyMieSim import (
    Experiment,
    GaussianSet,
    PolarizationSet,
    SphereSet,
    ureg,
)

source = GaussianSet(
    wavelength=np.linspace(500, 700, 5) * ureg.nanometer,
    polarization=PolarizationSet(angles=0 * ureg.degree),
    optical_power=1e-3 * ureg.watt,
    numerical_aperture=0.2,
)
scatterer = SphereSet(
    diameter=np.linspace(100, 500, 9) * ureg.nanometer,
    material=1.5,
    medium=1.0,
)

experiment = Experiment(scatterer_set=scatterer, source_set=source)
result = experiment.get("Qsca")
values = result.as_numpy()
dataframe = result.as_dataframe()

The experiment grid has five wavelength values and nine diameter values, so values.shape is (5, 9). See the parameter sweep guide for multiple measures and plotting.

Detector coupling

Add a detector when you need collected or coupled power rather than only a scatterer property:

from PyMieSim import (
    Gaussian,
    Photodiode,
    PolarizationState,
    Simulation,
    Sphere,
    ureg,
)

single_source = Gaussian(
    wavelength=633 * ureg.nanometer,
    polarization=PolarizationState(angle=0 * ureg.degree),
    optical_power=1e-3 * ureg.watt,
    numerical_aperture=0.2,
)
single_scatterer = Sphere(
    diameter=200 * ureg.nanometer,
    material=1.5 + 0.01j,
    medium=1.0,
)

detector = Photodiode(
    sampling=500,
    numerical_aperture=0.2,
    phi_offset=0 * ureg.degree,
    gamma_offset=0 * ureg.degree,
    medium=1.0,
)
simulation = Simulation(
    scatterer=single_scatterer,
    source=single_source,
    detector=detector,
)
coupling = simulation.run("coupling")
print(coupling)

coupling requires a detector. Other available detector types include CoherentMode and IntegratingSphere; see the detector coupling guide.

Common issues

  • If import PyMieSim fails, run python -m pip show PyMieSim and check that it uses the same Python executable as your script.

  • If a constructor reports a unit error, check that every dimensional input has units and convert it with .to(...) when necessary.

  • If coupling is unavailable, add a detector and inspect simulation.available_measures.

  • For slow or memory-heavy sweeps, print experiment.array_shape and experiment.total_iterations before requesting a result.

  • On servers or in CI, select a non-interactive Matplotlib backend such as Agg before importing plotting code.

See the online documentation for theory, performance guidance, runnable examples, and advanced near-field and far-field workflows.

Scattering efficiency of a 200 nm sphere with refractive index 4.0.

Code structure

Here is the architecture for a standard workflow using PyMieSim:

Code structure of a standard workflow using PyMieSim.

Developer setup

Clone the repository, select the Python interpreter you want to use, install the development and testing dependencies, and build an editable installation:

git clone https://github.com/MartinPdeS/PyMieSim.git
cd PyMieSim
python -m pip install ".[testing,documentation,dev]"
python -m PyOptik setup --no-progress
make PYTHON=python editable

make editable builds the native extensions in the local build directory and installs them into the same environment. Always run tests with that same interpreter:

python -c "import PyMieSim; print(PyMieSim.__version__)"
python -m pytest --config-file=pytest.ini

If the import reports missing native extensions, the build was not completed for this interpreter. Re-run make editable after checking that CMake, Fortran, pybind11, and OpenMP are installed. Do not mix build artifacts from different Python versions or architectures.

Building from source manually

The equivalent lower-level workflow is:

python -m pip install --no-build-isolation -Cbuild-dir=build -e .

The editable workflow is preferred because it keeps the Python sources and compiled extensions aligned. A released wheel does not require a compiler or the native build toolchain.

Testing

After the developer setup, run the unit tests with:

python -m pytest --config-file=pytest.ini

Citing PyMieSim

If you use PyMieSim in academic work, please cite:

@article{PoinsinetdeSivry-Houle:23,
    author = {Martin Poinsinet de Sivry-Houle and Nicolas Godbout and Caroline Boudoux},
    journal = {Opt. Continuum},
    title = {PyMieSim: an open-source library for fast and flexible far-field Mie scattering simulations},
    volume = {2},
    number = {3},
    pages = {520--534},
    year = {2023},
    doi = {10.1364/OPTCON.473102},
}

Contact

For questions or contributions, contact martin.poinsinet.de.sivry@gmail.com.

Metadata

Release files for PyMieSim 6.0.3

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

Built distributions (wheels)

Table of built distributions (wheels) for PyMieSim 6.0.3
File
pymiesim-6.0.3-cp314-cp314-win_amd64.whl CPython 3.14 CPython 3.14 Windows x86-64 Details
pymiesim-6.0.3-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 Details
pymiesim-6.0.3-cp314-cp314-macosx_26_0_arm64.whl CPython 3.14 CPython 3.14 macOS 26.0+ ARM64 Details
pymiesim-6.0.3-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details
pymiesim-6.0.3-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 Details
pymiesim-6.0.3-cp313-cp313-macosx_26_0_arm64.whl CPython 3.13 CPython 3.13 macOS 26.0+ ARM64 Details
pymiesim-6.0.3-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
pymiesim-6.0.3-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 Details
pymiesim-6.0.3-cp312-cp312-macosx_26_0_arm64.whl CPython 3.12 CPython 3.12 macOS 26.0+ ARM64 Details
pymiesim-6.0.3-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
pymiesim-6.0.3-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 Details
pymiesim-6.0.3-cp311-cp311-macosx_26_0_arm64.whl CPython 3.11 CPython 3.11 macOS 26.0+ ARM64 Details

Total release size: 98.3 MB

Release files / pymiesim-6.0.3-cp314-cp314-win_amd64.whl

Download URL pymiesim-6.0.3-cp314-cp314-win_amd64.whl
Size 14.2 MB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
79e88966674e63fc1af0ba007652b604aeb1a2888ae42ef7fad7efa4da086aef
BLAKE2b-256 checksum
How to use checksums
cfb88a7c684767d52b9f5735ecc98777ab4aa1138bd982f5e4cd741aa99308e1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.17

Release files / pymiesim-6.0.3-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL pymiesim-6.0.3-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 6.0 MB
Tags CPython 3.14 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
b580b242069998bb0582309d643d9d973a52a1c6e29e2f08bbe25210499c859f
BLAKE2b-256 checksum
How to use checksums
6ae3376a649c1b11c13a63695ee04dc044684f3e16f9903045b815de8ff5e15d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.17

Release files / pymiesim-6.0.3-cp314-cp314-macosx_26_0_arm64.whl

Download URL pymiesim-6.0.3-cp314-cp314-macosx_26_0_arm64.whl
Size 4.8 MB
Tags CPython 3.14 macOS 26.0+ ARM64
SHA-256 checksum
How to use checksums
244d659f09a9e0272024a04ae9ae8c2bbb9e507d62123aaeab9bec819f3b19f0
BLAKE2b-256 checksum
How to use checksums
ff446eb43947f80ee65085f90db839c63314da33c966806d0e3c8b83df3ef71d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.17

Release files / pymiesim-6.0.3-cp313-cp313-win_amd64.whl

Download URL pymiesim-6.0.3-cp313-cp313-win_amd64.whl
Size 13.7 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
db942ad3bd15fd6be42cd9c1e1b80867eb3e7c195ef7bf6fbdaec7e52cad0aab
BLAKE2b-256 checksum
How to use checksums
93f5c5a0d55db30b5631412dc4c302b246b4e179c2f8a1db1695ed609d5ae70d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.17

Release files / pymiesim-6.0.3-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL pymiesim-6.0.3-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 6.0 MB
Tags CPython 3.13 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
7a3fcc2b5c997d8f28eb7c42b05b5b4cbd4fadff2e8370f53507b3ac01046edd
BLAKE2b-256 checksum
How to use checksums
3a92f1536786673e2caebb076835b4bf578aa3c4d3b45328ce1ec765aaf820d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.17

Release files / pymiesim-6.0.3-cp313-cp313-macosx_26_0_arm64.whl

Download URL pymiesim-6.0.3-cp313-cp313-macosx_26_0_arm64.whl
Size 4.8 MB
Tags CPython 3.13 macOS 26.0+ ARM64
SHA-256 checksum
How to use checksums
d23b14dd1adcd3b70c2fb9a6dc9194729cc842005239abf59b72a5097d2e7fa7
BLAKE2b-256 checksum
How to use checksums
aee11ecb6b766c59e748b3e3d7e683856960a0b022f65931fff445e93d572915
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.17

Release files / pymiesim-6.0.3-cp312-cp312-win_amd64.whl

Download URL pymiesim-6.0.3-cp312-cp312-win_amd64.whl
Size 13.7 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
d51ec38eb4f19a29a3c6244b761bc743b989bcc2033a21790f51563ae3c33f38
BLAKE2b-256 checksum
How to use checksums
40f857661ef410c36dfc4ebdabfe94361ea6f44556e7b6724a71576913c229a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.17

Release files / pymiesim-6.0.3-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL pymiesim-6.0.3-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 6.0 MB
Tags CPython 3.12 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
c44907b02eb1e74f2de597a89bd96c0541493286083ba22cafef975ec2ee628b
BLAKE2b-256 checksum
How to use checksums
2d8de32b45ef3371726479ce1c0d6b2ac07bdb88a514632715e91a36e35d30d9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.17

Release files / pymiesim-6.0.3-cp312-cp312-macosx_26_0_arm64.whl

Download URL pymiesim-6.0.3-cp312-cp312-macosx_26_0_arm64.whl
Size 4.8 MB
Tags CPython 3.12 macOS 26.0+ ARM64
SHA-256 checksum
How to use checksums
02f56a89fbe4b7fad8eb6cf6635f530c680de213b37d58873ce1d80f1a4c11b9
BLAKE2b-256 checksum
How to use checksums
8cfb720ea098c6e4df87411a6d735965ea1ff56bb5523298708ef7c455d38550
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.17

Release files / pymiesim-6.0.3-cp311-cp311-win_amd64.whl

Download URL pymiesim-6.0.3-cp311-cp311-win_amd64.whl
Size 13.6 MB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
8fe9c6e4eb907cc9b9b2fb83c55d5c6c0e548f9725c6111085fbb7f124a4ba58
BLAKE2b-256 checksum
How to use checksums
f5e46ab92de6d12347f5e4675f95aafb0f1f07d8ffb526598b1b448902471d5a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.17

Release files / pymiesim-6.0.3-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL pymiesim-6.0.3-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 6.0 MB
Tags CPython 3.11 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
e145f8cca526356dcc7d706b5d02cfa0fd3a59f8caf83eb52aa43177618b3f79
BLAKE2b-256 checksum
How to use checksums
d85e87605a80a3ccf69aed96190ac8316288d1a702e9e71815397fe8400ca440
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.17

Release files / pymiesim-6.0.3-cp311-cp311-macosx_26_0_arm64.whl

Download URL pymiesim-6.0.3-cp311-cp311-macosx_26_0_arm64.whl
Size 4.8 MB
Tags CPython 3.11 macOS 26.0+ ARM64
SHA-256 checksum
How to use checksums
732ead915ed56488c80eeac46252776634cb902d6bf298b284f5de388a7c054d
BLAKE2b-256 checksum
How to use checksums
d2f53e789db49df2a41ac86bf9e30563cd706a3e07002f35aadb32561b652d55
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.17

Security for PyMieSim 6.0.3

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.

Release history Release notifications | RSS feed

This release

6.0.3 This release

12 release files No provenance

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