Skip to content

SouthEndMusic/SplineGrids.jl

Repository files navigation

SplineGrids.jl

Global Docs

CI Aqua QA codecov

SplineGrids.jl is designed to efficiently evaluate a broad class of spline objects on a grid in the spline's domain. The package supports:

  • Any number of input and output dimensions (see the examples here)
  • Any degree of basis functions and type of knot vector
  • Using weights to define NURBS (see an example here)
  • Any combination of partial derivatives (not for NURBS, coming up) (see an example here)
  • Local refinement (coming up)
  • CPU and GPU backends via KernelAbstractions.jl (tested with CUDABackend)

The intended use case of this package is to be integrated into the SciML ecosystem, for easy and efficient incorporation of spline geometries in problems of fitting, optimization, differential equation solving and machine learning. Since SplineGrids.jl makes heavy use of in-place computations, the recommended automatic differentiation framework to use with SplineGrids.jl is Enzyme.

API

using SplineGrids
using CUDA: CUDABackend

# Parameters per input dimension
n_control_points = (10, 10, 5)
degree = (2, 3, 2)
n_sample_points = (50, 50, 25)

# The number of output dimensions
Nout = 4

# The chosen backend (CPU() by default)
backend = CUDABackend()

# Defining the spline grid
spline_dimensions = SplineDimension.(n_control_points, degree, n_sample_points; backend)
spline_grid = SplineGrid(spline_dimensions, Nout)

# Set the desired control points
spline_grid.control_points .= rand(n_control_points..., Nout)

# Evaluate
evaluate!(spline_grid)

# The output can be found in spline_grid.eval of shape (n_sample_points..., Nout)

History and theory

The most well known introduction to spline theory is probably The NURBS book [1].

SplineGrids.jl was inspired by work on caustic design by optimizing spline-based lens surfaces with differentiable ray tracing. This work was published in a master thesis and later in follow-up research [2][3][4].

Some of the core ideas for this package where implemented earlier in NURBS Pytorch, but that package was never properly tested or released.

References

[1] Piegl, L., & Tiller, W. (2012). The NURBS book. Springer Science & Business Media.

[2] Koning, B. D., Heemels, A., Adam, A., & Möller, M. (2024). Gradient descent-based freeform optics design for illumination using algorithmic differentiable non-sequential ray tracing. Optimization and Engineering, 25(3), 1203-1235.

[3] Heemels, A., De Koning, B., Möller, M., & Adam, A. (2024). Optimizing freeform lenses for extended sources with algorithmic differentiable ray tracing and truncated hierarchical B-splines. Optics Express, 32(6), 9730-9746.

[4] Heemels, A., de Koning, B., Moller, M., & Adama, A. (2024, May). Unsupervised design of illumination optics using algorithmic differentiable raytracing. In International Optical Design Conference 2023 (Vol. 12798, pp. 84-85). SPIE.

Releases

No releases published

Packages

No packages published

Languages