torchoptics
Differentiable wave optics simulation library built on PyTorch
Science Score: 54.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
✓Academic publication links
Links to: arxiv.org -
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (15.5%) to scientific vocabulary
Keywords
Repository
Differentiable wave optics simulation library built on PyTorch
Basic Info
- Host: GitHub
- Owner: MatthewFilipovich
- License: mit
- Language: Python
- Default Branch: main
- Homepage: https://torchoptics.readthedocs.io
- Size: 37.3 MB
Statistics
- Stars: 71
- Watchers: 2
- Forks: 11
- Open Issues: 4
- Releases: 8
Topics
Metadata Files
README.md
TorchOptics is a differentiable wave optics simulation library built on PyTorch.
Key Features
- 🌊 Differentiable Wave Optics — Model, analyze, and optimize optical systems using Fourier optics.
- 🔥 Built on PyTorch — GPU acceleration, batch processing, and automatic differentiation.
- 🛠️ End-to-End Optimization — Joint optimization of optical hardware and machine learning models.
- 🔬 Optical Elements — Lenses, modulators, detectors, polarizers, and more.
- 🖼️ Spatial Profiles — Hermite-Gaussian, Laguerre-Gaussian, Zernike modes, and others.
- 🔆 Polarization and Coherence — Simulate polarized light and fields with arbitrary spatial coherence.
Learn more about TorchOptics in our research paper on arXiv.
Installation
TorchOptics is available on PyPI and can be installed with:
bash
pip install torchoptics
Documentation
Read the full documentation at torchoptics.readthedocs.io.
Usage
This example shows how to simulate a 4f imaging system using TorchOptics, computing and visualizing the field at each focal plane along the optical axis:
```python import torch import torchoptics from torchoptics import Field, System from torchoptics.elements import Lens from torchoptics.profiles import checkerboard
Set simulation properties
shape = 1000 # Number of grid points in each dimension spacing = 10e-6 # Spacing between grid points (m) wavelength = 700e-9 # Field wavelength (m) focallength = 200e-3 # Lens focal length (m) tilelength = 400e-6 # Checkerboard tile length (m) num_tiles = 15 # Number of tiles in each dimension
Determine device
device = "cuda" if torch.cuda.is_available() else "cpu"
Configure default properties
torchoptics.setdefaultspacing(spacing) torchoptics.setdefaultwavelength(wavelength)
Initialize input field with checkerboard pattern
fielddata = checkerboard(shape, tilelength, numtiles) inputfield = Field(field_data).to(device)
Define 4f optical system with two lenses
system = System( Lens(shape, focallength, z=1 * focallength), Lens(shape, focallength, z=3 * focallength), ).to(device)
Measure field at focal planes along the z-axis
measurements = [ system.measureatz(inputfield, z=i * focallength) for i in range(5) ]
Visualize the measured intensity distributions
for i, measurement in enumerate(measurements): measurement.visualize(title=f"z={i}f", vmax=1) ```
Intensity distributions at different focal planes in the 4f system.
Propagation of the intensity distribution.
For more examples and detailed usage, please refer to the documentation.
Contributing
We welcome contributions! See our Contributing Guide for details.
Citing TorchOptics
If you use TorchOptics in your research, please cite our paper:
bibtex
@misc{filipovich2024torchoptics,
title={TorchOptics: An open-source Python library for differentiable Fourier optics simulations},
author={Matthew J. Filipovich and A. I. Lvovsky},
year={2024},
eprint={2411.18591},
archivePrefix={arXiv},
primaryClass={physics.optics},
url={https://arxiv.org/abs/2411.18591},
}
License
TorchOptics is distributed under the MIT License. See the LICENSE file for more details.
Owner
- Name: Matthew Filipovich
- Login: MatthewFilipovich
- Kind: user
- Repositories: 2
- Profile: https://github.com/MatthewFilipovich
Citation (CITATION.cff)
cff-version: 1.2.0
message: "If you use this software, please cite it as below."
preferred-citation:
type: article
authors:
- family-names: "Filipovich"
given-names: "Matthew J."
orcid: "https://orcid.org/0000-0002-2195-698X"
- family-names: "Lvovsky"
given-names: "A. I."
doi: "10.48550/arXiv.2411.18591"
journal: "arXiv"
month: 11
title: "TorchOptics: An open-source Python library for differentiable Fourier optics simulations"
url: "https://arxiv.org/abs/2411.18591"
year: 2024
GitHub Events
Total
- Create event: 64
- Release event: 11
- Issues event: 35
- Watch event: 57
- Delete event: 52
- Issue comment event: 74
- Push event: 258
- Pull request review event: 20
- Pull request review comment event: 11
- Pull request event: 77
- Fork event: 9
Last Year
- Create event: 64
- Release event: 11
- Issues event: 35
- Watch event: 57
- Delete event: 52
- Issue comment event: 74
- Push event: 258
- Pull request review event: 20
- Pull request review comment event: 11
- Pull request event: 77
- Fork event: 9
Committers
Last synced: 9 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| Matthew Filipovich | 4****h | 91 |
| Robin Swanson | r****n@g****m | 1 |
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 21
- Total pull requests: 84
- Average time to close issues: 16 days
- Average time to close pull requests: about 2 hours
- Total issue authors: 5
- Total pull request authors: 2
- Average comments per issue: 0.86
- Average comments per pull request: 1.01
- Merged pull requests: 72
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 21
- Pull requests: 84
- Average time to close issues: 16 days
- Average time to close pull requests: about 2 hours
- Issue authors: 5
- Pull request authors: 2
- Average comments per issue: 0.86
- Average comments per pull request: 1.01
- Merged pull requests: 72
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- MatthewFilipovich (11)
- Timemakesmegrow (7)
- psycho-ygq (1)
- tonyzhang-netizen (1)
- Fau1ks (1)
Pull Request Authors
- MatthewFilipovich (79)
- swansonr (3)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- pypi 555 last-month
- Total dependent packages: 0
- Total dependent repositories: 0
- Total versions: 12
- Total maintainers: 1
pypi.org: torchoptics
Python library for differentiable Fourier optics simulations with PyTorch.
- Homepage: https://github.com/MatthewFilipovich/torchoptics
- Documentation: https://torchoptics.readthedocs.io/
- License: MIT License Copyright (c) 2024-2025 Matthew Filipovich Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
Latest release: 0.4.0
published 9 months ago
Rankings
Maintainers (1)
Dependencies
- actions/checkout v3 composite
- actions/setup-python v4 composite
- codecov/codecov-action v5 composite
- coverage *
- matplotlib *
- mypy *
- pylint *
- scipy *
- torch *
- black >=21 development
- pre-commit >=3.6.1 development
- pylint >=3.1.0 development
- scipy >=1.7.0 development
- matplotlib ==3.8.4
- torch ==2.3.0
- myst-nb *
- sphinx-autoapi *
- sphinx-copybutton *
- sphinx_rtd_theme *