diffinytrace 2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- diffinytrace-2.1/LICENSE +21 -0
- diffinytrace-2.1/MANIFEST.in +1 -0
- diffinytrace-2.1/PKG-INFO +26 -0
- diffinytrace-2.1/README.md +95 -0
- diffinytrace-2.1/diffinytrace/__init__.py +122 -0
- diffinytrace-2.1/diffinytrace/basis_functions/__init__.py +14 -0
- diffinytrace-2.1/diffinytrace/basis_functions/bspline.py +521 -0
- diffinytrace-2.1/diffinytrace/basis_functions/chebyshev.py +3 -0
- diffinytrace-2.1/diffinytrace/basis_functions/legendre.py +77 -0
- diffinytrace-2.1/diffinytrace/basis_functions/zernike.py +235 -0
- diffinytrace-2.1/diffinytrace/config.py +140 -0
- diffinytrace-2.1/diffinytrace/constraints.py +54 -0
- diffinytrace-2.1/diffinytrace/element.py +1660 -0
- diffinytrace-2.1/diffinytrace/export/__init__.py +8 -0
- diffinytrace-2.1/diffinytrace/export/cad.py +253 -0
- diffinytrace-2.1/diffinytrace/gaussian_smoother.py +530 -0
- diffinytrace-2.1/diffinytrace/hat_smoother.py +44 -0
- diffinytrace-2.1/diffinytrace/integrators.py +452 -0
- diffinytrace-2.1/diffinytrace/intersection.py +285 -0
- diffinytrace-2.1/diffinytrace/optimize.py +808 -0
- diffinytrace-2.1/diffinytrace/physical_object.py +150 -0
- diffinytrace-2.1/diffinytrace/plotting/__init__.py +16 -0
- diffinytrace-2.1/diffinytrace/plotting/core.py +92 -0
- diffinytrace-2.1/diffinytrace/plotting/quantity2D.py +188 -0
- diffinytrace-2.1/diffinytrace/plotting/system2D.py +220 -0
- diffinytrace-2.1/diffinytrace/plotting/system3D.py +327 -0
- diffinytrace-2.1/diffinytrace/plotting/wavelength.py +231 -0
- diffinytrace-2.1/diffinytrace/refractive_index.py +101 -0
- diffinytrace-2.1/diffinytrace/render.py +77 -0
- diffinytrace-2.1/diffinytrace/source.py +661 -0
- diffinytrace-2.1/diffinytrace/spectrum.py +79 -0
- diffinytrace-2.1/diffinytrace/surface.py +468 -0
- diffinytrace-2.1/diffinytrace/target_grid.py +399 -0
- diffinytrace-2.1/diffinytrace/transforms.py +472 -0
- diffinytrace-2.1/diffinytrace/utils/__init__.py +7 -0
- diffinytrace-2.1/diffinytrace/utils/autograd.py +116 -0
- diffinytrace-2.1/diffinytrace/utils/irradiance_importer.py +134 -0
- diffinytrace-2.1/diffinytrace.egg-info/PKG-INFO +26 -0
- diffinytrace-2.1/diffinytrace.egg-info/SOURCES.txt +43 -0
- diffinytrace-2.1/diffinytrace.egg-info/dependency_links.txt +1 -0
- diffinytrace-2.1/diffinytrace.egg-info/requires.txt +14 -0
- diffinytrace-2.1/diffinytrace.egg-info/top_level.txt +1 -0
- diffinytrace-2.1/requirements.txt +14 -0
- diffinytrace-2.1/setup.cfg +4 -0
- diffinytrace-2.1/setup.py +18 -0
diffinytrace-2.1/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Martin Pflaum
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
include requirements.txt
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: diffinytrace
|
|
3
|
+
Version: 2.1
|
|
4
|
+
Author: Martin Pflaum
|
|
5
|
+
Author-email: contact@martinpflaum.com
|
|
6
|
+
Requires-Python: ==3.12
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Dist: colour-science==0.4.7
|
|
9
|
+
Requires-Dist: matplotlib==3.10.8
|
|
10
|
+
Requires-Dist: numpy==2.3.5
|
|
11
|
+
Requires-Dist: pandas==3.0.1
|
|
12
|
+
Requires-Dist: Pillow==12.0.0
|
|
13
|
+
Requires-Dist: plotly==6.6.0
|
|
14
|
+
Requires-Dist: pvlib==0.15.0
|
|
15
|
+
Requires-Dist: scikit_learn==1.8.0
|
|
16
|
+
Requires-Dist: scipy==1.17.1
|
|
17
|
+
Requires-Dist: tqdm==4.67.3
|
|
18
|
+
Requires-Dist: nbformat==5.1.3
|
|
19
|
+
Requires-Dist: ipykernel==7.2.0
|
|
20
|
+
Requires-Dist: cadquery==2.7.0
|
|
21
|
+
Requires-Dist: torchmetrics==1.9.0
|
|
22
|
+
Dynamic: author
|
|
23
|
+
Dynamic: author-email
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
Dynamic: requires-dist
|
|
26
|
+
Dynamic: requires-python
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# DiffinyTrace
|
|
2
|
+
|
|
3
|
+
**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.
|
|
4
|
+
|
|
5
|
+
The source code is available at the [GitHub repository](https://github.com/martinpflaum/diffinytrace).
|
|
6
|
+
|
|
7
|
+
## Key Features
|
|
8
|
+
|
|
9
|
+
<div align="center">
|
|
10
|
+
<img src="docs/_static/system_3D_plot.png" width="60%" alt="Transformation example">
|
|
11
|
+
<p><strong>Flexible Transformations</strong> — apply general transformations such as rotations and translations to optical components, with full control over the parameters and their role in the transformation.</p>
|
|
12
|
+
</div>
|
|
13
|
+
|
|
14
|
+
<div align="center">
|
|
15
|
+
<img src="docs/_static/cad_export.png" width="40%" alt="CAD export example">
|
|
16
|
+
<p><strong>Seamless CAD Export</strong> — generate lenses and mirrors that can be exported to standard CAD file formats.</p>
|
|
17
|
+
</div>
|
|
18
|
+
|
|
19
|
+
<div align="center">
|
|
20
|
+
<img src="docs/_static/bspline_plot1.png" width="80%" alt="B-spline surface example">
|
|
21
|
+
<p><strong>Freeform Surfaces</strong> — design complex optical elements with advanced B-spline representations for maximum flexibility.</p>
|
|
22
|
+
</div>
|
|
23
|
+
|
|
24
|
+
* **Differentiable Ray Tracing**: Full automatic differentiation support through optical systems
|
|
25
|
+
* **Constraint Optimization**: Advanced optimization with PyTorch and SciPy integration
|
|
26
|
+
* **Illumination Design**: Algorithms for computing lens surfaces to achieve desired illumination profiles
|
|
27
|
+
* **GPU Acceleration**: CUDA support for high-performance computations
|
|
28
|
+
|
|
29
|
+
## Installation
|
|
30
|
+
|
|
31
|
+
1. **Create a new Enviroment** via conda:
|
|
32
|
+
```bash
|
|
33
|
+
conda create -n dit python==3.12
|
|
34
|
+
```
|
|
35
|
+
activate enviroment via
|
|
36
|
+
```bash
|
|
37
|
+
conda activate dit
|
|
38
|
+
```
|
|
39
|
+
install pip
|
|
40
|
+
```bash
|
|
41
|
+
conda install pip
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
2. **Install PyTorch**
|
|
46
|
+
|
|
47
|
+
Check your cuda version with
|
|
48
|
+
```bash
|
|
49
|
+
nvcc --version
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Diffinytrace 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](https://pytorch.org/get-started/locally/). DiffinyTrace should work for both cpu and cuda versions.
|
|
53
|
+
|
|
54
|
+
3. **Install DiffinyTrace**
|
|
55
|
+
Install all other dependencies and the library itself via:
|
|
56
|
+
```bash
|
|
57
|
+
no pip package yet
|
|
58
|
+
```
|
|
59
|
+
or directly in the folder via
|
|
60
|
+
```bash
|
|
61
|
+
pip install -r requirements.txt
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
## Basic Usage Example
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
import diffinytrace as dit
|
|
69
|
+
import torch
|
|
70
|
+
NBK7 = dit.materials["NBK7"]
|
|
71
|
+
|
|
72
|
+
wave_len = 1.024
|
|
73
|
+
light_transform = dit.transforms.Offset(torch.tensor([0.0,0.0,0.0]))
|
|
74
|
+
source = dit.source.CollimatedMonochromatic(light_transform,8.0,wave_len)
|
|
75
|
+
|
|
76
|
+
plane_surface = dit.Plane()
|
|
77
|
+
surface2 = dit.Aspheric(-1/50.)
|
|
78
|
+
transf1 = dit.transforms.Distance(10.0,parent_transform=source)
|
|
79
|
+
lens1 = dit.Lens(transf1,5.,plane_surface,surface2,NBK7,13.0)
|
|
80
|
+
transf2 = dit.transforms.Distance(15.0,parent_transform=lens1)
|
|
81
|
+
detector = dit.Detector(transf2,plane_surface,8.0)
|
|
82
|
+
system = dit.SequentialOpticalSystem({"source":source, "lens":lens1, "detector":detector})
|
|
83
|
+
|
|
84
|
+
x,weights = source.sample(10)
|
|
85
|
+
O,D,wave_len,_,meta_data = system(x,["source","lens","detector"])
|
|
86
|
+
dit.plotting.system2D.plot(system,meta_data)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Documentation
|
|
90
|
+
|
|
91
|
+
For comprehensive documentation, tutorials, and API reference, visit the [full documentation](https://diffinytrace.readthedocs.io/en/latest/index.html).
|
|
92
|
+
|
|
93
|
+
## License
|
|
94
|
+
|
|
95
|
+
DiffinyTrace is licensed under the MIT License. See the repository for full license details.
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# Copyright (c) 2025 Martin Pflaum
|
|
2
|
+
# This file is part of the diffinytrace project, licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
"""
|
|
6
|
+
This module provides a collection of functions and classes for optical system design and analysis.
|
|
7
|
+
It includes modules for ray tracing, surface definitions, optimization, and more.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
__all__ = [
|
|
11
|
+
# Submodules
|
|
12
|
+
"source",
|
|
13
|
+
"transforms",
|
|
14
|
+
"target_grid",
|
|
15
|
+
"utils",
|
|
16
|
+
"plotting",
|
|
17
|
+
"basis_functions",
|
|
18
|
+
"gaussian_smoother",
|
|
19
|
+
"optimize",
|
|
20
|
+
"integrators",
|
|
21
|
+
"export",
|
|
22
|
+
"render",
|
|
23
|
+
"constraints",
|
|
24
|
+
"spectrum",
|
|
25
|
+
|
|
26
|
+
# intersection
|
|
27
|
+
"cat_semi_functionals",
|
|
28
|
+
"get_functional_param_args",
|
|
29
|
+
"construct_surface_and_normal_func",
|
|
30
|
+
"construct_surface_and_normal_func_with_params",
|
|
31
|
+
"CustomAutogradRule_t",
|
|
32
|
+
"get_ray_intersection_length",
|
|
33
|
+
|
|
34
|
+
# surface
|
|
35
|
+
"Plane",
|
|
36
|
+
"Aspheric",
|
|
37
|
+
"Bspline",
|
|
38
|
+
"Legendre",
|
|
39
|
+
"bspline_n_after_refinement",
|
|
40
|
+
|
|
41
|
+
# element
|
|
42
|
+
"OpticalSystem",
|
|
43
|
+
"SequentialOpticalSystem",
|
|
44
|
+
"OpticalElement",
|
|
45
|
+
"OpticalSurface",
|
|
46
|
+
"LensSurfaceTransmissionEnter",
|
|
47
|
+
"LensSurfaceTransmissionLeave",
|
|
48
|
+
"Lens",
|
|
49
|
+
"Mirror",
|
|
50
|
+
"Detector",
|
|
51
|
+
"trace_to_detector",
|
|
52
|
+
"get_unused_params_mask",
|
|
53
|
+
"set_used_params_bounds_to_constant",
|
|
54
|
+
"set_unused_params_to_zero",
|
|
55
|
+
"set_unused_bspline_coeff_to_nearest",
|
|
56
|
+
"FresnelVirtualLens",
|
|
57
|
+
|
|
58
|
+
# config
|
|
59
|
+
"set_tolerance",
|
|
60
|
+
"get_tolerance",
|
|
61
|
+
"set_max_iterations",
|
|
62
|
+
"get_max_iterations",
|
|
63
|
+
"restore_default_settings",
|
|
64
|
+
"get_damping_factor",
|
|
65
|
+
"set_damping_factor",
|
|
66
|
+
"get_show_iteration_count",
|
|
67
|
+
"set_show_iteration_count",
|
|
68
|
+
|
|
69
|
+
# optimize
|
|
70
|
+
"minimize",
|
|
71
|
+
"make_parameter_from_input",
|
|
72
|
+
|
|
73
|
+
# refractive_index
|
|
74
|
+
"materials",
|
|
75
|
+
"RefractiveIndex",
|
|
76
|
+
|
|
77
|
+
# autograd
|
|
78
|
+
"grad",
|
|
79
|
+
]
|
|
80
|
+
|
|
81
|
+
import os
|
|
82
|
+
os.environ["KMP_DUPLICATE_LIB_OK"]="TRUE"
|
|
83
|
+
import torch
|
|
84
|
+
torch.set_default_dtype(torch.float64)
|
|
85
|
+
|
|
86
|
+
from . import source
|
|
87
|
+
from . import transforms
|
|
88
|
+
from . import target_grid
|
|
89
|
+
from . import gaussian_smoother
|
|
90
|
+
|
|
91
|
+
from . import utils
|
|
92
|
+
#from . import refractive_index
|
|
93
|
+
from . import plotting
|
|
94
|
+
from . import basis_functions
|
|
95
|
+
from . import optimize
|
|
96
|
+
from . import integrators
|
|
97
|
+
from . import export
|
|
98
|
+
from . import render
|
|
99
|
+
from . import constraints
|
|
100
|
+
from . import spectrum
|
|
101
|
+
|
|
102
|
+
from .intersection import cat_semi_functionals,get_functional_param_args,\
|
|
103
|
+
construct_surface_and_normal_func,construct_surface_and_normal_func_with_params,\
|
|
104
|
+
CustomAutogradRule_t,get_ray_intersection_length
|
|
105
|
+
|
|
106
|
+
from .surface import Plane,Aspheric,Bspline,Legendre,bspline_n_after_refinement
|
|
107
|
+
|
|
108
|
+
from .element import OpticalSystem,SequentialOpticalSystem,OpticalElement,OpticalSurface,\
|
|
109
|
+
LensSurfaceTransmissionEnter,LensSurfaceTransmissionLeave,Lens,Mirror,Detector,trace_to_detector,\
|
|
110
|
+
get_unused_params_mask,set_used_params_bounds_to_constant,\
|
|
111
|
+
set_unused_params_to_zero,set_unused_bspline_coeff_to_nearest,\
|
|
112
|
+
FresnelVirtualLens
|
|
113
|
+
|
|
114
|
+
from .config import set_tolerance,get_tolerance,set_max_iterations,\
|
|
115
|
+
get_max_iterations,restore_default_settings,get_damping_factor,set_damping_factor,\
|
|
116
|
+
get_show_iteration_count,set_show_iteration_count
|
|
117
|
+
from .optimize import minimize,make_parameter_from_input
|
|
118
|
+
|
|
119
|
+
from .refractive_index import materials
|
|
120
|
+
from .refractive_index import RefractiveIndex
|
|
121
|
+
from .utils.autograd import grad
|
|
122
|
+
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Copyright (c) 2025 Martin Pflaum
|
|
2
|
+
# This file is part of the diffinytrace project, licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
__all__ = [
|
|
5
|
+
"bspline",
|
|
6
|
+
"legendre",
|
|
7
|
+
"zernike",
|
|
8
|
+
"chebyshev"
|
|
9
|
+
]
|
|
10
|
+
|
|
11
|
+
from . import bspline
|
|
12
|
+
from . import legendre
|
|
13
|
+
from . import zernike
|
|
14
|
+
from . import chebyshev
|