Skip to content

Fix multiple bugs - #101

Merged
lbolla merged 60 commits into
masterfrom
fix/bugs
Nov 20, 2026
Merged

lbolla merged 60 commits into
masterfrom
fix/bugs

Conversation

@lbolla

@lbolla lbolla commented Nov 15, 2026

Copy link
Copy Markdown
Owner

Summary

This PR resolves 24 runtime, physics/math, API, and script bugs across EMpy and updates dependency floors for modern NumPy/SciPy/Matplotlib compatibility.

Dependencies

  • Bump minimum dependency versions in pyproject.toml / uv.lock (numpy>=2.1, scipy>=1.13, matplotlib>=3.8.4).

Runtime & Python 3 Compatibility Fixes

  • devices.py / FMM.py: Fix Etalon, SWG, and FMM1d/FMM2d runtime crashes; fix FMMMode1dy.plot, FMMMode2d.TEfrac_old, and FMMMode2d.plot.
  • utils.py / geometries.py: Convert 1D refractive index arrays to scalars where expected; use integer division for slice indices; infer GenericDevice dimension from T; repair find_peaks indexing and Python 3 sorting; support Python 3 slice indexing on Multilayer; guard LiquidCrystalCell(nlayers < 3), short-circuit voltage == 0, and raise a clear ImportError if scikits.bvp1lg is missing.
  • FD.py / FMM.py: Fix FDMode.overlap grid alignment and FMMMode2d.overlap signature.
  • RCWA.py: Fix IsotropicRCWA ill-conditioned kx perturbation and missing raise.
  • scripts/FDTD.py / examples/ex_modesolver_2.py: Fix monitor formatting, shell spacing, integer array parsing, overlap_f dy step, and EMpy.utils.CrossSection typo.

Physics, Mathematical & Algorithmic Fixes

  • AnisotropicTransferMatrix.solve (transfer_matrix.py): Add analytical isotropic root fast-path and physics-based forward/backward root classification (fixing TIR double-root noise), compute all 4 eigenmodes via SVD nullspace for non-degenerate anisotropic layers, and compute R and T via exact $z$-Poynting flux.
  • FMM.py: Check slices[-1].boundary.xright instead of xleft in creaTeThSeSh; transpose fields passed to interp2 in FMMMode2d.get_fields_for_FDTD; allocate complex Delta in FMMshooting and FMMshootingTM.
  • RCWA.py: Handle evanescent/negative-discriminant roots cleanly in dispersion_relation_ordinary and dispersion_relation_extraordinary (including C[1] != 0), align phi docstring with xz-plane K, and support isotropic/x-uniaxial AnisotropicMaterial end layers in AnisotropicRCWA.
  • SymmetricDoubleGrating (utils.py): Place ridges with symmetric spacer width (1 - f1 - f2) / 2 instead of zero gap.
  • rix2losses (utils.py): Align absorption sign (alpha = -4 * pi * imag(n) / wl) with EMpy's n = nr - 1j * k convention.
  • SVFDModeSolver (FD.py): Map 'S'/'A' magnetic-field boundary symmetry signs separately for Ex vs Ey/scalar, matching VFDModeSolver.

API & State-Mutation Fixes

  • transfer_matrix.py: Support scalar wls via np.atleast_1d in both IsotropicTransferMatrix and AnisotropicTransferMatrix.
  • materials.py / scattering.py: Evaluate EpsilonTensor epsilon_tensor_known across multi-wavelength arrays and remove mutable default arguments.
  • devices.py: Avoid in-place mutation of self.K and self.l in T_TCRR.solve and T_CTCRR.solve.
  • scattering.py: Normalize stack input shapes, validate currentsScatteringKottler inputs with ValueError, support 1D/2D dS, and guard R == 0 self-terms.

Verification

  • pytest -q: 46 passed (including new unit tests for Fresnel/TIR energy conservation, birefringent mode coupling, dispersion relations, double-grating Fourier quadrature, SVFDModeSolver symmetry, and loss round-trips).
  • black, flake8, pyflakes, and mypy: all pass cleanly.

…0_known interpolation, and uniform RCWA kx shift
@lbolla
lbolla merged commit c347fa3 into master Nov 20, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant