Top level¶
api
¶
Top-level entry points: solve, estimate, compare, choose_method.
All accept any problem kind (see lightsmith.problems) as a model, dict or
JSON string.
AUTO_ORDER
module-attribute
¶
AUTO_ORDER: dict[str, tuple[str, ...]] = {'scattering': ('mie', 'tmatrix', 'dda', 'fdtd'), 'layer_stack': ('tmm', 'rcwa', 'fdtd'), 'periodic': ('rcwa', 'fdfd', 'fdtd'), 'mode': ('fde',), 'device': ('eme', 'fdfd', 'fdtd'), 'bands': ('pwe', 'fdfd'), 'circuit': ('circuit',), 'optimization': ('inverse',)}
solve
¶
Solve problem with one method (or backend name). device: auto | cpu | gpu | cuda:N | torch-cpu.
estimate
¶
estimate(problem: BaseModel | dict | str, method: str = 'auto', device: str = 'auto') -> dict[str, Any]
Pre-flight: which backend would run, on what device, and roughly how big. Never solves.
compare
¶
compare(problem: BaseModel | dict | str, methods: list[str] | None = None, device: str = 'auto', reference: str | None = None) -> dict[str, Any]
Solve with several methods and report relative differences against a reference.
By default runs every available backend that supports problem, using Mie as the
reference for scattering when it applies (otherwise the first result).
device
¶
CPU/GPU device selection via the Python array API standard.
Native solvers are written once against the array API (through
array_api_compat) and run on NumPy (CPU), PyTorch (CPU/CUDA/ROCm) or CuPy
(CUDA). Install a GPU framework with uv sync --extra gpu.
Device
dataclass
¶
doctor
¶
Report which array frameworks and GPUs are usable. Safe to call anywhere.
resolve_device
¶
resolve_device(device: str = 'auto') -> Device
Map a user-facing device string to a concrete :class:Device.
"auto" picks a CUDA GPU when one is usable, else CPU.
"gpu"/"cuda"/"cuda:N" require a GPU and raise with install hints otherwise.
"torch-cpu" runs the native solvers through PyTorch on the CPU.