Meep test suite ported to PSFDTD
18 of Meep's own end-to-end tests rewritten for PSFDTD and judged with Meep's reference values and error metrics; 16 of 18 pass.
Meep ships end-to-end tests that step fields and assert on numbers. This page reports what happens when those tests are rewritten for PSFDTD with the same cell, resolution, sources, monitors, run control and assertions, and judged with Meep's own reference values and error metrics. 16 of 18 ported tests pass. The two failures are real mismatches against Meep's regression values; their causes are described under Limitations and the tolerances were not relaxed to make them pass.
Setup
Source of the tests. Meep repository (NanoComp/meep) pinned at commit b7943593, python/tests and tests/*.cpp. All tests that step fields (or call the eigensolver) and check numbers were catalogued:
| Category | Count | Notes |
|---|---|---|
| End-to-end tests with numeric assertions | 237 | Python 160, C++ 77 |
| Immediately portable | 12 | plus 3 tests of which some variants are portable (planewave_1D normal incidence, refl_angular θ=0, second assertion of flux_2d) |
| Need a mode source / mode monitor | 9 | 4 of these were implemented |
| Blocked | 216 | most common missing features: MPB band solving 42, Bloch k≠0 / complex fields 39+, symmetry planes 22, time-domain field energy readout 32, cylindrical coordinates 17, CW source 15, Harminv 14, adjoint 13, material grids 13 |
| Not end-to-end (pure unit tests) | 284 | do not step fields |
Porting method.
- Cell and PML: Meep's PML is inside the cell, PSFDTD's is outside the region, so region = cell − 2 × PML thickness and layers = thickness × resolution; the grid points coincide with Meep's. The PML uses a quadratic profile equivalent to Meep's
mp.PML. - Source: the
meep_gaussianwaveform matches Meep'sGaussianSourcebit for bit. - 1D tests are emulated in 2D TM with one periodic cell along y.
- Run control:
run(until=T)counts steps with Meep's float32 time comparison;stop_when_fields_decayed/stop_when_energy_decayedare reproduced step by step from PSFDTD probe / energy-monitor traces, so the stop step is identical to Meep's.stop_when_flux_decayedis replaced by PSFDTD's own energy shutoff. - Modes: PSFDTD exports its smoothed ε and the Tidy3D local mode solver is run on it (same grid), so injected and projected modes are eigenmodes of the structure PSFDTD actually discretizes.
- Mirror symmetries in the original tests are only a Meep speed-up and are removed in the ports (Meep is still timed with the symmetries of the original test).
Tolerances. Each check records its error, the PSFDTD tolerance, Meep's own tolerance and its kind (meep-ref regression value, meep-live value printed by a live Meep run, analytic, self consistency). Meep's regression tolerances (for example places=7, 1e-8) only make sense for bit-level regression of Meep against itself; two different solvers differ at the 1e-4 to 1e-3 level. Regression-value checks therefore get a separate PSFDTD tolerance (flux spectra 1e-3 in Meep's metric, single values 1e-2 relative), fixed before the runs and not adjusted afterwards. Analytic and self-consistency checks use Meep's own tolerances.
Hardware and software. Apple M3 Max, macOS (macOS-26.6.2-arm64), run dated 2026-09-27. Meep 1.33.0-beta (conda-forge, double precision, single process; the original divide_parallel test uses 2 MPI processes). PSFDTD FP64 (same precision as Meep), run once with 1 thread and once with 12 threads; all check values are bit-identical between the two.
Results
Times are time-stepping wall clock on the Apple M3 Max. "Value" is the tightest check of that test. "Per cell·step" normalizes by the cells actually stepped (Meep's mirror symmetries reduce them, the ports do not use them), for the 1-thread run.
| Ported test | Result | Checks | Tightest check | Value | PSFDTD tol | Meep tol | Steps PSFDTD / Meep | Meep (s) | PSFDTD 1 / 12 threads (s) | Meep/PSFDTD time (1T / 12T) | Meep symmetry | Per cell·step |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
bend_flux | pass | 8/8 | bend: assertClose(expected, (f, trans, refl)[:20]) | 1.94e-04 | 1e-03 | 1e-03 | 10005 / 10005 | 1.19 | 0.83 / 0.47 | 1.4× / 2.5× | – | 1.4× |
chunks | FAIL | 0/1 | get_fluxes(tot_flux)[0] of sim2 (minus sim1) | 3.05e-01 | 2e-02 | 6e-10 | 16012 / 14010 | 0.78 | 0.30 / 0.31 | 2.6× / 2.5× | – | 3.0× |
divide_parallel | pass | 2/2 | total flux at f=0.5 | 5.31e-05 | 1e-02 | 3e-09 | 8400 / 8400 | 0.14 | 0.25 / 0.25 | 0.5× / 0.6× | ÷4 | 2.2× |
holey_wvg_cavity | pass | 1/1 | max over the 46 (freq, flux) pairs of Meep's assertClose ratio | 2.83e-05 | 1e-03 | 1e-10 | 10005 / 10005 | 0.92 | 1.03 / 1.12 | 0.9× / 0.8× | ÷2 | 1.8× |
geometry_center | pass | 1/1 | Ez(2,-1) at t=50 | 2.70e-08 | 1e-02 | 8e-07 | 2000 / 2000 | 0.21 | 0.12 / 0.07 | 1.7× / 3.0× | – | 1.7× |
time | pass | 2/2 | |meep_time() - 212 dt| | 8.88e-16 | 5e-08 | 5e-08 | 212 / 212 | 0.01 | 0.01 / 0.01 | 0.6× / 1.2× | ÷4 | 2.6× |
stop_flux_single | pass | 2/2 | len(fluxes) == 1 | 0.00e+00 | 0 | 0 | 2020 / – | – | 0.09 / 0.10 | – | – | – |
stop_flux_multi | pass | 2/2 | len(fluxes) == 3 | 0.00e+00 | 0 | 0 | 2020 / – | – | 0.10 / 0.10 | – | – | – |
stop_flux_long_run | pass | 1/1 | max |F_decayed / F_long - 1| | 5.82e-04 | 1e-03 | 1e-03 | 24020 / – | – | 1.08 / 1.07 | – | – | – |
bragg_transmission | pass | 2/2 | max_i errT_i (fmin/f_i)^2 | 7.02e-04 | 1e-02 | 1e-02 | 20000 / – | 0.10 | 0.05 / 0.06 | 1.7× / 1.7× | – | – |
pml1d_scaling | pass | 11/11 | refl(d=32) / refl(d=16) × 2^6 | 1.00e+00 | 1.1 | 1.1 | 168000 / – | 0.85 | 0.41 / 0.43 | 2.1× / 2.0× | – | – |
planewave_1d | pass | 8/8 | res 200: |line[z2] - p2| | 3.18e-02 | 8e-02 | 8e-02 | 150009 / 150009 | 7.91 | 1.03 / 1.03 | 7.7× / 7.6× | – | 7.7× |
refl_angular | pass | 1/1 | assertClose(R_meep, R_fresnel) | 1.82e-02 | 3e-02 | 3e-02 | 120004 / 120004 | 1.67 | 0.24 / 0.23 | 7.0× / 7.4× | – | 7.0× |
flux_2d | pass | 2/2 | max relative deviation from Meep's printed box1/box2 fluxes | 4.00e-03 | 1e-02 | – | 4160 / – | 0.32 | 0.06 / 0.06 | 5.3× / 5.5× | – | – |
mode_coeffs | FAIL | 7/8 | band 2 k (Tidy3D on PSFDTD ε) vs MPB 0.494353 | 1.27e-02 | 1e-02 | 1e-02 | 12000 / 12000 | 1.88 | 1.13 / 0.62 | 1.7× / 3.0× | ÷2 | 3.3× |
reciprocity | pass | 2/2 | | |S11|^2 - |S22|^2 | | 2.30e-17 | 5e-03 | 5e-03 | 38334 / 38334 | 1.81 | 1.63 / 1.62 | 1.1× / 1.1× | ÷2 | 2.2× |
reciprocity_kpoint | pass | 2/2 | | |S11|^2(+k) - |S11|^2(-k) | | 0.00e+00 | 5e-05 | 5e-05 | 30667 / 30667 | 2.71 | 3.05 / 1.39 | 0.9× / 2.0× | ÷2 | 1.8× |
linear_taper_2d | pass | 1/1 | | |c-|^2/|c+_inc|^2 - (-taper_flux/incident_flux) | | 2.37e-05 | 5e-05 | 5e-05 | 16012 / 16012 | 1.13 | 1.11 / 1.09 | 1.0× / 1.0× | ÷2 | 2.0× |
Notes on the table:
- Meep times cover every
Simulation.runof the original test, initialization excluded; for C++ tests the whole ported function. PSFDTD's first pass that locates Meep's stop step is not counted. - C++ drivers do not report step counts, so the Meep step count and "per cell·step" are blank there.
stop_flux_*: the installed Meep 1.33.0-beta does not yet havestop_when_flux_decayed(a newer API in the pinned commit), so Meep's original tests did not run and could not be timed.planewave_1d: Meep's original test runs 5 variants; only the two that correspond to the port (res 400 1D, res 200 one-pixel 3D) are timed.
No figures are produced by this benchmark; the reports are tables only.
Comparison
PSFDTD is compared against three kinds of reference, all taken from Meep's test files or from local Meep 1.33.0-beta runs on the same Apple M3 Max:
- Meep regression values.
geometry_center(2.7e-8) is inside Meep's own bit-level regression tolerance (8.3e-7), and thebend_fluxbend spectrum (1.9e-4) is inside Meep's tolerance (1e-3). The other regression checks differ at the 1e-5 to 1e-3 level, attributed to the different PML formulation and sub-pixel averaging; these pass the PSFDTD tolerance but not Meep's bit-level tolerance (for exampledivide_parallel5.31e-05 against a Meep tolerance of 3e-09,holey_wvg_cavity2.83e-05 against 1e-10). - Analytic and self-consistency checks use Meep's own tolerances and all pass: Bragg mirror 7e-4 against 0.01, PML thickness scaling as d^-6, Fresnel reflectance 1.8e-2 against 0.03, reciprocity to machine precision, taper mode/flux reflectance consistent to 2.4e-5 against 5e-5.
- Run control. For every Python test where step counts can be compared, the stop step equals Meep's, with the exception of
chunks(16012 vs 14010), where the PML behaviour itself differs.
Speed (Apple M3 Max, FP64, PSFDTD against serial Meep). Per cell·step, single-threaded PSFDTD is 1.4× to 7.7× faster than Meep. By wall clock, on tests where Meep uses symmetry planes the ratio is 0.5× to 1.9×, and 1.0× to 7.7× on the others. These grids are tiny (1e3 to 1e5 cells), so multithreading gives almost no benefit; throughput on larger problems is on the GPU performance page.
Limitations
Two of the 18 ported tests fail against Meep's regression values. They are left failing; the tolerances were not widened.
-
chunksfails (3.05e-01 against a PSFDTD tolerance of 2e-02). The test fills the PML with n = 3.5 and compares the scattered flux with Meep's regression value 86.908…. At resolution 10 there are only 2.9 cells per wavelength inside the PML, so the value is a discretization artifact of an under-resolved PML and depends on each code's PML scheme. Raising the resolution of the same configuration (local Meep 1.33 and PSFDTD runs; stop steps equal for res ≥ 20):Resolution Meep PSFDTD 10 (original test) 86.9 60.4 20 3.79 1.67 40 2.13 1.53 The source report states that both converge to about 1.5 to 2. Note that the two codes still differ at resolution 40 (2.13 vs 1.53); they are not shown to converge to the same number. PSFDTD cannot reproduce the res-10 value without copying Meep's PML scheme.
-
mode_coeffsfails one of 8 checks (1.27e-02 against 1e-02). The band-2 k reference 0.494353 comes from MPB and itself differs from the exact continuum slab mode 0.506161 by 1.2e-2. The mode computed on PSFDTD's smoothed ε is within 8.633e-04 of the exact value but 1.267e-02 from MPB. For band 1 the three agree: PSFDTD is 3.716e-04 from the exact value 0.607689 and 3.016e-03 from MPB's 0.604301. -
holey_wvg_cavitypasses in Meep's metric but has large pointwise differences at fringe minima. The stop step equals Meep's (10005).decay_by = 0.1truncates the ringing, so the spectrum carries fringes whose phase differs slightly between the codes: the relative error reaches ±15% at fringe minima, although that is only 3.6% of the maximum flux. In Meep's own metric the error is 2.8e-5. -
Small coverage of Meep's test suite. 18 tests are ported out of 237 catalogued end-to-end tests; 216 are blocked by missing features (listed in Setup). Not ported from the mode-source group:
test_kpoint_func,test_eigensource_normalization,test_dft_energy,test_gaussian_beam,test_grating_3d. Within ported tests some variants are skipped: the oblique-incidence (Bloch k) variant ofplanewave_1D, the time-domain energy-balance assertion offlux_2d, and Meep'scscale/get_eigenmodeamplitude checks inmode_coeffs. -
Regression checks use a looser PSFDTD tolerance than Meep's. Passing a regression check here means agreement at the 1e-3 (flux spectra) or 1e-2 (single values) level, not bit-level agreement with Meep.
-
Three tests have no Meep timing (
stop_flux_*), andstop_when_flux_decayedis replaced by PSFDTD's energy shutoff, so those ports test PSFDTD's own stopping rule and are self-consistency checks only. -
PSFDTD is slower than Meep by wall clock on some tests where Meep exploits mirror symmetry (
divide_parallel0.5× / 0.6×,holey_wvg_cavity0.9× / 0.8×,time0.6× with 1 thread,reciprocity_kpoint0.9× with 1 thread).
Porting these tests also exposed three PSFDTD bugs that were fixed: the CPML κ profile order (reflection fell as d^-4 instead of d^-6 when κ_max > 1), point-DFT interpolation not wrapping across a periodic boundary (NaN on a one-cell periodic axis), and backward mode sources flipping both J and M.
Reproduce
export MEEP_SRC=/path/to/meep # Meep sources at the pinned commit (test files)
export MEEP_PYTHON=/path/to/python # interpreter with meep; MEEP_MPI_PYTHON for the MPI build (divide_parallel)
TD=/path/to/python-with-tidy3d # the mode tests need tidy3d
PYTHONPATH=python $TD -m bench.meep_tests.run # all ported tests
PYTHONPATH=python $TD -m bench.meep_tests.run --only bend_flux --threads 1
PYTHONPATH=python $TD -m bench.meep_tests.run --meep # also run and time Meep's original tests
python3 -m bench.meep_tests.report bench/results/meep_tests/<stamp>/results.jsonReference: Meep, github.com/NanoComp/meep, commit b7943593.
Analytic and Meep correctness suite
Eight small 2D/3D problems checked against closed-form solutions, against Meep on an identical grid, and GPU-vs-CPU on an RTX 4090.
GPU performance and roofline
PSFDTD throughput on an RTX 4090 measured against the device's own memory-bandwidth and FMA limits, with CPU and Meep baselines.