Tutorials
Step-by-step examples that solve a concrete problem with SVETlANNa.
Every tutorial contains complete, runnable code. We recommend following along in a Jupyter notebook or a Python script.
Contents
Difficulty
| Tutorial | Level | Key concepts |
|---|---|---|
| Beam focusing | Beginner | ThinLens, FreeSpace, Wavefront |
| 4f system | Intermediate | Fourier optics, spatial filtering |
| Phase grating on an SLM | Intermediate | SpatialLightModulator, diffraction orders, quantisation |
| Laguerre–Gaussian beam | Intermediate | Custom wavefronts, vortex beams, free-space propagation |
| Phase retrieval | Advanced | Iterative algorithms, Gerchberg–Saxton |
Suggested order
Beam focusing
The basics: focusing a Gaussian beam with a lens. Introduces Wavefront, ThinLens and
FreeSpace.
4f system
A classical 4f setup for optical filtering — Fourier optics put to work.
Phase grating on an SLM
A sinusoidal phase grating displayed on a SpatialLightModulator; the diffraction orders
are compared with the Bessel-function prediction.
Laguerre–Gaussian beam
Building a vortex mode from scratch on the simulation grid and propagating it through free space, validated against the analytical solution.
Phase retrieval
The Gerchberg–Saxton algorithm: recovering phase from intensity measurements.
Prerequisites
Before you start we suggest reading:
- Core concepts — the architecture of the library
- SimulationParameters — setting up the grid
- Optical elements — the available elements
- Wavefronts — working with fields
Running the examples
# minimal template used throughout the tutorials
import torch
from svetlanna import SimulationParameters, Wavefront
from svetlanna.units import ureg
params = SimulationParameters.from_ranges(
x_range=(-2*ureg.mm, 2*ureg.mm), x_points=512,
y_range=(-2*ureg.mm, 2*ureg.mm), y_points=512,
wavelength=632.8*ureg.nm
)
wf = Wavefront.gaussian_beam(params, waist_radius=0.5*ureg.mm)
print(f"Ready. Field shape: {wf.shape}")To run on a GPU, install the CUDA build of PyTorch and call params.to('cuda') before
creating any elements.