Metadata-Version: 2.4
Name: lightsim
Version: 0.1.1
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: Environment :: GPU :: NVIDIA CUDA :: 13
Classifier: Operating System :: POSIX :: Linux
Classifier: Operating System :: MacOS
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Rust
Classifier: Topic :: Scientific/Engineering :: Physics
Requires-Dist: numpy>=1.24
Requires-Dist: scipy>=1.10
Requires-Dist: gdsfactory>=8 ; extra == 'gds'
Requires-Dist: matplotlib>=3.7 ; extra == 'plot'
Requires-Dist: thewalrus ; extra == 'quantum-crosscheck'
Requires-Dist: strawberryfields ; extra == 'quantum-crosscheck'
Requires-Dist: perceval-quandela ; extra == 'quantum-crosscheck'
Requires-Dist: pytest>=7 ; extra == 'test'
Requires-Dist: gdsfactory>=8 ; extra == 'test'
Requires-Dist: matplotlib>=3.7 ; extra == 'test'
Provides-Extra: gds
Provides-Extra: plot
Provides-Extra: quantum
Provides-Extra: quantum-crosscheck
Provides-Extra: test
License-File: LICENSE
Summary: Rust-native simulation engine for photonic chips: FDTD on GPUs, mode solvers, eigenmode expansion, finite elements, circuits, inverse design and quantum light, with a Python API
Keywords: fdtd,electromagnetics,maxwell,photonics,simulation,gpu,cuda,gdsfactory,inverse-design,adjoint,mode-solver,eigenmode-expansion,finite-elements,photonic-integrated-circuits,quantum-optics,boson-sampling
Author: SU3 Labs
License-Expression: MIT
Requires-Python: >=3.10
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Documentation, https://developer.su3labs.com/lightsim/docs/
Project-URL: Homepage, https://developer.su3labs.com/lightsim/
Project-URL: Issues, https://github.com/su3co/lightsim/issues
Project-URL: Repository, https://github.com/su3co/lightsim

# lightsim

[![docs](https://img.shields.io/badge/docs-developer.su3labs.com-blue)](https://developer.su3labs.com/lightsim/)
[![license: MIT](https://img.shields.io/badge/license-MIT-green)](https://github.com/su3co/lightsim/blob/main/LICENSE)
[![version 0.1.1](https://img.shields.io/badge/version-0.1.1-orange)](https://github.com/su3co/lightsim/blob/main/Cargo.toml)
[![rust](https://github.com/su3co/lightsim/actions/workflows/rust.yml/badge.svg)](https://github.com/su3co/lightsim/actions/workflows/rust.yml)
[![wheels](https://github.com/su3co/lightsim/actions/workflows/workflow.yml/badge.svg)](https://github.com/su3co/lightsim/actions/workflows/workflow.yml)

**Rust-native simulation engine for photonic chips, with a Python API.**

lightsim's core is a GPU-first FDTD solver. Around it are waveguide mode
solvers, eigenmode expansion, finite-element heat, electrostatics and modes,
circuit simulation and inverse design, all without external programs. On one
RTX PRO 6000 it runs at 22–27 Gcells/s, 2.2–2.4× faster than FDTDX from
17 M cells up ([benchmarks](https://github.com/su3co/lightsim/blob/main/docs/benchmarks.md)).

## Features

- **CUDA:** kernels written in Rust and compiled to PTX with NVIDIA's
  [cuda-oxide](https://github.com/NVIDIA/cuda-rust); one build runs on Ampere
  through Blackwell (tested on RTX PRO 6000 and GB10), on one GPU, several
  GPUs (peer-to-peer halos) or several machines (TCP halos).
- **Vulkan and Metal:** a portable GPU backend for AMD, Intel and NVIDIA GPUs
  through Vulkan and Apple GPUs through Metal (Rust kernels compiled to SPIR-V
  with rust-gpu, run through wgpu).
- **FDTD in 3-D and 2-D** on non-uniform meshes, with dispersive, nonlinear
  (χ², χ³), anisotropic and magneto-optic media, gain media and conducting
  sheets; CPML, Bloch and mirror-symmetry boundaries.
- **Inverse design:** adjoint gradients and exact gradients through reverse
  mode, density and shape optimisation.
- **RF and electro-optics:** antennas, transmission lines and RF circuits;
  the Pockels chain from the RF field to the optical response.
- **gdsfactory:** layout import, port-driven S-parameters, and
  `lightsim.gplugins` with the interface of gdsfactory's Meep plugin.
- **Process design kits:** load a fab's kit (gdsfactory, KLayout technology,
  lightsim's technology file, a licensed kit on disk) and simulate its cells.
- **Fabrication Monte Carlo:** width, thickness, etch, sidewall and overlay
  spreads and tiny defects (line-edge roughness, particles, missing
  elements) per sample, run in batches on CPUs and GPUs, with yield.
- **Quantum light** (`lightsim.quantum`): photons and Gaussian states through
  circuits built from simulated or measured S-matrices, with loss, partly
  distinguishable photons, sources, detectors and heralded gates; permanents
  and hafnians on CPUs and GPUs; gradients for inverse design.

## Install

```bash
pip install lightsim
```

Wheels for Linux (x86-64 and arm64: the CPU, NVIDIA GPUs through CUDA with
only the driver installed, and any GPU with a Vulkan driver) and macOS
(Apple silicon and Intel: the CPU and the Mac's GPU through Metal), for
Python 3.10 and newer. The package holds the Python API and the `lightsim`
command:

```bash
python -c "import lightsim; print(lightsim.__version__, lightsim.devices())"
lightsim info
```

From source (Rust 1.99.1; for NVIDIA GPUs, CUDA 13):

```bash
git clone https://github.com/su3co/lightsim && cd lightsim
pip install maturin
maturin develop --release                     # CPU only
maturin develop --release --features cuda     # with GPU support (NVIDIA, CUDA)
maturin develop --release --features vulkan   # portable GPU backend (metal on macOS)
cargo build --release -p lightsim-cli         # the `lightsim` program alone (same --features)
```

Details: [installation guide](https://developer.su3labs.com/lightsim/docs/guide/install/).

## Example

S-parameters of a gdsfactory component (`pip install "gdsfactory>=8"`), on a
laptop CPU in seconds:

```python
import gdsfactory as gf
import numpy as np
from lightsim.sparams import write_sparameters

gf.gpdk.PDK.activate()                               # gdsfactory's generic PDK
c = gf.components.straight(length=2)                 # 2 um of 500 x 220 nm silicon strip
sp = write_sparameters(c, wavelengths=np.linspace(1.5e-6, 1.6e-6, 5),
                       steps_per_wavelength=12, device="cpu")

print(sorted(k for k in sp if "@" in k))
print(np.round(np.abs(sp["o2@0,o1@0"]) ** 2, 3))     # power transmission o1 -> o2
print(round(sp["mode_neff"]["o1"].real, 3))          # effective index of the port mode
```

```text
['o1@0,o1@0', 'o1@0,o2@0', 'o2@0,o1@0', 'o2@0,o2@0']
[0.999 1.    1.    1.    0.999]
2.422
```

With `device="cuda:0"` the same call runs on a GPU. The
[quick start](https://developer.su3labs.com/lightsim/docs/guide/quickstart/)
continues with a simulation built by hand.

## Links

- [Documentation](https://developer.su3labs.com/lightsim/)
- [Benchmarks](https://github.com/su3co/lightsim/blob/main/docs/benchmarks.md)
- [Validation](https://github.com/su3co/lightsim/blob/main/docs/validation.md)
- [Features against Lumerical FDTD and FDTDX](https://github.com/su3co/lightsim/blob/main/docs/features.md)
- [Contributing](https://github.com/su3co/lightsim/blob/main/CONTRIBUTING.md)

MIT licence.

