Motivation¶
Transfer Matrix Method (TMM) is a technique used to model multilayer optical thin-films, where the path of light incident on the film is determined using Snell’s law, and the transmittance and reflectance coefficients at interfaces between different materials are calculated using the Fresnel equations.
In TMM, the optical behavior of a multilayer structure composed of dielectric materials is obtained by computing the system matrix \(\mathbf{M}\), as shown in Equation (1). This matrix calculation, commonly referred to as the Abeles TMM [1], results from the successive multiplication of the transfer matrices of each layer and interface [2] as expressed in Equation (2). Each layer is represented as \(\mathbf{M}_i = \mathbf{I}_i \mathbf{P}_i\), where \(\mathbf{I}_i\) denotes the interface matrix and \(\mathbf{P}_i\) represents the propagation matrix that describes the light propagation through the \(i\) th layer. The interface matrix \(\mathbf{I}_i\) contains terms that depend on the reflection and transmission coefficients at the boundary between the \(i\) th and \((i+1)\) th layers.
As can be seen in Equation (3) and Equation (4), its elements, \(\alpha_{i,i+1}\) and \(\gamma_{i,i+1}\), vary depending on the polarization of the incoming light. The propagation matrix \(\mathbf{P}_i\) characterizes the optical phase accumulated by the electromagnetic wave as it traverses the \(i\) th layer. As detailed in Equation (5), the accumulated phase \(\delta_i\) is given by \(\delta_i = \frac{2\pi}{\lambda} n_i d_i \cos\theta_i\), where complex-valued \(n_i\) is the sum of the refractive index and extinction coefficient of the layer, \(d_i\) is the layer thickness, \(\theta_i\) is the angle of incidence, and \(\lambda\) is the wavelength of the incoming light [3]. Finally, the elements of the resulting system matrix \(\mathbf{M}\) yield the reflection and transmission properties of the optical coating formed by the stack of layers [4]. The TMM relies fundamentally on matrix–matrix multiplications and linear transformations, both of which are computationally efficient operations [5]. Owing to the inherently structured nature of these calculations [6], the overall simulation workflow benefits substantially from hardware-level acceleration via vectorization and parallelization. This makes TMM particularly well suited for high-throughput modeling [7] and optimization of multilayer optical coatings, where rapid evaluation across a wide parameter space is essential [8]. However, in currently implemented TMM packages [9] [10] [11], the angle of incidence and wavelength of the incoming light are typically treated as scalar inputs, rather than as vectorized parameters.
Schematic representation of two implementation strategies for calculating transmission, reflection, and absorption in multilayer thin-film simulations. A multilayer system composed of stacked layers (a) is modeled by traditionally computing the optical response sequentially through multiplication of a chain of 2×2 transfer matrices for each wavelength and angle of incidence (b). In contrast, the vectorized approach (c) performs the same computation by vectorizing the operations along both the wavelength and angle-of-incidence axes.¶
The simulation of the stack of layers, as shown in Figure 1a, is performed by taking only a single wavelength and angle of incidence value, as illustrated in Figure 1b, and consequently, in an traditional TMM implementation, a single function call returns transmittance, reflectance, and absorbance for only one wavelength and one angle of incidence. In scalar implementations of the TMM, two nested loops are typically employed to simulate the optical response of thin-films over arrays of wavelengths and angles of incidence [9]. In addition to this, redundant computations frequently arise. For example, when investigating the optical characteristics of a thin-film at multiple angles of incidence for a fixed wavelength, the wavelength-dependent component of the wavevector along the propagation direction, \(k_z\), is recalculated. This approach is highly inefficient, as these redundant recalculations significantly increase computational cost without improving accuracy. To eliminate these redundant calculations, wavelength and angle of incidence should be considered as vectors rather than scalars, and by performing vectorization, the two nested for loops can be eliminated. In TMMax, we vectorize wavelength and angle of incidence using the JAX library [12]. As seen in the schematic of the vectorized implementation in Figure 1c, we vectorize all intermediate operations in TMM and subsequently apply the JAX’s just-in-time (JIT) decorator. Instead of running the mapped TMM code sequentially over each batch element of wavelength and angle of incidence, jax.jit fuses all operations across the batch into a single XLA-compiled [13] kernel. This reduces function call overhead and provides a faster TMM implementation.
The chain of matrices is multiplied using a for loop to obtain the overall system matrix in the TMM, as expressed in Equation (1). However, the for loop inherently involves carry-over dependencies that limit computational efficiency in calculating the system matrix; fortunately, more advanced computational strategies can be used to mitigate such inefficiencies [14]. In TMMax, we eliminate this carry-over for loop by employing the scan function within the lax module of the JAX. The lax module is a Python wrapper that enables the execution of primitives written in XLA within Python. In this way, we achieve a faster TMM by removing the for loop from the code, vectorizing the computations, applying JIT compilation transformations, and thus preventing the TMM from entering the for loop, thereby avoiding interpreter bottlenecks. Moreover, most of the implemented TMM libraries operate on CPUs and the computation of the system matrix over a specified wavelength and angle of incidence range typically relies on sequential for loops, which iterate across the spectral and angular domains to evaluate transmittance and reflectance. This inherently limits computational efficiency due to the serial nature of the execution. While this sequential execution remains efficient for thin-films with a limited number of layers, its performance degrades considerably as the layer count increases. For example, simulating a 100-layer structure becomes computationally intensive due to backend bottlenecks, where the prolonged runtime of for loops leads to significant processing delays. However, these delays can be effectively mitigated in TMM because calculations for different angles of incidence and wavelengths are inherently parallelizable and non-recursive. Therefore, TMM is inherently suitable for parallelization and can run on platforms such as GPUs and TPUs. For this reason, we implement TMMax with the JAX, thereby obtaining a backend-agnostic TMM. In other words, we enable TMMax to run seamlessly on CPUs, GPUs and TPUs without any code modification. Additionally, we facilitate deep learning–based inverse design involving TMM by performing all calculations on the GPU, eliminating the need for data transfer back to the CPU [15].
Automatic differentiation holds a crucial role in optimization problems because it computes derivatives required for optimization both accurately and efficiently, unlike finite difference methods which approximate derivatives and can suffer from truncation and round-off errors [16]. This approximation arises because finite differences estimate derivatives by evaluating small perturbations in parameters, which inherently limits precision. In the design process of systems such as multilayer thin-films, minimizing the loss function over physical parameters (thickness, refractive index, etc.) is necessary [17], and gradients play a critical role at this stage. Conventional TMM implementations are written using libraries like NumPy [18] that do not natively support automatic differentiation. For example, if automatic differentiation is desired in such NumPy-based implementations, an additional library such as Autograd [19] must be used, which increases the implementation complexity of the code. TMMax, however, is designed according to the functional programming principles with JAX, enabling effortless gradient computation. Furthermore, TMMax can be integrated with the Optax library [20], a gradient processing and optimization library built on JAX that offers a wide range of optimization functions and procedures. This integration enables direct computation of derivatives with respect to thin-film parameters, such as layer thicknesses and material properties, thereby facilitating efficient gradient-based inverse design. As a result, these gradients can be utilized by advanced optimization algorithms, such as L-BFGS [21] and Adam [22], to rapidly converge toward optimal thin-film configurations. Consequently, layered structures can be rapidly designed to achieve targets such as optical reflectivity or transmittance.
The majority of implemented TMM packages focus exclusively on the calculation of the system matrix [17] [23] . However, these libraries generally lack a material database or offer only limited material data. This deficiency requires users to manually add their own refractive index and extinction coefficient data, which is both time-consuming and prone to errors. Furthermore, the accuracy of calculations performed with TMM directly depends on the reliability of the refractive index and extinction coefficient data used; if the material data is inaccurate, the simulation deviates from the experimentally obtained optical response. Therefore, in TMMax, we integrate a database of 30 widely used materials for multilayer optical thin-film fabrication. These materials are selected based on commonly used ones referenced in the reference book Thin-Film Optical Filters by H. Angus Macleod [3]. The refractive index data were carefully gathered from refractiveindex.info [24], a trusted online database that collects optical properties from many scientific papers and verifies each entry against the original sources to ensure accuracy and reliability.The source of the material information for each study is documented in the “README.md” file located in the “database_info” folder of the library, and we designed the TMMax material database as a dynamic, living ecosystem. To facilitate collaborative growth, we implemented user-friendly helper functions that support the straightforward addition of refractive index and extinction coefficient data from external laboratories into the TMMax database. By contributing data through these tools and submitting pull requests to the TMMax GitHub repository, we foster a community-driven platform that continually expands and enriches shared material knowledge for the thin-film coating community.
References¶
Abelès, Florin. Recherches sur la propagation des ondes électromagnétiques sinusoïdales dans les milieux stratifiés - application aux couches minces. Ann. Phys., 12(5):596–640, 1950. URL: https://doi.org/10.1051/anphys/195012050596, doi:10.1051/anphys/195012050596.
Charalambos C Katsidis and Dimitrios I Siapkas. General transfer-matrix method for optical multilayer systems with coherent, partially coherent, and incoherent interference. Applied optics, 41(19):3978–3987, 2002.
Bernd Harbecke. Coherent and incoherent reflection and transmission of multilayer structures. Applied Physics B, 39(3):165–170, 1986.
Sergey A. Dyakov, Vladimir A. Tolmachev, Ekaterina V. Astrova, Sergey G. Tikhodeev, Viktor Yu. Timoshenko, and Tatiana S. Perova. Numerical methods for calculation of optical properties of layered structures. In Kamil A. Valiev and Alexander A. Orlikovsky, editors, International Conference on Micro- and Nano-Electronics 2009, volume 7521, 75210G. International Society for Optics and Photonics, SPIE, 2010. URL: https://doi.org/10.1117/12.862566, doi:10.1117/12.862566.
Rudi Santbergen, Arno H.M. Smets, and Miro Zeman. Optical model for multilayer structures with coherent, partly coherent and incoherent layers. Opt. Express, 21(S2):A262–A267, Mar 2013. URL: https://opg.optica.org/oe/abstract.cfm?URI=oe-21-102-A262, doi:10.1364/OE.21.00A262.
Emanuele Centurioni. Generalized matrix method for calculation of internal light energy flux in mixed coherent and incoherent multilayers. Appl. Opt., 44(35):7532–7539, Dec 2005. URL: https://opg.optica.org/ao/abstract.cfm?URI=ao-44-35-7532, doi:10.1364/AO.44.007532.
Yu Shi, Wei Li, Aaswath Raman, and Shanhui Fan. Optimization of multilayer optical films with a memetic algorithm and mixed integer programming. Acs Photonics, 5(3):684–691, 2017.
Steven J. Byrnes. Multilayer optical calculations. 2020. URL: https://arxiv.org/abs/1603.02720, arXiv:1603.02720.
Pavel Dmitriev. PyTMM: python implementation of the transfer matrix method for optical simulations. 2017. Archived on Zenodo; accessed 2025‑07‑14. URL: https://github.com/kitchenknif/PyTMM, doi:10.5281/zenodo.1063716.
Filip Dominec. Transfer_matrix_method: python implementation of the transfer matrix method. https://github.com/FilipDominec/transfer_matrix_method, 2017. Accessed: 2025-07-14.
James Bradbury, Roy Frostig, Peter Hawkins, Matthew James Johnson, Chris Leary, Dougal Maclaurin, George Necula, Adam Paszke, Jake VanderPlas, Skye Wanderman-Milne, and Qiao Zhang. JAX: composable transformations of Python+NumPy programs. 2018. URL: http://github.com/jax-ml/jax.
OpenXLA Team. XLA: Accelerated Linear Algebra Compiler for Machine Learning. https://github.com/openxla/xla, 2023. Accessed: 2025-07-13. URL: https://github.com/openxla/xla.
Kazufumi Nishida, Yasuaki Ito, and Koji Nakano. Accelerating the dynamic programming for the matrix chain product on the gpu. In 2011 Second International Conference on Networking and Computing, volume, 320–326. 2011. doi:10.1109/ICNC.2011.62.
Ravi S. Hegde. Accelerating optics design optimizations with deep learning. Optical Engineering, 58(6):065103, 2019. URL: https://doi.org/10.1117/1.OE.58.6.065103, doi:10.1117/1.OE.58.6.065103.
Atilim Gunes Baydin, Barak A Pearlmutter, Alexey Andreyevich Radul, and Jeffrey Mark Siskind. Automatic differentiation in machine learning: a survey. Journal of machine learning research, 18(153):1–43, 2018.
Alexander Luce, Ali Mahdavi, Florian Marquardt, and Heribert Wankerl. Tmm-fast, a transfer matrix computation package for multilayer thin-film optimization: tutorial. J. Opt. Soc. Am. A, 39(6):1007–1013, Jun 2022. URL: https://opg.optica.org/josaa/abstract.cfm?URI=josaa-39-6-1007, doi:10.1364/JOSAA.450928.
Charles R. Harris, K. Jarrod Millman, Stéfan J van der Walt, Ralf Gommers, Pauli Virtanen, David Cournapeau, Eric Wieser, Julian Taylor, Sebastian Berg, Nathaniel J. Smith, Robert Kern, Matti Picus, Stephan Hoyer, Marten H. van Kerkwijk, Matthew Brett, Allan Haldane, Jaime Fernández del Río, Mark Wiebe, Pearu Peterson, Pierre Gérard-Marchant, Kevin Sheppard, Tyler Reddy, Warren Weckesser, Hameer Abbasi, Christoph Gohlke, and Travis E. Oliphant. Array programming with NumPy. Nature, 585:357–362, 2020. doi:10.1038/s41586-020-2649-2.
Dougal Maclaurin, David Duvenaud, and Ryan P Adams. Autograd: effortless gradients in numpy. In ICML 2015 AutoML workshop, volume 238. CNRS, 2015.
DeepMind, Igor Babuschkin, Kate Baumli, Alison Bell, Surya Bhupatiraju, Jake Bruce, Peter Buchlovsky, David Budden, Trevor Cai, Aidan Clark, Ivo Danihelka, Antoine Dedieu, Claudio Fantacci, Jonathan Godwin, Chris Jones, Ross Hemsley, Tom Hennigan, Matteo Hessel, Shaobo Hou, Steven Kapturowski, Thomas Keck, Iurii Kemaev, Michael King, Markus Kunesch, Lena Martens, Hamza Merzic, Vladimir Mikulik, Tamara Norman, George Papamakarios, John Quan, Roman Ring, Francisco Ruiz, Alvaro Sanchez, Laurent Sartran, Rosalia Schneider, Eren Sezener, Stephen Spencer, Srivatsan Srinivasan, Miloš Stanojević, Wojciech Stokowiec, Luyu Wang, Guangyao Zhou, and Fabio Viola. The DeepMind JAX Ecosystem. 2020. URL: http://github.com/google-deepmind.
Dong C Liu and Jorge Nocedal. On the limited memory bfgs method for large scale optimization. Mathematical programming, 45(1):503–528, 1989.
Diederik P. Kingma and Jimmy Ba. Adam: a method for stochastic optimization. 2017. URL: https://arxiv.org/abs/1412.6980, arXiv:1412.6980.
Leandro Acquaroli. Lnacquaroli/thinfilmstools.jl: v0.9.0. April 2022. URL: https://doi.org/10.5281/zenodo.6479354, doi:10.5281/zenodo.6479354.
Mikhail N Polyanskiy. Refractiveindex. info database of optical constants. Scientific Data, 11(1):94, 2024.
Mark Kness. Colorpy-a python package for handling physical descriptions of color and light spectra. The source package can be found at https://github. com/markkness/ColorPy, 2008.