Skip to content

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: BaseModel | dict | str, method: str = 'auto', device: str = 'auto') -> BaseModel

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).

choose_method

choose_method(problem: BaseModel | dict | str) -> tuple[type[Backend], list[str]]

Pick the preferred available backend for problem; also return why others were skipped.

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

Device(framework: str, name: str)

framework instance-attribute

framework: str

name instance-attribute

name: str

is_gpu property

is_gpu: bool

namespace

namespace() -> Any

native_device

native_device() -> Any

asarray

asarray(a, dtype=None)

to_numpy staticmethod

to_numpy(a) -> ndarray

describe

describe() -> dict[str, Any]

doctor

doctor() -> dict[str, Any]

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.