PyMoosh: a comprehensive numerical toolkit for computing the optical properties of multilayered structures

Denis Langevin, Pauline Bennet, Abdourahman Khaireh-Walieh, Peter R. Wiecha, Olivier Teytaud, A. MoreauJournal of the Optical Society of America B 2023 · DOI · arXiv

TL;DR

PyMoosh is a comprehensive, open-source Python library designed to simulate the optical properties of multilayered structures with high numerical stability and speed. It bridges the gap between specialized research tools and educational software, offering a unified interface for everything from simple reflectance calculations to complex guided-mode tracking and photovoltaic efficiency optimization.

What Problem Does This Paper Address?

While the physics of multilayered optical structures (like Bragg mirrors or anti-reflective coatings) has been understood for over a century, modern applications—such as plasmonics, metamaterials, and deep-learning-driven inverse design—demand more from simulation tools.

Researchers often face a trade-off: use simple transfer matrix methods that become numerically unstable when dealing with many layers or metallic components (due to "floating-point cancellation"), or use complex, specialized software that is difficult to integrate into modern programming workflows. PyMoosh addresses this by providing a user-friendly, Pythonic environment that implements multiple numerical formalisms, allowing users to choose the right tool for their specific balance of speed and stability.

Methods

PyMoosh implements five distinct numerical formalisms to solve Maxwell’s equations in 1D stacks:

  1. Transfer Matrices (T-matrices): The standard approach, though prone to instability in thick or evanescent structures.
  2. Scattering Matrices (S-matrices): The "gold standard" for stability, particularly when evanescent waves are present (e.g., in metals or prism couplers).
  3. Abelès Formalism: A computationally efficient method that is roughly twice as fast as T-matrices while maintaining similar stability.
  4. Dirichlet-to-Neumann (DtN) Maps: A modern alternative that offers a good compromise for large stacks with evanescent fields.
  5. Admittance Formalism: The fastest method for computing reflectance, making it ideal for high-speed optimization loops.

Beyond basic reflectance/transmittance, the toolkit includes specialized solvers for:

  • Absorption Profiles: Calculating exactly where energy is deposited within a stack.
  • Source Modeling: Computing fields generated by internal current sources (Green functions) or external Gaussian beams.
  • Guided Mode Tracking: Finding and following the dispersion curves of leaky or guided modes using a steepest-descent algorithm in the complex plane.

Datasets

As a simulation toolkit, PyMoosh does not introduce a new experimental dataset. However, it includes built-in physical data necessary for realistic simulations, such as the AM1.5 solar spectrum for photovoltaic calculations. The authors also provide a suite of Jupyter Notebook "use cases" that serve as benchmarks for common problems, including Surface Plasmon Resonance (SPR), ellipsometry, and waveguide coupling.

Key Insights and Ideas

  • No "One Size Fits All": The paper provides a rare, head-to-head comparison of different formalisms. For instance, while the S-matrix is the most stable, the Admittance formula is significantly faster for optimization tasks where only reflectance is needed.
  • Stability over 150 Layers: The authors demonstrate that T-matrix and Abelès methods typically fail due to numerical noise when a structure exceeds ~150 layers or involves significant evanescent decay, whereas S-matrix and DtN methods remain accurate to machine precision.
  • The Importance of Square Roots: A subtle but critical insight is how the determination of the complex square root (the phase of the propagation constant) affects the ability to find guided modes. PyMoosh allows manual adjustment of this to ensure "poles" (modes) are correctly identified in the complex plane.
  • Designed for "Good Glue": By choosing Python, the authors emphasize PyMoosh's role as "glue" for larger workflows, such as generating massive datasets for training neural networks or performing inverse design.

Key Results

  • Computational Efficiency: The Admittance formalism is shown to be the most efficient for reflectance, while the Abelès formalism is twice as fast as the T-matrix or DtN methods for general calculations.
  • Numerical Reliability: In a "frustrated Total Internal Reflection" test case, S-matrix and DtN methods maintained accuracy across several microns of air gap, while T-matrix and Abelès methods diverged rapidly.
  • Solar Application: The toolkit successfully calculates the short-circuit current ($j_{sc}$) for amorphous silicon solar cells, demonstrating how a simple anti-reflective coating can boost absorptance from ~50% to over 85% across the visible spectrum.

Limitations and Future Work

The authors acknowledge a few areas for expansion:

  • Mode Tracking: The current steepest-descent method for finding guided modes, while reliable, is not necessarily the most efficient compared to more advanced contour integration techniques.
  • Material Models: Future versions aim to include more advanced material descriptions, such as spatial dispersion in metals, which becomes important at the nanoscale.
  • Optimization Integration: While PyMoosh is designed to be used with optimization libraries, the authors plan to demonstrate more seamless integration with advanced inverse design algorithms in future publications.

Summary updated

Abstract

We present PyMoosh, a Python-based simulation library designed to provide a comprehensive set of numerical tools allowing the computation of essentially all optical characteristics of multilayered structures, ranging from reflectance and transmittance to guided modes and photovoltaic efficiency. PyMoosh is designed not just for research purposes, but also for use cases in education. To this end, we have invested significant effort in ensuring the user-friendliness and simplicity of the interface. PyMoosh has been developed in line with the principles of open science and considering the fact that multilayered structures are increasingly being used as a testing ground for optimization and deep learning approaches. We provide in this paper the theoretical basis at the core of PyMoosh, an overview of its capabilities, as well as a comparison between the different numerical methods implemented in terms of speed and stability. We are convinced such a versatile tool will be useful for the community in many ways.
BibTeX
@article{langevin2023pymoosh,
  author = {Denis Langevin and Pauline Bennet and Abdourahman Khaireh-Walieh and Peter R. Wiecha and Olivier Teytaud and A. Moreau},
  title = {{PyMoosh: a comprehensive numerical toolkit for computing the optical properties of multilayered structures}},
  journal = {Journal of the Optical Society of America B},
  year = {2023},
  doi = {10.1364/josab.506175},
}
Figure