DiffinyTrace
DiffinyTrace is a Python library for differentiable ray tracing and optical system optimization using PyTorch. It enables automatic differentiation through optical systems, making it possible to optimize lens designs, mirror configurations, and other optical components using gradient-based methods.
The source code is available at the GitHub repository.
Key Features
Flexible Transformations — apply general transformations such as rotations and translations to optical components, with full control over the parameters and their role in the transformation.
Seamless CAD Export — generate lenses and mirrors that can be exported to standard CAD file formats.
Freeform Surfaces — design complex optical elements with advanced B-spline representations for maximum flexibility.
- Differentiable Ray Tracing: Full automatic differentiation support through optical systems
- Constraint Optimization: Advanced optimization with PyTorch and SciPy integration
- Illumination Design: Algorithms for computing lens surfaces to achieve desired illumination profiles
- GPU Acceleration: CUDA support for high-performance computations
Installation
-
Create a new Enviroment via conda:
conda create -n dit python==3.12
activate enviroment via
conda activate dit
install pip
conda install pip
-
Install PyTorch
Check your cuda version with
nvcc --versionDiffinytrace only has been tested with 2.10.0+cu130. Make sure to install the appropriate version of PyTorch for your system. You can find the installation instructions on the PyTorch website. DiffinyTrace should work for both cpu and cuda versions.
-
Install DiffinyTrace Install all other dependencies and the library itself via:
pip install diffinytrace
or directly in the folder via
pip install -r requirements.txt
Basic Usage Example
import diffinytrace as dit
import torch
NBK7 = dit.materials["NBK7"]
wave_len = 1.024
light_transform = dit.transforms.Offset(torch.tensor([0.0,0.0,0.0]))
source = dit.source.CollimatedMonochromatic(light_transform,8.0,wave_len)
plane_surface = dit.Plane()
surface2 = dit.Aspheric(-1/50.)
transf1 = dit.transforms.Distance(10.0,parent_transform=source)
lens1 = dit.Lens(transf1,5.,plane_surface,surface2,NBK7,13.0)
transf2 = dit.transforms.Distance(15.0,parent_transform=lens1)
detector = dit.Detector(transf2,plane_surface,8.0)
system = dit.SequentialOpticalSystem({"source":source, "lens":lens1, "detector":detector})
x,weights = source.sample(10)
O,D,wave_len,_,meta_data = system(x,["source","lens","detector"])
dit.plotting.system2D.plot(system,meta_data)
Documentation
For comprehensive documentation, tutorials, and API reference, visit the full documentation.
License
DiffinyTrace is licensed under the MIT License. See the repository for full license details.
Metadata
Release files for diffinytrace 2.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| diffinytrace-2.4.tar.gz | 78.3 kB | Without provenance | Details for diffinytrace-2.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| diffinytrace-2.4-py3-none-any.whl | Python 3 | none | any | Details for diffinytrace-2.4-py3-none-any.whl |
Total release size: 169.8 kB
Release files / diffinytrace-2.4.tar.gz
| Download URL | diffinytrace-2.4.tar.gz |
|---|---|
| Size | 78.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c464866cb5ad2c43e654c9bfc29ef89b1783c7f30453599264209a828482cb30
|
|
BLAKE2b-256 checksum How to use checksums |
c4b7942c10383e4111433fb45cc7d55dd33301d993c4bd6c5d891e6ec01f172d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.0
|
Release files / diffinytrace-2.4-py3-none-any.whl
| Download URL | diffinytrace-2.4-py3-none-any.whl |
|---|---|
| Size | 91.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
15d66288121396847c167ec5434d28f1c21fb17a3e7d5ec00eda29d1fcd283e4
|
|
BLAKE2b-256 checksum How to use checksums |
7738896c9fac93349cedbea13ffab8e1cb196324ed903fd5fafef048faa647f4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.0
|
Security for diffinytrace 2.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.