FluxOptics.jl: A Differentiable Wave Optics Framework for Inverse Design in Julia

FluxOptics.jl: A Differentiable Wave Optics Framework for Inverse Design in Julia - Published in JOSS (2026)

https://github.com/anscoil/fluxoptics.jl

Science Score: 87.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
  • .zenodo.json file
  • DOI references
    Found 1 DOI reference(s) in JOSS metadata
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
    Published in Journal of Open Source Software
Last synced: 1 day ago · JSON representation

Repository

A Julia package for inverse problems in optics with differentiable forward models.

Basic Info
  • Host: GitHub
  • Owner: anscoil
  • License: mit
  • Language: Julia
  • Default Branch: main
  • Size: 66 MB
Statistics
  • Stars: 9
  • Watchers: 0
  • Forks: 0
  • Open Issues: 1
  • Releases: 0
Created 7 months ago · Last pushed 13 days ago
Metadata Files
Readme Contributing License

README.md

FluxOptics.jl

FluxOptics.jl

Stable Dev Build Status

Differentiable optical propagation and inverse design in Julia

FluxOptics.jl enables gradient-based optimization of optical systems through fully differentiable wave propagation. It allows you to design diffractive optical elements, optimize beam shaping, reconstruct optical fields, and characterize photonic structures.

✨ Key Features

  • 🌊 Wave propagation: Angular Spectrum, Rayleigh-Sommerfeld, Beam Propagation Method
  • 🎯 Inverse design: End-to-end optimization of phase masks, DOEs, and refractive index profiles
  • 🔧 Proximal optimization: FISTA, TV regularization, ISTA sparsity, custom constraints
  • 📊 Multi-wavelength & multimode: Polychromatic propagation and mode coupling
  • 🚀 GPU accelerated: Seamless CUDA support
  • 🧩 Composable architecture: Intuitive piping syntax for complex optical systems

Applications

FluxOptics.jl is designed for: - Inverse design: Diffractive optical elements, metasurfaces, beam shaping - Optical characterization: Phase retrieval, tomographic reconstruction, waveguide/fiber analysis - Laser physics: Cavity eigenmode analysis, mode selection, resonator design - Photonics: Fiber coupling, multimode decomposition, GRIN media simulation

📦 Installation

julia using Pkg Pkg.add("FluxOptics")

Minimum Julia version: 1.11

Required for optimization workflows

To run gradient-based optimization, you need:

Automatic differentiation: julia Pkg.add("Zygote") # Used in all examples and tutorials

Optimization algorithms : FluxOptics.jl reexports Descent from Optimisers.jl and provides Fista (Nesterov-accelerated proximal gradient). Install Optimisers.jl for additional algorithms:

julia Pkg.add("Optimisers") # For additional optimizers (Adam, Momentum, etc.)

Optional: Visualization

For plotting capabilities: julia Pkg.add("CairoMakie") # for visualize() Pkg.add("GLMakie") # for visualize_slider()

🚀 Quick Start

Design diffractive optical elements that split a Gaussian beam into two equal outputs:

```julia using FluxOptics, Zygote

Uncomment to use more FFTW threads

using FFTW

FFTW.setnumthreads(6)

using CUDA # Uncomment to use CUDA

Setup: 512×512 grid, 1 μm pitch, 1.064 μm wavelength

ns = (512, 512) ds = (1.0, 1.0) λ = 1.064 x, y = spatial_vectors(ns, ds)

Source and target fields

u0 = ScalarField(Gaussian(30.0)(x, y), ds, λ) target = ScalarField(Gaussian(30.0)(x, y, Shift2D(-60, 0)), ds, λ) + ScalarField(Gaussian(30.0)(x, y, Shift2D(60, 0)), ds, λ)

Uncomment if you are using CUDA

u0 = cu(u0)

target = cu(target)

normalizepower!(u0) normalizepower!(target)

Optical system: source → propagation → DOE → propagation → DOE → propagation

doe1 = Phase(u0, zeros(size(u0)); trainable=true, buffered=true) doe2 = Phase(u0, zeros(size(u0)); trainable=true, buffered=true) prop1 = RSProp(u0, 1500.0) prop2 = RSProp(u0, 2000.0) system = ScalarSource(u0) |> prop1 |> doe1 |> prop2 |> doe2 |> prop1

Optimize

loss(system) = sum(abs2, abs2.(system().out.electric - target.electric)) opt = FluxOptics.setup(Fista(4e3), system)

Lower the number of iterations for a quick test on cpu

for i in 1:1000 l, ∇ = Zygote.withgradient(loss, system) FluxOptics.update!(opt, system, ∇[1]) end

Result: 99.25% coupling efficiency

output = system().out coupling_efficiency(output, target) ```

📖 Tutorials

Complete documentation →

Six comprehensive tutorials:

| Tutorial | Description | |----------|-------------| | Fox-Li Cavity | Eigenmode analysis in semi-degenerate laser resonators | | Field Retrieval | Reconstruct amplitude and phase from intensity-only data | | Multi-Wavelength | Independent RGB beam control with cascaded DOEs | | Waveguide Tomography | Refractive index reconstruction from angle-resolved intensity | | Multimode Shaping | Shape 105 modes into square/ring targets with TV regularization | | Mode Sorting | Transform 45 Gaussian beams into Hermite-Gaussian modes (8-plane system) |

⚡ Performance

FluxOptics.jl is benchmarked against JaxOptics, WaveOpticsPropagation.jl, and TorchOptics on Angular Spectrum propagation (512×512, up to 1386 modes, NVIDIA RTX 4070):

| Library | GPU speedup vs FluxOptics | |---------|--------------------------| | FluxOptics | (baseline) | | JaxOptics | 0.8× | | WaveOpticsPropagation.jl | 0.6× | | TorchOptics | 0.002× |

FluxOptics also handles ~1.5× more modes than JaxOptics before running out of GPU memory.

Note: these benchmarks measure Angular Spectrum propagation performance in isolation. On full optimization loops, the gap may narrow: TorchOptics showed as little as 13× slowdown on a 3-plane monomode conversion task. For FFT and tensor-dominated problems, XLA-based frameworks like JAX may even slightly outperform Julia due to whole-graph compilation, and for such cases, JaxOptics may well be sufficient. FluxOptics is expected to show stronger advantages on more complex optical components where manual optimization and Julia's flexibility become decisive.

Full benchmark details

🤝 Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines on: - Reporting bugs and requesting features - Sharing use cases and examples - Submitting code contributions

📝 Citation

If you use FluxOptics.jl in your research, please cite:

bibtex @software{fluxoptics2025, author = {Barré, Nicolas}, title = {FluxOptics.jl: Differentiable Optical Simulations in Julia}, year = {2025}, url = {https://github.com/anscoil/FluxOptics.jl} }

📄 License

MIT License - see LICENSE file for details.

🙏 Acknowledgments

Built on the Julia ecosystem: - Zygote.jl / ChainRulesCore.jl for automatic differentiation - Optimisers.jl for optimization algorithms - CUDA.jl for GPU acceleration

Owner

  • Name: Nicolas Barré
  • Login: anscoil
  • Kind: user
  • Location: Rennes (FRANCE)

JOSS Publication

FluxOptics.jl: A Differentiable Wave Optics Framework for Inverse Design in Julia
Published
February 23, 2026
Volume 11, Issue 118, Page 9734
Authors
Nicolas Barré ORCID
Independent Researcher, France
Editor
Abhishek Tiwari ORCID
Tags
optics inverse design automatic differentiation beam propagation diffractive optics computational optics

GitHub Events

Total
  • Delete event: 3
  • Pull request event: 5
  • Watch event: 3
  • Issue comment event: 1
  • Push event: 38
  • Commit comment event: 2
Last Year
  • Delete event: 3
  • Pull request event: 5
  • Watch event: 3
  • Issue comment event: 1
  • Push event: 38
  • Commit comment event: 2

Issues and Pull Requests

Last synced: 10 days ago

All Time
  • Total issues: 0
  • Total pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Total issue authors: 0
  • Total pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • julia 2 total
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 1
juliahub.com: FluxOptics

A Julia package for inverse problems in optics with differentiable forward models.

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 2 Total
Rankings
Dependent repos count: 8.0%
Average: 21.2%
Dependent packages count: 34.4%
Last synced: 13 days ago