NonlinearTMM: Nonlinear Transfer-Matrix Method
A Python library for optical simulations of multilayer structures using the transfer-matrix method, extended to support nonlinear processes (SHG, SFG, DFG) and Gaussian beam propagation.
See also: GeneralTmm — a 4×4 TMM for anisotropic (birefringent) multilayer structures.
Table of Contents
Features
- Standard TMM — reflection, transmission, absorption for p- and s-polarized plane waves at arbitrary angles
- Parameter sweeps — over wavelength, angle of incidence, layer thickness, or any other parameter
- 1D and 2D electromagnetic field profiles — E and H field distributions through the structure
- Field enhancement — calculation of field enhancement factors (e.g. for SPP excitation)
- Gaussian beam propagation — any beam profile through layered structures, not just plane waves
- Second-order nonlinear processes — SHG, SFG, DFG in multilayer structures
- Wavelength-dependent materials — interpolated from measured optical data (YAML format)
- High performance — C++ core (Eigen) with Cython bindings, OpenMP parallelization
- Cross-platform wheels — Linux (x86_64), Windows (x64, ARM64), macOS (ARM64); Python 3.10–3.14
Installation
pip install NonlinearTMM
Pre-built wheels are available for most platforms. A C++ compiler is only needed when installing from source.
API Overview
The library exposes three main classes: Material, TMM, and SecondOrderNLTMM.
| Class / method | Purpose |
|---|---|
Material(wls, ns) |
Wavelength-dependent material from arrays of λ and complex n |
Material.Static(n) |
Constant refractive index (shortcut) |
TMM(wl=…, pol=…, I0=…) |
Create a solver; wl = wavelength (m), pol = "p" or "s" |
tmm.AddLayer(d, mat) |
Append layer (d in m, inf for semi-infinite) |
tmm.Sweep(param, values) |
Solve for an array of values of any parameter |
tmm.GetFields(zs) |
E, H field profiles along the layer normal |
tmm.GetFields2D(zs, xs) |
E, H on a 2-D grid |
tmm.GetEnhancement(layerNr) |
Field enhancement in a given layer |
tmm.wave |
Access _Wave parameters for Gaussian beam calculations |
tmm.WaveSweep(param, values) |
Parameter sweep for beam calculations |
tmm.WaveGetFields2D(zs, xs) |
2-D field map for beam excitation |
SecondOrderNLTMM(…) |
Second-order nonlinear TMM (SHG, SFG, DFG) |
For the full API, see the reference documentation.
Examples
Surface Plasmon Polaritons — ExampleTMM.py
Kretschmann configuration (prism | 50 nm Ag | air) at 532 nm. Demonstrates reflection sweeps, field enhancement, and 1D/2D field visualization of surface plasmon polaritons.
import math
import numpy as np
from NonlinearTMM import TMM, Material
# Materials
prism = Material.Static(1.5)
ag = Material.Static(0.054007 + 3.4290j) # Silver @ 532nm
air = Material.Static(1.0)
# Set up TMM (Kretschmann configuration)
tmm = TMM(wl=532e-9, pol="p", I0=1.0)
tmm.AddLayer(math.inf, prism)
tmm.AddLayer(50e-9, ag)
tmm.AddLayer(math.inf, air)
# Sweep angle of incidence
betas = np.sin(np.radians(np.linspace(0, 80, 500))) * 1.5
result = tmm.Sweep("beta", betas, outEnh=True, layerNr=2)
Gaussian Beam Excitation — ExampleTMMForWaves.py
The same Kretschmann structure excited by a 10 mW Gaussian beam (waist 10 μm). Shows how finite beam width affects resonance depth and field enhancement.
Second-Harmonic Generation — ExampleSecondOrderNonlinearTmm.py
Second-harmonic generation (SHG) in a 1 mm nonlinear crystal with
χ⁽²⁾ nonlinearity. Two s-polarized pump beams at 1000 nm generate a
second-harmonic signal at 500 nm. The SecondOrderNLTMM class also supports
sum-frequency generation (SFG) and difference-frequency generation (DFG).
References
Loot, A., & Hizhnyakov, V. (2017). Extension of standard transfer-matrix method for three-wave mixing for plasmonic structures. Applied Physics A, 123(3), 152. doi:10.1007/s00339-016-0733-0
Loot, A., & Hizhnyakov, V. (2018). Modeling of enhanced spontaneous parametric down-conversion in plasmonic and dielectric structures with realistic waves. Journal of Optics, 20, 055502. doi:10.1088/2040-8986/aab6c0
Documentation
Full documentation is available at https://ardiloot.github.io/NonlinearTMM/.
- Getting started — installation, package structure, examples
- API reference — complete class and method reference
Development
Setup
git clone --recurse-submodules https://github.com/ardiloot/NonlinearTMM.git
cd NonlinearTMM
# Install uv if not already installed:
# https://docs.astral.sh/uv/getting-started/installation/
# Create venv, build the C++ extension, and install all dependencies
uv sync
Running tests
uv run pytest -v
Code formatting and linting
Pre-commit hooks are configured to enforce formatting (ruff, clang-format) and catch common issues. To install the git hook locally:
uv run pre-commit install
To run all checks manually:
uv run pre-commit run --all-files
CI overview
| Workflow | Trigger | What it does |
|---|---|---|
| Pytest | Push to master / PRs |
Tests on {ubuntu, windows, macos} × Python {3.10–3.14} |
| Pre-commit | Push to master / PRs |
Runs ruff, clang-format, ty, and other checks |
| Publish to PyPI | Release published | Builds wheels + sdist via cibuildwheel, uploads to PyPI |
| Publish docs | Release published | Builds Sphinx docs and deploys to GitHub Pages |
Releasing
Versioning is handled automatically by setuptools-scm from git tags.
- Ensure CI is green on the
masterbranch. - Create a new release on GitHub:
- Go to Releases → Draft a new release
- Create a new tag following PEP 440 (e.g.
v1.2.0) - Target the
masterbranch (or a specific commit on master) - Click Generate release notes for an auto-generated changelog
- For pre-releases (e.g.
v1.2.0rc1), check Set as a pre-release — these upload to TestPyPI instead of PyPI
- Publish the release — the workflow builds wheels for Linux (x86_64), Windows (x64, ARM64), and macOS (ARM64), and uploads to PyPI.
License
Metadata
Release files for NonlinearTMM 1.4.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| nonlineartmm-1.4.2.tar.gz | 2.3 MB | Without provenance | Details for nonlineartmm-1.4.2.tar.gz |
Built distributions (wheels)
Total release size: 31.1 MB
Release files / nonlineartmm-1.4.2.tar.gz
| Download URL | nonlineartmm-1.4.2.tar.gz |
|---|---|
| Size | 2.3 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1b04802822d1bba25142c6a05fbb1497d2f02e38857f23838c2b619e02ec585d
|
|
BLAKE2b-256 checksum How to use checksums |
adbb97a4ec5190097c0b0b860d4284481c8627ea4e7efa805267072808dc6c53
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / nonlineartmm-1.4.2-cp314-cp314-win_arm64.whl
| Download URL | nonlineartmm-1.4.2-cp314-cp314-win_arm64.whl |
|---|---|
| Size | 404.9 kB |
| Tags | CPython 3.14 Windows ARM64 |
|
SHA-256 checksum How to use checksums |
0840d4c536a7146df28fcc5eb5bd16253d2c591fe89d77ce2695c3dc7e527b70
|
|
BLAKE2b-256 checksum How to use checksums |
6fd9130a5bd1eb1418830ad2f85e5addb0ab1796d0143ba15734b003822e4c1b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / nonlineartmm-1.4.2-cp314-cp314-win_amd64.whl
| Download URL | nonlineartmm-1.4.2-cp314-cp314-win_amd64.whl |
|---|---|
| Size | 437.4 kB |
| Tags | CPython 3.14 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
939f1990c4ef458e7f7ec6064f3a8d4863fc21f4df60f5baf2d479af391e3536
|
|
BLAKE2b-256 checksum How to use checksums |
91b56e741c29764db361810bc83e28e1e5f338b620eaddcd90a4fcd7e8aae82b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / nonlineartmm-1.4.2-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | nonlineartmm-1.4.2-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 4.6 MB |
| Tags | CPython 3.14 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
008d0ccc0b42204bea04a3c0936813eb4bb413dd7afd4904de77e138dab57290
|
|
BLAKE2b-256 checksum How to use checksums |
ed5b25da9e58c133895f7fd27fec5cb25808700b0f14c21bc206e5944efceedb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / nonlineartmm-1.4.2-cp314-cp314-macosx_11_0_arm64.whl
| Download URL | nonlineartmm-1.4.2-cp314-cp314-macosx_11_0_arm64.whl |
|---|---|
| Size | 459.8 kB |
| Tags | CPython 3.14 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
0162b52a813f41b72078bc01bdb4320ed3cf7f07167908b36f37a6221e24900c
|
|
BLAKE2b-256 checksum How to use checksums |
8e46d77ce5062999f1beabea619add601aad9ea9bdc1e8dd82a3cb5e57c43c80
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / nonlineartmm-1.4.2-cp313-cp313-win_arm64.whl
| Download URL | nonlineartmm-1.4.2-cp313-cp313-win_arm64.whl |
|---|---|
| Size | 395.5 kB |
| Tags | CPython 3.13 Windows ARM64 |
|
SHA-256 checksum How to use checksums |
f7136e4a2126c867d2ba1508fabe2f78cc1064db6760508f329ec4f993318790
|
|
BLAKE2b-256 checksum How to use checksums |
9140a2906ca1115bcc04644e0874c0b5bb9fd7fbb2ab428c2f1f8083e6bc5cdf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / nonlineartmm-1.4.2-cp313-cp313-win_amd64.whl
| Download URL | nonlineartmm-1.4.2-cp313-cp313-win_amd64.whl |
|---|---|
| Size | 427.3 kB |
| Tags | CPython 3.13 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
f6b32b8e72e7a7e5288ff8a4023c9ca5a4521dfa833efef5f0e904855cd03783
|
|
BLAKE2b-256 checksum How to use checksums |
968f4b9e4224485d25c28645ddcf593ca1680e71cacbd33e392b896cdf2b8aff
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / nonlineartmm-1.4.2-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | nonlineartmm-1.4.2-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 4.6 MB |
| Tags | CPython 3.13 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
66ae8be272058438711308ac3caa9a2a1dc91fcc10c95f400addccb25d0c0da3
|
|
BLAKE2b-256 checksum How to use checksums |
8a1a56cdabe3c4eb204b89acdd7dffdc2df4e1bbf761619646d32a0d0b11d863
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / nonlineartmm-1.4.2-cp313-cp313-macosx_11_0_arm64.whl
| Download URL | nonlineartmm-1.4.2-cp313-cp313-macosx_11_0_arm64.whl |
|---|---|
| Size | 453.1 kB |
| Tags | CPython 3.13 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
291ecebb854d3435a58434e8f45ca551c5468d5cd4137b3a35622c664b6f59bd
|
|
BLAKE2b-256 checksum How to use checksums |
2ea2059bc463bfae2d957223a1b710e3067eecf3c92492d879352097ef55ae35
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / nonlineartmm-1.4.2-cp312-cp312-win_arm64.whl
| Download URL | nonlineartmm-1.4.2-cp312-cp312-win_arm64.whl |
|---|---|
| Size | 395.6 kB |
| Tags | CPython 3.12 Windows ARM64 |
|
SHA-256 checksum How to use checksums |
7b6ede0af649a365aee90d2617d6d4af403d46c2ee71d994c36fbdce82f59750
|
|
BLAKE2b-256 checksum How to use checksums |
4e6352b1c49ad4ec16ee04661f45367832ef4abee151f860c85cad8188a14eb1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / nonlineartmm-1.4.2-cp312-cp312-win_amd64.whl
| Download URL | nonlineartmm-1.4.2-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 427.7 kB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
68f64d8e8bf05154613134bc4b0da75bfe2f116dc3b546b3696b9dfa516a6122
|
|
BLAKE2b-256 checksum How to use checksums |
77cfaafbeebaf574addd8df34315236dd47b073f07e353aa18e6b0b9c4abfc56
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / nonlineartmm-1.4.2-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | nonlineartmm-1.4.2-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 4.7 MB |
| Tags | CPython 3.12 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
c8e5f86b955da70762bed58e83271852c06a39e292a6d9e6b0d07d45209870c5
|
|
BLAKE2b-256 checksum How to use checksums |
1f3b725eebd44a9d7b739fc6f7a3f9f4104041761b9558ca0d181168c3fffaf9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / nonlineartmm-1.4.2-cp312-cp312-macosx_11_0_arm64.whl
| Download URL | nonlineartmm-1.4.2-cp312-cp312-macosx_11_0_arm64.whl |
|---|---|
| Size | 453.5 kB |
| Tags | CPython 3.12 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
746f26c8b6b14a8d6884fc44928d43f4bd2eb45a1be0a9330d9490095a888b83
|
|
BLAKE2b-256 checksum How to use checksums |
815fcee097b91b4eaec4ce4d8433c4d2b393bae4579bbb19c6b704d883d3cbeb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / nonlineartmm-1.4.2-cp311-cp311-win_amd64.whl
| Download URL | nonlineartmm-1.4.2-cp311-cp311-win_amd64.whl |
|---|---|
| Size | 431.1 kB |
| Tags | CPython 3.11 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
957881370a6f4f2a6024ad4a9559f191d4c329825836bcd6dde4b257d2824a0d
|
|
BLAKE2b-256 checksum How to use checksums |
e883421f0b3f5b377d5c55a22edb99106b2ee4722fb430937958a1546d01ab4e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / nonlineartmm-1.4.2-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | nonlineartmm-1.4.2-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 4.6 MB |
| Tags | CPython 3.11 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
b36d466915cd02a71c5a8f80003bc15307d2f325196921cb925ac31c921e5198
|
|
BLAKE2b-256 checksum How to use checksums |
de8fb2aad6804387eb1c626b9f94ec1b22acbe4462651d129b92d803b3140ec9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / nonlineartmm-1.4.2-cp311-cp311-macosx_11_0_arm64.whl
| Download URL | nonlineartmm-1.4.2-cp311-cp311-macosx_11_0_arm64.whl |
|---|---|
| Size | 451.8 kB |
| Tags | CPython 3.11 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
70b66f1df2a904b807577d1feeb5ec6d05159f1b164ba9250ca10a5ad31c96b1
|
|
BLAKE2b-256 checksum How to use checksums |
3c3a8266bafd834982bc618e37e1fd2fa4d75a3ae6c3da709c2b63a4c121d94f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / nonlineartmm-1.4.2-cp310-cp310-win_amd64.whl
| Download URL | nonlineartmm-1.4.2-cp310-cp310-win_amd64.whl |
|---|---|
| Size | 431.1 kB |
| Tags | CPython 3.10 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
19f02b83613b9c25cb0a6fbcfdb8975f48417dcb96326c2556c587a4157e4480
|
|
BLAKE2b-256 checksum How to use checksums |
e6fb869a0386784011e8b93d7d7af38fc1d7cbb67c762493f32bc0d83d705fe8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / nonlineartmm-1.4.2-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | nonlineartmm-1.4.2-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 4.6 MB |
| Tags | CPython 3.10 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
f39603ae704a8ad2a8d04f5bb31db92b02a07c002e25b4e1fa45060977fe94ed
|
|
BLAKE2b-256 checksum How to use checksums |
2535b14ce36d9b160f175818603ad9d314bbf992dd9c4f6861b8d2218ad56e00
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / nonlineartmm-1.4.2-cp310-cp310-macosx_11_0_arm64.whl
| Download URL | nonlineartmm-1.4.2-cp310-cp310-macosx_11_0_arm64.whl |
|---|---|
| Size | 451.7 kB |
| Tags | CPython 3.10 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
7aa1a975b164f2d52a885ba304c4cb02f5c163bd43d22c353ef95be5e1efe93b
|
|
BLAKE2b-256 checksum How to use checksums |
94bdfff54ac3e0d6252853fd03fe880df7c5580aa8031c1ff3e95a94db0937e8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Security for NonlinearTMM 1.4.2
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.