A PyTorch based package for designing and analyzing optical devices, utilzing the Rigorous Diffraction Interface Theory (R-DIT).
Project description
TorchRDIT
TorchRDIT is an advanced software package designed for the inverse design of meta-optics devices, utilizing an eigendecomposition-free implementation of Rigorous Diffraction Interface Theory (R-DIT). It provides a GPU-accelerated and fully differentiable framework powered by PyTorch, enabling the efficient optimization of photonic structures.
This framework achieves up to 16.2× speedup compared to traditional inverse design methods based on Rigorous Coupled-Wave Analysis (RCWA). By integrating differentiable R-DIT with topology optimization techniques and neural networks (e.g., SIREN), TorchRDIT facilitates the design of complex meta-optics devices, including:
- Parameter-constrained and free-form meta-atoms.
- Reconfigurable photonic structures using optical phase-change materials.
- High-performance meta-lenses and beam deflectors.
With its focus on computational efficiency and flexibility, TorchRDIT lays the foundation for next-generation metasurface design workflows, offering capabilities for the creation of intricate and multifunctional photonic devices.
TorchRDIT is used for the papers:
- Eigendecomposition-free inverse design of meta-optics devices
- Inverse Design of Photonic Structures Using Automatic Differentiable Rigorous Diffraction Interface Theory
- A 3D-Printed Millimeter-Wave Free-Form Metasurface Based on Automatic Differentiable Inverse Design
- Differentiable Inverse Design of Free- form Meta-optics Using Multiplicative Filter Network
Features
The EM algorithms used in this package are Rigorous Diffraction Interface Theory (R-DIT) and Rigorous Coupled Wave Analysis (RCWA) . The solver is developed on an automatic differentiable framework (PyTorch) and is fully differentiable for more advanced applications.
Key Capabilities
- Eigendecomposition-free R-DIT: Up to 16.2× speedup over traditional RCWA
- Full differentiability: Seamless integration with gradient-based optimization
- GPU acceleration: CUDA and MPS backend support
- GDS Export/Import: Industry-standard format for fabrication workflows
- Export photonic masks to GDS format
- Import masks from GDS vertex data
- Support for complex geometries with holes
- Batch processing for multiple designs
- Material handling: Dispersive materials with automatic fitting
- Flexible geometry: Arbitrary unit cells and lattice systems
Fast Fourier Factorization
TorchRDIT’s FFF implementation follows the tangent-field techniques popularized by fmmax and S4, but is written entirely in PyTorch (torchrdit/src/torchrdit/vector.py). When is_use_FFF=True, the solver automatically instantiates the tangent generator, yet you can also invoke it explicitly via compute_tangent_field:
from torchrdit.vector import compute_tangent_field
tx, ty = compute_tangent_field(
mask.float(),
XO=solver.XO,
YO=solver.YO,
lattice_t1=solver.lattice_t1,
lattice_t2=solver.lattice_t2,
harmonics=tuple(int(k) for k in solver.harmonics),
scheme="POL", # POL, NORMAL, JONES, or JONES_DIRECT
)
Choose between the four built-in schemes—POL, NORMAL, JONES, JONES_DIRECT—to match the field representation expected by your Fourier factorization workflow while keeping gradients intact.
For background on the algorithmic formulation see:
- M. F. Schubert and A. M. Hammond, "Fourier modal method for inverse design of metasurface-enhanced micro-LEDs," Opt. Express 31, 42945 (2023).
- V. Liu and S. Fan, "S4 : A free electromagnetic solver for layered periodic structures," Computer Physics Communications 183, 2233–2244 (2012).
Installation
You can install the package directly from PyPI:
pip install torchrdit
Dependencies
- torch>=2.5.1
- numpy>=2.2.0
- scipy>=1.15.3
- scikit-image>=0.25.2
- matplotlib>=3.10.3
- tqdm>=4.67.1
- pyyaml>=6.0.2
- ruff>=0.12.2
- gdstk>=0.9.60
Note: The gdstk library may require additional system dependencies:
These are typically available through your system's package manager (e.g., apt-get install libz-dev libqhull-dev on Ubuntu).
Usage
TorchRDIT includes several example files to demonstrate its capabilities:
R-DIT Algorithm Examples
- example_gmrf_rdit.py: GMRF with hexagonal unit cells using R-DIT algorithm
Dispersive Materials Examples
- example_gmrf_dispersive.py: GMRF with dispersive materials and permittivity fitting
Design Optimization Examples
- example_gmrf_variable_optimize.py: Demonstration of parameter optimization using automatic differentiation
GDS Export/Import Examples
- example_gds_export.py: Comprehensive GDS functionality demonstration
Quick GDS Example
from torchrdit.shapes import ShapeGenerator
from torchrdit.gds import mask_to_gds, gds_to_mask
# Create shape and export to GDS
shape_gen = ShapeGenerator(X, Y, grids)
mask = shape_gen.generate_circle_mask(center=(0, 0), radius=0.5)
mask_to_gds(mask, shape_gen.get_layout(), "DEVICE", "output.gds")
# Import from GDS
reconstructed = gds_to_mask("output.json", shape_gen)
For more detailed documentation, please visit our Wiki.
Related Works
- Eigendecomposition-free inverse design of meta-optics devices
- Inverse Design of Photonic Structures Using Automatic Differentiable Rigorous Diffraction Interface Theory
Citation
The package contains the work from multiple publicatinos. Please consider to cithe the following paper for the R-DIT solver:
Yi Huang, Ziwei Zhu, Yunxi Dong, Hong Tang, Bowen Zheng, Viktor A. Podolskiy, and Hualiang Zhang, "Eigendecomposition-free inverse design of meta-optics devices," Opt. Express 32, 13986-13997 (2024)
@article{Huang:24,
author = {Yi Huang and Ziwei Zhu and Yunxi Dong and Hong Tang and Bowen Zheng and Viktor A. Podolskiy and Hualiang Zhang},
journal = {Opt. Express},
keywords = {Diffraction theory; Finite-difference time-domain method; Inverse design; Machine learning; Neural networks; Refractive index},
number = {8},
pages = {13986--13997},
publisher = {Optica Publishing Group},
title = {Eigendecomposition-free inverse design of meta-optics devices},
volume = {32},
month = {Apr},
year = {2024},
url = {https://opg.optica.org/oe/abstract.cfm?URI=oe-32-8-13986},
doi = {10.1364/OE.514347},
abstract = {The inverse design of meta-optics has received much attention in recent years. In this paper, we propose a GPU-friendly inverse design framework based on improved eigendecomposition-free rigorous diffraction interface theory, which offers up to 16.2\&\#x2009;\&\#x00D7; speedup over the traditional inverse design based on rigorous coupled-wave analysis. We further improve the framework\&\#x2019;s flexibility by introducing a hybrid parameterization combining neural-implicit and traditional shape optimization. We demonstrate the effectiveness of our framework through intricate tasks, including the inverse design of reconfigurable free-form meta-atoms.},
}
License
This project is licensed under the GPL-3.0 License. See the LICENSE file for details.
Feedback and Support
If you have any questions, issues, or suggestions, please open an issue or email us at yi_huang at student dot uml dot edu.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file torchrdit-0.1.30.tar.gz.
File metadata
- Download URL: torchrdit-0.1.30.tar.gz
- Upload date:
- Size: 2.8 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c466e13d8d9c56f67988ef16413f4f130e0e6c8e43a7951d0cd6ae4498a68491
|
|
| MD5 |
343be76c4f97ccbc61918804aa91418d
|
|
| BLAKE2b-256 |
eb559bcfa58b83c1536025ff518751b1571ef705b22d87db94d82036ca6c7d7e
|
Provenance
The following attestation bundles were made for torchrdit-0.1.30.tar.gz:
Publisher:
ci.yml on yi-huang-1/torchrdit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
torchrdit-0.1.30.tar.gz -
Subject digest:
c466e13d8d9c56f67988ef16413f4f130e0e6c8e43a7951d0cd6ae4498a68491 - Sigstore transparency entry: 1280531776
- Sigstore integration time:
-
Permalink:
yi-huang-1/torchrdit@91c3cf80f63541b3a7c320697f029e7708cd8a1d -
Branch / Tag:
refs/tags/0.1.30 - Owner: https://github.com/yi-huang-1
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@91c3cf80f63541b3a7c320697f029e7708cd8a1d -
Trigger Event:
release
-
Statement type:
File details
Details for the file torchrdit-0.1.30-py3-none-any.whl.
File metadata
- Download URL: torchrdit-0.1.30-py3-none-any.whl
- Upload date:
- Size: 170.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2e84d5c66a38d0b8437aa9da55e560eb7c5ca804e54d2b9d448981f3ab6819ea
|
|
| MD5 |
04693417e4cd61f444f00a63ff5d158a
|
|
| BLAKE2b-256 |
094f62e0e9fa8c44524c5c4726e887be6ccde68de93d83d9f0c2f8fe68679378
|
Provenance
The following attestation bundles were made for torchrdit-0.1.30-py3-none-any.whl:
Publisher:
ci.yml on yi-huang-1/torchrdit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
torchrdit-0.1.30-py3-none-any.whl -
Subject digest:
2e84d5c66a38d0b8437aa9da55e560eb7c5ca804e54d2b9d448981f3ab6819ea - Sigstore transparency entry: 1280531781
- Sigstore integration time:
-
Permalink:
yi-huang-1/torchrdit@91c3cf80f63541b3a7c320697f029e7708cd8a1d -
Branch / Tag:
refs/tags/0.1.30 - Owner: https://github.com/yi-huang-1
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@91c3cf80f63541b3a7c320697f029e7708cd8a1d -
Trigger Event:
release
-
Statement type: