EMpy - ElectroMagnetic Python
EMpy - ElectroMagnetic Python is a Python suite of numerical algorithms widely used in electromagnetism, photonics, and integrated optics: transfer matrix methods, rigorous coupled-wave analysis (RCWA), finite-difference and film-mode-matching waveguide mode solvers, coupled-resonator photonic circuits, liquid-crystal optics, and vector diffraction/scattering integrals.
Run the domain-organized scripts in examples/ (see examples/README.md for the full catalog of 22 literature benchmarks and cross-solver comparisons) to see how EMpy works in practice, and visit https://lbolla.github.io/EMpy/ for additional documentation.
What's New in 3.0
EMpy 3.0 is a comprehensive numerical and electrodynamic upgrade across the entire library (see CHANGELOG.md for full details):
- Unified Passive Electrodynamic Conventions: Consistent
exp(+iωt - ik·r)harmonic phase, passive complex refractive indexn = n_r - iκ(κ ≥ 0), passive branch-cut selection across total internal reflection (TIR), plasmonic, and lossy media, and complex-symmetric linear algebra throughout. - Stabilized Full-Wave & Multilayer Solvers: Rewritten 4 × 4 Yeh–Berreman
AnisotropicTransferMatrix(biaxial binormals, weak-birefringenceΔn → 0continuity, cross-mode Poynting flux), ETM-stabilizedAnisotropicRCWAwith Li's inverse-rule factorization, scale-invariantFMM1d/FMM2d(SI meters & microns), and Redheffer star-product S-matrix cascades (GenericDevice, passive & Lorentz-reciprocalSimpleJoint). - Out-of-the-Box Liquid Crystals & Modern Stack:
LiquidCrystalCellnow solves coupled 1D Oseen–Frank elastic + electrostatic BVPs natively viascipy.integrate.solve_bvp(no legacyscikits.bvp1lgdependency required), targeting Python 3.10–3.14, NumPy 2.x, and SciPy 1.13+. - 22 Literature Benchmarks & Rigorous Verification: Reorganized 7-domain
examples/suite with literature citations and an 85-test physics/invariant verification suite (Δn → 0,κ → 0⁺, unitarity, passivity, reciprocity).
Implemented Algorithms
- Transfer Matrix Method (
EMpy.transfer_matrix):IsotropicTransferMatrix: 2 × 2 characteristic-matrix solver for s- and p-polarized plane waves in isotropic multilayers, including absorbing media, total internal reflection (TIR), and surface-plasmon resonance (SPR) geometries.AnisotropicTransferMatrix: 4 × 4 Yeh–Berreman solver for arbitrarily oriented uniaxial, biaxial, twisted-nematic, and lossy anisotropic multilayers, solving the first-order Berreman eigenproblem with SVD nullspace polarization vectors, biaxial optic-axis / binormal degeneracy orthogonalization, and cross-mode-interference Poynting flux.
- Rigorous Coupled-Wave Analysis (
EMpy.RCWA):IsotropicRCWA: Planar and conical diffraction solver for multilayer surface-relief gratings (BinaryGrating,SymmetricDoubleGrating,AsymmetricDoubleGrating) based on Moharam's formulation, Lalanne's TM Fourier factorization, and Enhanced Transmittance Matrix (ETM) stabilization.AnisotropicRCWA: 3D vector coupled-wave solver for arbitrarily Euler-rotated anisotropic gratings with isotropic or uniaxial end layers, Li's inverse-rule Fourier factorization for discontinuous permittivity tensors, and ETM recursion for thick high-order stacks.
- Waveguide Mode Solvers & Junctions (
EMpy.modesolvers):FD(SVFDModeSolver,VFDModeSolver): Semivectorial and full-vectorial 2D finite-difference mode solvers on non-uniform staggered grids, supporting symmetry walls, 5-component anisotropic permittivity tensors, complex-coordinate-stretching PML boundaries (stretchmesh), and shift-invert ARPACK eigensolvers.FMM(FMM1d,FMM2d): Scale-invariant 1D slab and 2D channel waveguide Film Mode Matching solvers (supporting both SI meters and microns) expanding fields in slice eigenmodes with overflow-free evanescent inner products and analytical sub-cell Poynting overlaps.geometries&interface(SWG,SimpleJoint,GenericDevice): Mode-matching S-matrix junctions (offering both passive conjugated-Poynting mode matching and Lorentz-reciprocal unconjugated-reaction mode matching, including cross-solverFDMode↔FMMMode2doverlaps), stabilized multi-element Redheffer star-product S-matrix cascades (GenericDevice) for sub-cutoff and long lossy waveguides, and staggered-grid FDTD mode-overlap helpers (scripts/FDTD.py).
- Photonic Devices, Scattering, Materials & Liquid Crystals (
EMpy.devices,EMpy.scattering,EMpy.materials,EMpy.utils):devices: Transfer- and chain-matrix models for directional couplers (Coupler), delay lines (Line), Mach–Zehnder interferometers (MZ), single and N-coupled ring resonators (APRR,SRR,NRR), tunable multi-coupler ring filters (T_TCRR,T_CRTCRR,T_CTCRR), dispersive/lossy Fabry–Pérot cavities (Etalon), and silicon strip waveguide dispersion (SWG).scattering: 3D Kottler–Stratton–Chu vector surface-current radiation and scattering integral (currentsScatteringKottler).materials&utils: Constant, polynomial, Sellmeier, tabulated (interpolated), and thermo-opticIsotropicMaterial,AnisotropicMaterial, andLiquidCrystalmodels, together withLiquidCrystalCell(coupled 1D Oseen–Frank elastic free-energy and Laplace electrostatic BVP solver with pretilt, twist, chiral pitch, and voltage).
Testing & Verification Strategy
EMpy's test suite (tests/) validates numerical implementations against analytical electrodynamics and physical invariants:
- Consistent Harmonic & Passive Loss Convention:
- All solvers follow
exp(+iωt - ik·r)with passive complex refractive indexn = n_r - iκ(κ ≥ 0), passive square-root branch selection (Re(k_z) - Im(k_z) ≥ 0) across propagating, evanescent/TIR, and negative-ε_rregimes, and general complex-symmetric linear algebra (M = Mᵀ) without spurious Hermitian conjugation.
- All solvers follow
- Conservation Laws, Passivity & Reciprocity:
- Lossless structures: Exact energy conservation and unitarity (
R + T = 1,sum(DE1 + DE3) = 1,Sᴴ S = I,|THRU|² + |DROP|² = 1). - Passive lossy structures (
κ > 0): Strict passivity (R + T ≤ 1,‖S‖₂ ≤ 1, Beer–Lambert modal attenuation|exp(-iβL)| < 1) and Lorentz reciprocity (S = Sᵀwheneverε = εᵀ).
- Lossless structures: Exact energy conservation and unitarity (
- Degenerate-Limit Continuity (
AGENTS.md):- Anisotropic → Isotropic (
Δn → 0): Every anisotropic solver (AnisotropicMaterial,LiquidCrystalCell,AnisotropicTransferMatrix,AnisotropicRCWA, 5-componentVFDModeSolver) is tested against the corresponding isotropic solver both via explicit isotropic tensors (ε = ε₀ n² I₃bypassingisIsotropic()shortcuts) and along weak-birefringence sequences (Δn ∈ {1e-4, 1e-8, 0}) with arbitrary 3D Euler rotations, optic-axis / binormal degeneracies, normal-incidence azimuthal limits (α → 0⁺, δ ≠ 0), andn = 0/ homogeneous grating limits. - Lossy → Lossless (
κ → 0⁺): Lossy code paths are tested both at complex zero-loss dtype (n = n_r + 0.0j) and along continuousκ → 0⁺sequences against strictly real lossless paths across propagating, sub-cutoff, PML, and TIR regimes.
- Anisotropic → Isotropic (
- Independent Cross-Solver & Analytical Benchmarks:
- Verified against Fresnel/Brewster/Airy equations, Kretschmann SPR dips, Jones waveplate calculus, Gooch–Tarry twisted-nematic transmission, Rytov subwavelength effective-medium theory, 1D slab dispersion relations, 2D Gauss–Legendre quadrature, and pointwise Maxwell curl/divergence equations, as well as CI runs across Python 3.10–3.14,
lowest-directdependency bounds, and allexamples/**/ex_*.pyscripts.
- Verified against Fresnel/Brewster/Airy equations, Kretschmann SPR dips, Jones waveplate calculus, Gooch–Tarry twisted-nematic transmission, Rytov subwavelength effective-medium theory, 1D slab dispersion relations, 2D Gauss–Legendre quadrature, and pointwise Maxwell curl/divergence equations, as well as CI runs across Python 3.10–3.14,
Installation
Requires Python >= 3.10:
pip install ElectroMagneticPython
Note:
LiquidCrystalCellsolves the 1D Oseen–Frank liquid-crystal boundary-value problem out of the box usingscipy.integrate.solve_bvp(and will only use the legacyscikits.bvp1lgpackage if explicitly installed).
Development
Download the source code from https://github.com/lbolla/EMpy.
EMpy is managed with uv (https://docs.astral.sh/uv/).
Install the development environment:
make develop
Run tests and linters (black --check, flake8, pyflakes, mypy):
make test
make lint
Format code with black:
make black
Run an example script (see examples/README.md for all categories):
uv run examples/devices/ex_ring_resonators_aprr_srr_nrr.py
Upgrade locked dependencies:
make upgrade
Release process
Package versioning is managed with bump2version and setuptools_scm:
make release PART=patch # PART=[major|minor|patch]
Pushing the version tag triggers GitHub Actions to build and publish the package to PyPI.
References
- D. W. Berreman, "Optics in stratified and anisotropic media: 4 × 4-matrix formulation," J. Opt. Soc. Am. 62(4), 502–510 (1972).
- P. Yeh, "Electromagnetic propagation in birefringent layered media," J. Opt. Soc. Am. 69(5), 742–756 (1979); Optical Waves in Layered Media (Wiley, 1988).
- E. N. Glytsis and T. K. Gaylord, "Three-dimensional (vector) rigorous coupled-wave analysis of anisotropic grating diffraction," J. Opt. Soc. Am. A 7(8), 1399–1410 (1990).
- M. G. Moharam, E. B. Grann, D. A. Pommet, and T. K. Gaylord, "Formulation for stable and efficient implementation of the rigorous coupled-wave analysis of binary gratings," J. Opt. Soc. Am. A 12(5), 1068–1076 (1995).
- M. G. Moharam, D. A. Pommet, E. B. Grann, and T. K. Gaylord, "Stable implementation of the rigorous coupled-wave analysis for surface-relief gratings: enhanced transmittance matrix approach," J. Opt. Soc. Am. A 12(5), 1077–1086 (1995).
- P. Lalanne and G. M. Morris, "Highly improved convergence of the coupled-wave method for TM polarization," J. Opt. Soc. Am. A 13(4), 779–784 (1996).
- L. Li, "Use of Fourier series in the analysis of discontinuous periodic structures," J. Opt. Soc. Am. A 13(9), 1870–1876 (1996); "Reformulation of the Fourier modal method for surface-relief gratings made with anisotropic materials," J. Mod. Opt. 45(7), 1313–1334 (1998).
- A. B. Fallahkhair, K. S. Li, and T. E. Murphy, "Vector finite difference modesolver for anisotropic dielectric waveguides," J. Lightwave Technol. 26(11), 1423–1431 (2008).
- A. S. Sudbø, "Film mode matching: a versatile numerical method for vector mode field calculations in dielectric waveguides," Pure Appl. Opt. 2(3), 211–233 (1993); "Improved formulation of the film mode matching method for mode field calculations in dielectric waveguides," Pure Appl. Opt. 3(3), 381–388 (1994).
- O. Schwelb, "Transmission, group delay, and dispersion in single-ring optical resonators and add/drop filters—a tutorial overview," J. Lightwave Technol. 22(5), 1380–1394 (2004).
- G. Barbarossa, A. M. Matteo, and M. N. Armenise, "Theoretical analysis of triple-coupler ring-based optical guided-wave resonator," J. Lightwave Technol. 13(2), 148–157 (1995).
- C. H. Gooch and H. A. Tarry, "The optical properties of twisted nematic liquid crystal structures with twist angles ≤ 90°," J. Phys. D: Appl. Phys. 8(13), 1575–1584 (1975).
- F. Kottler, "Elektromagnetische Theorie der Beugung an schwarzen Schirmen," Ann. Phys. 376(15), 457–508 (1923); J. A. Stratton and L. J. Chu, "Diffraction theory of electromagnetic waves," Phys. Rev. 56(1), 99–107 (1939).
- S. M. Rytov, "Electromagnetic properties of a finely stratified medium," Sov. Phys. JETP 2(3), 466–475 (1956).
Citation
If you find EMpy useful in your job, please consider adding a citation.
As reference:
Bolla, L. (2017). EMpy [Computer software]. https://github.com/lbolla/EMpy/
As text:
We used EMpy (version x.y.z) to complete our work.
Metadata
Release files for ElectroMagneticPython 3.0.0
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 |
|---|---|---|---|---|
| electromagneticpython-3.0.0.tar.gz | 314.5 kB | Without provenance | Details for electromagneticpython-3.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| electromagneticpython-3.0.0-py3-none-any.whl | Python 3 | none | any | Details for electromagneticpython-3.0.0-py3-none-any.whl |
Total release size: 533.3 kB
Release files / electromagneticpython-3.0.0.tar.gz
| Download URL | electromagneticpython-3.0.0.tar.gz |
|---|---|
| Size | 314.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8f10e80172365d7171c98a5fed5567e0f72c153f4b26679c6c11618f2a2a835e
|
|
BLAKE2b-256 checksum How to use checksums |
a4030ac9fde1fce30b5f7200608c24de033a767a296aa912ac49fe466d9a30a1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / electromagneticpython-3.0.0-py3-none-any.whl
| Download URL | electromagneticpython-3.0.0-py3-none-any.whl |
|---|---|
| Size | 218.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e67bd90a08ff5297f804017ad2f87fb843db4a8995a76db0ffee735abd7b6125
|
|
BLAKE2b-256 checksum How to use checksums |
0e76c08a54f46cbfd51c41ace6a87d9dd30ac124089f969627046fbedefaedf0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for ElectroMagneticPython 3.0.0
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.