torchoptics

Differentiable wave optics simulation library built on PyTorch

https://github.com/matthewfilipovich/torchoptics

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

computational-optics deep-learning differentiable-optics diffraction fourier-optics holography imaging inverse-design machine-learning microscopy optical-neural-network optics physics pytorch wave-optics
Last synced: 6 months ago · JSON representation ·

Repository

Differentiable wave optics simulation library built on PyTorch

Basic Info
Statistics
  • Stars: 71
  • Watchers: 2
  • Forks: 11
  • Open Issues: 4
  • Releases: 8
Topics
computational-optics deep-learning differentiable-optics diffraction fourier-optics holography imaging inverse-design machine-learning microscopy optical-neural-network optics physics pytorch wave-optics
Created about 1 year ago · Last pushed 6 months ago
Metadata Files
Readme Contributing License Citation

README.md

[![build](https://github.com/MatthewFilipovich/torchoptics/actions/workflows/build.yml/badge.svg)](https://github.com/MatthewFilipovich/torchoptics/actions/workflows/build.yml) [![Codecov](https://img.shields.io/codecov/c/github/matthewfilipovich/torchoptics?token=52MBM273IF)](https://codecov.io/gh/MatthewFilipovich/torchoptics) [![Documentation Status](https://readthedocs.org/projects/torchoptics/badge/?version=latest)](https://torchoptics.readthedocs.io/en/latest/?badge=latest) [![PyPI version](https://img.shields.io/pypi/v/torchoptics.svg)](https://pypi.org/project/torchoptics/) [![Python Version](https://img.shields.io/badge/python-3.9%2B-blue)](https://www.python.org/downloads/) [![License](https://img.shields.io/github/license/MatthewFilipovich/torchoptics?color=blue)](https://github.com/MatthewFilipovich/torchoptics/blob/main/LICENSE)

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

Open In Colab

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

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

All Time
  • Total Commits: 92
  • Total Committers: 2
  • Avg Commits per committer: 46.0
  • Development Distribution Score (DDS): 0.011
Past Year
  • Commits: 92
  • Committers: 2
  • Avg Commits per committer: 46.0
  • Development Distribution Score (DDS): 0.011
Top Committers
Name Email 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
enhancement (5) documentation (4) bug (1)
Pull Request Labels
bug (1)

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
  • Versions: 12
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 555 Last month
Rankings
Dependent packages count: 9.4%
Average: 35.9%
Dependent repos count: 62.3%
Maintainers (1)
Last synced: 6 months ago

Dependencies

.github/workflows/build.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v4 composite
  • codecov/codecov-action v5 composite
pyproject.toml pypi
requirements-ci.txt pypi
  • coverage *
  • matplotlib *
  • mypy *
  • pylint *
  • scipy *
  • torch *
requirements-dev.txt pypi
  • black >=21 development
  • pre-commit >=3.6.1 development
  • pylint >=3.1.0 development
  • scipy >=1.7.0 development
requirements.txt pypi
  • matplotlib ==3.8.4
  • torch ==2.3.0
docs/requirements.txt pypi
  • myst-nb *
  • sphinx-autoapi *
  • sphinx-copybutton *
  • sphinx_rtd_theme *