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 5.8.1

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 5.8.1
File
pymiesim-5.8.1-cp314-cp314-win_amd64.whl CPython 3.14 CPython 3.14 Windows x86-64 Details
pymiesim-5.8.1-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 Details
pymiesim-5.8.1-cp314-cp314-macosx_26_0_arm64.whl CPython 3.14 CPython 3.14 macOS 26.0+ ARM64 Details
pymiesim-5.8.1-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details
pymiesim-5.8.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 Details
pymiesim-5.8.1-cp313-cp313-macosx_26_0_arm64.whl CPython 3.13 CPython 3.13 macOS 26.0+ ARM64 Details
pymiesim-5.8.1-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
pymiesim-5.8.1-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-5.8.1-cp312-cp312-macosx_26_0_arm64.whl CPython 3.12 CPython 3.12 macOS 26.0+ ARM64 Details
pymiesim-5.8.1-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
pymiesim-5.8.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 Details
pymiesim-5.8.1-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-5.8.1-cp314-cp314-win_amd64.whl

Download URL pymiesim-5.8.1-cp314-cp314-win_amd64.whl
Size 14.2 MB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
3f2bce3b066f1b1d71c5a4175e030954d3dfde49c1bb92ee14771629d4c2da60
BLAKE2b-256 checksum
How to use checksums
7315aa5df95891b71c09ab51f116d7e1ff7d99b521307ddfe14a91f15130ba32
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

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

Download URL pymiesim-5.8.1-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
f1ccad8fccbac40a7fe785052e8fad2602b7c406c73d26548d14572231a91ff8
BLAKE2b-256 checksum
How to use checksums
fd3f7778af7e3646add72d51803aa17a7cdf0da190af5a7edeef0dfb28e5f3e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

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

Download URL pymiesim-5.8.1-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
1ccada087d2955940731af3b4d6a6f36dbeab679178d60fe7a4d8c8121a21ac2
BLAKE2b-256 checksum
How to use checksums
2e76b0c1c60e1143e00a838d284151efaad043208a9efb6ee2ea2337fd3cece1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

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

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

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

Download URL pymiesim-5.8.1-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
6105a29997a7137590f737ded1b48ca8ca6ba30db98567a7707a87199cbff042
BLAKE2b-256 checksum
How to use checksums
7a9340103d137d88e3697364cdfe2678957578b7609217082bf6ef74b7db2a7e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

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

Download URL pymiesim-5.8.1-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
cd7dfec9b0dd7e79c36ae5b27a4fba41e567ec14c7be9723b5adfefafc27c599
BLAKE2b-256 checksum
How to use checksums
0678fce1ce7c3c4e277345b849dd3e69804682422ffebafda51c79b72bcef89c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

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

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

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

Download URL pymiesim-5.8.1-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
0d01521f71fa13c6612991740e027157ca8206a6e7f44d4843ebe032dd79c8e5
BLAKE2b-256 checksum
How to use checksums
e373aebe10fb98a0b1e7b7b031d2ab75bba9c9a9c8ff0b3c4300db051cee7495
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

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

Download URL pymiesim-5.8.1-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
a9d3c2b67682b7eb63c7c29c77e1b40c4b9e4fe3e13231da862342b2a1d42555
BLAKE2b-256 checksum
How to use checksums
c9e95151eeba015ea4ff900e083ffc02bbfce08b7093a214e5a893b92ac1c48f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

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

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

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

Download URL pymiesim-5.8.1-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
c9a9476d4c31eb333c8af0cccd7c8a0ff7bee8e91293b35333d2861c75ab43d8
BLAKE2b-256 checksum
How to use checksums
fa97233676dce63c0fa58d450d23cc9bbf41c09ef6beb7d481beaf8a6579044e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

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

Download URL pymiesim-5.8.1-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
da4f34c73747c4e1e9f799f40675ee5453efdd2431728d3eec964348952542b8
BLAKE2b-256 checksum
How to use checksums
3f86f34e6bcef9976c6aad316117c3115bb38717846e90acc22ff0d8624e150b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

This release

5.8.1 This release

12 release files

5.8.0

12 release files

5.7.1

9 release files

5.6.4

9 release files

5.6.0

9 release files

5.3.0

9 release files

5.2.2

9 release files

5.2.1

9 release files

5.2.0

9 release files

5.1.13

9 release files

5.1.12

9 release files

5.1.11

9 release files

5.1.10

9 release files

5.1.9

9 release files

5.1.8

9 release files

5.1.7

9 release files

5.1.6

9 release files

5.1.5

9 release files

5.1.4

9 release files

5.1.3

9 release files

5.1.2

9 release files

5.1.1

9 release files

5.1.0

9 release files

5.0.4

9 release files

5.0.3

9 release files

5.0.2

9 release files

5.0.1

9 release files

5.0.0

9 release files

4.0.2

9 release files

4.0.0

9 release files

3.9.0

9 release files

3.8.6

9 release files

3.8.5

9 release files

3.8.2

12 release files

3.8.0

12 release files

3.7.0

12 release files

3.6.3

12 release files

3.6.2

12 release files

3.6.1

12 release files

3.6.0

12 release files

3.5.4

9 release files

3.5.3

9 release files

3.5.2

9 release files

3.5.1

9 release files

3.5.0

9 release files

3.4.0

9 release files

3.3.4

9 release files

3.3.1

9 release files

3.2.7

9 release files

3.2.6

9 release files

3.2.5

9 release files

3.2.4

9 release files

3.2.3

9 release files

3.2.2

9 release files

3.2.1

9 release files

3.0.1

9 release files

3.0.0

9 release files

2.6.3

9 release files

1.10.4

1 release file

1.10.3

4 release files

1.9.4

15 release files

1.9.3

15 release files

1.9.0

15 release files

1.8.3

15 release files

1.8.2

15 release files

1.8.1

15 release files

1.8.0

15 release files

1.7.3

15 release files

1.7.2

15 release files

1.7.1

15 release files

1.7.0

15 release files

1.5.3

3 release files

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