How do I run EME locally?#
Date |
Category |
|---|---|
2026-04-23 12:00:00 |
EME |
An tidy3d.EMESimulation can be run end-to-end on a local machine by pairing it with the local mode solver. EMESimulation.mode_simulations yields one tidy3d.ModeSimulation per EME cell, and EMESimulation.propagate turns the mode results into the device S-matrix.
Prerequisites#
EMESimulation.mode_simulations is available without any extra license and returns one ModeSimulation per EME cell. Turning those mode results into an S-matrix — via EMESimulation.propagate, EMESimulation.compute_overlaps, EMESimulation.propagate_from_overlaps, or the per-element staged helpers — requires the optional tidy3d-extras package with the local_eme feature. Install with pip install "tidy3d[extras]"; see the extras plugin page for details.
One-shot#
mode_data = [ms.run_local() for ms in sim.mode_simulations]
smatrix = sim.propagate(mode_data)
Cloud-parallel mode solves#
Pass the per-cell ModeSimulation objects to web.run as a dict keyed by cell index. web.run preserves dict keys as task names in the returned mapping, so the results can be read back in canonical EME cell order and fed to propagate:
from tidy3d import web
mode_sims = {f"cell_{i}": ms for i, ms in enumerate(sim.mode_simulations)}
results = web.run(mode_sims, task_name="eme_local_modes")
mode_data = [results[f"cell_{i}"] for i in range(len(mode_sims))]
smatrix = sim.propagate(mode_data)
Reusing overlaps across sweep variants#
Overlap integrals dominate the cost of propagation and are sweep-invariant under tidy3d.EMELengthSweep, tidy3d.EMEModeSweep, and tidy3d.EMEPeriodicitySweep. For iterative design on the same modal basis, compute them once with EMESimulation.compute_overlaps and replay them through EMESimulation.propagate_from_overlaps:
import tidy3d as td
cell_overlaps, interface_overlaps = sim.compute_overlaps(mode_data)
# Reuse the overlaps across sweep configurations without re-solving modes.
smatrix = sim.propagate_from_overlaps(cell_overlaps, interface_overlaps)
swept = sim.updated_copy(sweep_spec=td.EMELengthSweep(scale_factors=[0.5, 1.0, 2.0]))
smatrix_swept = swept.propagate_from_overlaps(cell_overlaps, interface_overlaps)
Full staged pipeline#
For finer control — for example, to checkpoint intermediates to HDF5 or run individual stages out-of-order — each pipeline element is exposed as its own method. The stage artifacts they return (EMEStageCellModes, EMEStageCellOverlap, EMEStageInterfaceOverlap, EMEStageCellSMatrix, EMEStageInterfaceSMatrix) are all HDF5-serializable, so any subset of the pipeline can be cached to disk and replayed later:
# Stage 1: per-cell mode data → validated, filtered cell-mode artifacts.
mode_data = [ms.run_local() for ms in sim.mode_simulations]
cell_modes = [sim.stage_cell_modes(md, cell_index=i) for i, md in enumerate(mode_data)]
# Stage 2: overlap integrals (per cell and per interface).
cell_overlaps = [sim.compute_cell_overlap(cm) for cm in cell_modes]
iface_overlaps = [
sim.compute_interface_overlap(cell_modes[li], cell_modes[ri])
for li, ri in sim.cell_index_pairs
]
# Stage 3: per-element S-matrices, then stacked device S-matrix.
cell_sms = [sim.compute_cell_smatrix(co) for co in cell_overlaps]
iface_sms = [
sim.compute_interface_smatrix(cell_overlaps[li], cell_overlaps[ri], io)
for (li, ri), io in zip(sim.cell_index_pairs, iface_overlaps)
]
smatrix = sim.compute_smatrix(cell_overlaps, cell_sms, iface_sms)
To express the local S-matrix in another modal basis after propagate, propagate_from_overlaps, or compute_smatrix, use EMESimulation.smatrix_in_basis with the original port mode data and the replacement modes:
smatrix_custom = sim.smatrix_in_basis(
smatrix,
port_modes=(mode_data[0], mode_data[-1]),
modes2=output_modes,
)
Omit modes1 or modes2 for ports that should stay in the EME port-mode basis. For remote EME runs, use EMESimulationData.smatrix_in_basis on the returned simulation data instead.
Limitations#
The local path only produces the device S-matrix. EMESimulation.monitors (such as EMEFieldMonitor, EMEModeSolverMonitor, EMECoefficientMonitor) are dropped with a warning; run the simulation through the remote backend if you need monitor data.
The local path also does not support EMEFreqSweep — list target frequencies in EMESimulation.freqs and control reuse with EMEModeSpec.interp_spec instead. Anisotropic media in bent cells with bend_medium_frame="global" are also unsupported locally; use bend_medium_frame="co_rotating" or the remote backend.