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 web GUI: PyMieSim Parameter Sweep Lab.

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

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

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

The released wheels are the easiest option. Building from source 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.

Building from source

For development or manual compilation, clone the repository and run:

git submodule update --init
mkdir build && cd build
cmake ../ -G"Unix Makefiles"
sudo make install
cd ..
python -m pip install .

Testing

Run the unit tests with:

pip install PyMieSim[testing]
pytest

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.

Release files for PyMieSim 5.3.0

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.3.0
File
pymiesim-5.3.0-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details
pymiesim-5.3.0-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-5.3.0-cp313-cp313-macosx_26_0_arm64.whl CPython 3.13 CPython 3.13 macOS 26.0+ ARM64 Details
pymiesim-5.3.0-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
pymiesim-5.3.0-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.3.0-cp312-cp312-macosx_26_0_arm64.whl CPython 3.12 CPython 3.12 macOS 26.0+ ARM64 Details
pymiesim-5.3.0-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
pymiesim-5.3.0-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-5.3.0-cp311-cp311-macosx_26_0_arm64.whl CPython 3.11 CPython 3.11 macOS 26.0+ ARM64 Details

Total release size: 67.8 MB

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

Download URL pymiesim-5.3.0-cp313-cp313-win_amd64.whl
Size 12.8 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
07a06171c32e277bc16053e2bafb947615f064ad307d60421a379982d5d6f552
BLAKE2b-256 checksum
How to use checksums
dd08bd7275a4f9f890ff14432940d94c0a698e71a646f10e58212ff78f7008e6
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.3.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL pymiesim-5.3.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 5.5 MB
Tags CPython 3.13 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
2b689603df659fe45becec79ee07d91dbddee105ad648d068c7c4e2cc1d11b56
BLAKE2b-256 checksum
How to use checksums
23e0193b5565b194a710679c600dbcc44f70462a5440453ab727965f6545a3b0
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.3.0-cp313-cp313-macosx_26_0_arm64.whl

Download URL pymiesim-5.3.0-cp313-cp313-macosx_26_0_arm64.whl
Size 4.4 MB
Tags CPython 3.13 macOS 26.0+ ARM64
SHA-256 checksum
How to use checksums
0b3024df8a0d81e6b96b021031fe826bea795ec96b9b5a28ee3ea7da699a30bf
BLAKE2b-256 checksum
How to use checksums
26d6cccb077563ea66a7fe18d163e0b83ed12bec06e48c88621145c1b3a51143
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.3.0-cp312-cp312-win_amd64.whl

Download URL pymiesim-5.3.0-cp312-cp312-win_amd64.whl
Size 12.8 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
dd0fdb2f538680ac8871c6c35e59bba9d573f5c044f7fc1d6091d889f2dc74c6
BLAKE2b-256 checksum
How to use checksums
e4b948c489cd7624c3e5d8114b45ae08cdbd8bfeaf372a46afc017714befabc8
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.3.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL pymiesim-5.3.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 5.5 MB
Tags CPython 3.12 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
aa404b9f167557f6b41b755e09972c6818908b609bd9e9067f425cf3fbe5331d
BLAKE2b-256 checksum
How to use checksums
cfa8ecd114b9b4682890f0da60abdf58134fc1c0bee7e9ff3455675276cb7ef9
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.3.0-cp312-cp312-macosx_26_0_arm64.whl

Download URL pymiesim-5.3.0-cp312-cp312-macosx_26_0_arm64.whl
Size 4.4 MB
Tags CPython 3.12 macOS 26.0+ ARM64
SHA-256 checksum
How to use checksums
e64ea448decc69413c538f6b5ce595537a0253a84b3fef9ad23c52cc4934cc05
BLAKE2b-256 checksum
How to use checksums
00f6f7099b48617e657aef6153da7852e4258045b0b3eb5e67df337b953e0093
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.3.0-cp311-cp311-win_amd64.whl

Download URL pymiesim-5.3.0-cp311-cp311-win_amd64.whl
Size 12.7 MB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
5e18bf829b67ec8f6e12ae7c5e0797e9a10791062389fa75a3653791451f487f
BLAKE2b-256 checksum
How to use checksums
34b903a5f22b1ef1fecde13fa3aad4a96b8205605da2702f6a9b24d0ffde8e0c
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.3.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL pymiesim-5.3.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 5.5 MB
Tags CPython 3.11 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
8f8eeaa482e04debea354af15f501d44bf4a8108ed06a90daecd0e73932ecbef
BLAKE2b-256 checksum
How to use checksums
9adf74f5850fb9e6721152941362a9d8cd060575b9c8437366b6388d1a2dd59c
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.3.0-cp311-cp311-macosx_26_0_arm64.whl

Download URL pymiesim-5.3.0-cp311-cp311-macosx_26_0_arm64.whl
Size 4.3 MB
Tags CPython 3.11 macOS 26.0+ ARM64
SHA-256 checksum
How to use checksums
5bb69d0007decbcd130b6cf910ce80869f809ad2b6c6a554548a087856130439
BLAKE2b-256 checksum
How to use checksums
06297c6821bfe078c1fe002061ed72cba40ed73b4b910cb5a19fea7932c92948
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

5.6.0

9 release files

This release

5.3.0 This release

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