v1.4.0 — GPU-accelerated ray tracing with OpenCL
What's New in v1.4.0
GPU-accelerated ray tracing with OpenCL
Trace 100k–1M+ rays through optical systems with 10–100x speedup using your GPU.
traceMany()automatically uses the GPU when available, and silently falls back to native Python if OpenCL is not installed or no GPU is foundtraceManyOpenCL()provides direct GPU access with clear error messages if pyopencl is missingtraceManyNative()is the explicit CPU-only path
Compact ray storage for GPU transfer
CompactRays: flat numpy structured array (24 bytes/ray) for efficient CPU↔GPU transferCompactRay: lightweight view into the shared buffer with the same API asRay- Vectorized
yValues/thetaValuesproperties (~100x faster than iteration) - Vectorized
fillWithRandomUniform()(~85x faster than Python loop)
New trace result classes
RayTrace/RayTraces: unified interface for trace results withlastRay/lastRayspropertiesCompactRaytrace/CompactRaytraces: GPU-optimized equivalents
Other improvements
- Graceful handling of missing
pyopencl,tkinter, andmytkdependencies - Thorlabs lens catalog merged and consolidated (
thorlabs.py) - Fixed ABCD matrix multiplication bug in OpenCL kernel
- Fixed
maxCountbug and duplicate entry ray inMatrixGroup.trace() - Added Sphinx documentation for OpenCL at raytracing.readthedocs.io
- 675 tests passing
Installation
pip install raytracing==1.4.0
# Optional: for GPU acceleration
pip install pyopenclQuick example
from raytracing import *
path = ImagingPath()
path.append(Space(d=50))
path.append(Lens(f=50, diameter=25))
path.append(Space(d=120))
rays = CompactRays(100000)
rays.fillWithRandomUniform(-10, 10, -0.1, 0.1)
traces = path.traceMany(rays) # Uses GPU if available