torchoptics.elements#
Optical element classes.
Classes#
Amplitude-only modulator element. |
|
Beam splitter element. |
|
Cylindrical lens element. |
|
Detector element. |
|
Base class for optical elements. |
|
Half Waveplate element. |
|
Identity element. |
|
Left circular polarizer element. |
|
Lens element. |
|
Linear detector element, conceptually similar to |
|
Linear polarizer element. |
|
Base class for elements that modulate the field. |
|
Modulator element. |
|
Phase-only modulator element. |
|
Polarized amplitude-only modulator element. |
|
Base class for elements that modulate the polarized field. |
|
Polarized modulator element. |
|
Polarized phase-only modulator element. |
|
Polarizing beam splitter element. |
|
Base class for elements that modulate the field based on the wavelength. |
|
Phase-only modulator element that modulates the optical field based on physical thickness. |
|
Quarter Waveplate element. |
|
Right circular polarizer element. |
|
Waveplate element. |
Package Contents#
- class torchoptics.elements.AmplitudeModulator(amplitude, z=0, spacing=None, offset=None)#
Bases:
torchoptics.elements.elements.ModulationElementAmplitude-only modulator element.
The amplitude modulator is described by an amplitude profile.
- Parameters:
amplitude (Tensor) – Amplitude profile (real-valued tensor).
z (Scalar) – Position along the z-axis. Default: 0.
spacing (Vector2 | None) – Distance between grid points along planar dimensions. Default: if None, uses a global default (see
torchoptics.set_default_spacing()).offset (Vector2 | None) – Center coordinates of the plane. Default: (0, 0).
- modulation_profile()#
Return the modulation profile.
- Return type:
- class torchoptics.elements.BeamSplitter(shape, theta, phi_0, phi_r, phi_t, z=0, spacing=None, offset=None)#
Bases:
torchoptics.elements.elements.ElementBeam splitter element.
The beam splitter is described by the following transfer matrix:
\[\begin{split}\tau = e^{i\phi_0} \begin{bmatrix} \sin \theta e^{i\phi_R} & \cos \theta e^{-i\phi_T} \\ \cos \theta e^{i\phi_T} & -\sin \theta e^{-i\phi_R} \end{bmatrix}\end{split}\]Note
A 50:50 beam splitter is obtained by setting \(\theta = \pi/4\).
The dielectric 50:50 beam splitter has \(\phi_T = \phi_R = \phi_0 = 0\), while the symmetric beam splitter of Loudon (also 50:50) has \(\phi_T = 0\), \(\phi_R = -\pi/2\), and \(\phi_0 = \pi/2\).
- Parameters:
shape (Vector2) – Number of grid points along the planar dimensions.
z (Scalar) – Position along the z-axis. Default: 0.
theta (Scalar) – Angle relating the transmitted and reflected beams.
phi_0 (Scalar) – Global phase shift.
phi_r (Scalar) – Reflection phase shift.
phi_t (Scalar) – Transmission phase shift.
spacing (Vector2 | None) – Distance between grid points along planar dimensions. Default: if None, uses a global default (see
torchoptics.set_default_spacing()).offset (Vector2 | None) – Center coordinates of the plane. Default: (0, 0).
- forward(field, other=None)#
Apply the beam splitter to the input fields.
- property transfer_matrix: torch.Tensor#
Return the transfer matrix of the beam splitter.
- Return type:
- class torchoptics.elements.CylindricalLens(shape, focal_length, theta=0, z=0, spacing=None, offset=None)#
Bases:
torchoptics.elements.elements.PolychromaticModulationElementCylindrical lens element.
Represents a thin cylindrical lens with the following modulation profile:
\[\mathcal{M}(x, y) = \exp\left(-i \frac{\pi}{\lambda f} x^2 \right)\]- where:
\(\lambda\) is the wavelength of the light, and
\(f\) is the focal length of the lens.
- Parameters:
shape (Vector2) – Number of grid points along the planar dimensions.
focal_length (Scalar) – Focal length of the lens.
z (Scalar) – Position along the z-axis. Default: 0.
theta (Scalar) – Angle of the lens in radians. Default: 0.
spacing (Vector2 | None) – Distance between grid points along planar dimensions. Default: if None, uses a global default (see
torchoptics.set_default_spacing()).offset (Vector2 | None) – Center coordinates of the plane. Default: (0, 0).
- modulation_profile(wavelength=None)#
Return the modulation profile.
- Parameters:
wavelength (torchoptics.types.Scalar | None)
- Return type:
- class torchoptics.elements.Detector(shape, z=0, spacing=None, offset=None)#
Bases:
torchoptics.elements.elements.ElementDetector element.
Computes the power measured by the detector for each grid cell using the following equation:
\[P_{i,j} = I_{i,j} \cdot \Delta A_{\text{cell}}\]- where:
\(P_{i,j}\) is the power measured in the grid cell at position \((i, j)\),
\(I_{i,j}\) is the intensity at position \((i, j)\), and
\(\Delta A_{\text{cell}}\) is the area of a single grid cell.
- Parameters:
shape (Vector2) – Number of grid points along the planar dimensions.
z (Scalar) – Position along the z-axis. Default: 0.
spacing (Vector2 | None) – Distance between grid points along planar dimensions. Default: if None, uses a global default (see
torchoptics.set_default_spacing()).offset (Vector2 | None) – Center coordinates of the plane. Default: (0, 0).
- class torchoptics.elements.Element(shape, z=0, spacing=None, offset=None)#
Bases:
torchoptics.planar_grid.PlanarGridBase class for optical elements.
The
forward()method must be implemented by the subclass.- Parameters:
shape (Vector2) – Number of grid points along the planar dimensions.
z (Scalar) – Position along the z-axis. Default: 0.
spacing (Vector2 | None) – Distance between grid points along planar dimensions. Default: if None, uses a global default (see
torchoptics.set_default_spacing()).offset (Vector2 | None) – Center coordinates of the plane. Default: (0, 0).
- validate_field(field)#
Validate that the field has the same geometry as the element.
- Parameters:
field (Field) – The field to validate.
- Return type:
None
- visualize(**kwargs)#
Visualize the Element.
- Return type:
matplotlib.figure.Figure | None
- class torchoptics.elements.HalfWaveplate(shape, theta, z=0, spacing=None, offset=None)#
Bases:
torchoptics.elements.elements.PolarizedModulationElementHalf Waveplate element.
The half waveplate is described by the following polarization matrix:
\[\begin{split}J = \begin{bmatrix} \cos^2(\theta) - \sin^2(\theta) & 2 \cos(\theta) \sin(\theta) & 0 \\ 2 \cos(\theta) \sin(\theta) & \sin^2(\theta) - \cos^2(\theta) & 0 \\ 0 & 0 & 1 \end{bmatrix}\end{split}\]- where
\(\theta\) is the fast axis angle.
- Parameters:
shape (Vector2) – Number of grid points along the planar dimensions.
z (Scalar) – Position along the z-axis. Default: 0.
theta (Scalar) – Fast axis angle of the waveplate.
spacing (Vector2 | None) – Distance between grid points along planar dimensions. Default: if None, uses a global default (see
torchoptics.set_default_spacing()).offset (Vector2 | None) – Center coordinates of the plane. Default: (0, 0).
- polarized_modulation_profile()#
Return the polarized modulation profile.
- Return type:
- class torchoptics.elements.IdentityElement(shape, z=0, spacing=None, offset=None)#
Bases:
torchoptics.elements.elements.ElementIdentity element.
The identity element does not modify the input field. It is useful as a placeholder element in
torchoptics.System.- Parameters:
shape (Vector2) – Number of grid points along the planar dimensions.
z (Scalar) – Position along the z-axis. Default: 0.
spacing (Vector2 | None) – Distance between grid points along planar dimensions. Default: if None, uses a global default (see
torchoptics.set_default_spacing()).offset (Vector2 | None) – Center coordinates of the plane. Default: (0, 0).
- forward(field)#
Return the input field without modification.
- Parameters:
field (torchoptics.fields.Field)
- Return type:
torchoptics.fields.Field
- class torchoptics.elements.LeftCircularPolarizer(shape, z=0, spacing=None, offset=None)#
Bases:
torchoptics.elements.elements.PolarizedModulationElementLeft circular polarizer element.
The left circular polarizer is described by the following polarization matrix:
\[\begin{split}J = \begin{bmatrix} \frac{1}{2} & -\frac{i}{2} & 0 \\ \frac{1}{2} & \frac{1}{2} & 0 \\ 0 & 0 & 1 \end{bmatrix}\end{split}\]- Parameters:
shape (Vector2) – Number of grid points along the planar dimensions.
z (Scalar) – Position along the z-axis. Default: 0.
spacing (Vector2 | None) – Distance between grid points along planar dimensions. Default: if None, uses a global default (see
torchoptics.set_default_spacing()).offset (Vector2 | None) – Center coordinates of the plane. Default: (0, 0).
- polarized_modulation_profile()#
Return the polarized modulation profile.
- Return type:
- class torchoptics.elements.Lens(shape, focal_length, z=0, spacing=None, offset=None)#
Bases:
torchoptics.elements.elements.PolychromaticModulationElementLens element.
Represents a thin lens with the following modulation profile:
\[\mathcal{M}(x, y) = \exp\left(-i \frac{\pi}{\lambda f} (x^2 + y^2) \right)\]- where:
\(\lambda\) is the wavelength of the light, and
\(f\) is the focal length of the lens.
- Parameters:
shape (Vector2) – Number of grid points along the planar dimensions.
focal_length (Scalar) – Focal length of the lens.
z (Scalar) – Position along the z-axis. Default: 0.
spacing (Vector2 | None) – Distance between grid points along planar dimensions. Default: if None, uses a global default (see
torchoptics.set_default_spacing()).offset (Vector2 | None) – Center coordinates of the plane. Default: (0, 0).
- modulation_profile(wavelength=None)#
Return the modulation profile.
- Parameters:
wavelength (torchoptics.types.Scalar | None)
- Return type:
- class torchoptics.elements.LinearDetector(weight, z=0, spacing=None, offset=None)#
Bases:
torchoptics.elements.elements.ElementLinear detector element, conceptually similar to
torch.nn.Linear.Applies a spatially varying weight to the field intensity and integrates over the plane, producing a weighted sum for each output channel.
The total weighted power measured by the detector is computed as:
\[P_c = \sum_{i, j} w_{c, i, j} \cdot I_{i, j} \cdot \Delta A_{\text{cell}}\]- where:
\(P_c\) is the total weighted power measured by the detector for channel \(c\),
\(w_{c, i, j}\) is the weight matrix for channel \(c\),
\(I_{i, j}\) is the intensity at position \((i, j)\), and
\(\Delta A_{\text{cell}}\) is the area of a single grid cell.
Note
This equation in its integral form is expressed as:
\[P_c = \int \int w_c(x, y) \cdot I(x, y) \, dx \, dy\]- Parameters:
weight (Tensor) – Weight matrix of shape (C, H, W).
z (Scalar) – Position along the z-axis. Default: 0.
spacing (Vector2 | None) – Distance between grid points along planar dimensions. Default: if None, uses a global default (see
torchoptics.set_default_spacing()).offset (Vector2 | None) – Center coordinates of the plane. Default: (0, 0).
- forward(field)#
Calculate the weighted power.
- Parameters:
field (Field) – The input field.
- Returns:
The weighted power.
- Return type:
Tensor
- visualize(*index, **kwargs)#
Visualize the detector output or the weight matrix.
- Parameters:
- Return type:
matplotlib.figure.Figure | None
- class torchoptics.elements.LinearPolarizer(shape, theta, z=0, spacing=None, offset=None)#
Bases:
torchoptics.elements.elements.PolarizedModulationElementLinear polarizer element.
The linear polarizer is described by the following polarization matrix:
\[\begin{split}J = \begin{bmatrix} \cos^2(\theta) & \cos(\theta) \sin(\theta) & 0 \\ \cos(\theta) \sin(\theta) & \sin^2(\theta) & 0 \\ 0 & 0 & 1 \end{bmatrix}\end{split}\]where \(\theta\) is the transmission axis of the polarizer.
- Parameters:
shape (Vector2) – Number of grid points along the planar dimensions.
z (Scalar) – Position along the z-axis. Default: 0.
theta (Scalar) – Transmission axis of the polarizer.
spacing (Vector2 | None) – Distance between grid points along planar dimensions. Default: if None, uses a global default (see
torchoptics.set_default_spacing()).offset (Vector2 | None) – Center coordinates of the plane. Default: (0, 0).
- polarized_modulation_profile()#
Return the polarized modulation profile.
- Return type:
- class torchoptics.elements.ModulationElement(shape, z=0, spacing=None, offset=None)#
-
Base class for elements that modulate the field.
The
modulation_profileproperty must be implemented by the subclass.- Parameters:
shape (Vector2) – Number of grid points along the planar dimensions.
z (Scalar) – Position along the z-axis. Default: 0.
spacing (Vector2 | None) – Distance between grid points along planar dimensions. Default: if None, uses a global default (see
torchoptics.set_default_spacing()).offset (Vector2 | None) – Center coordinates of the plane. Default: (0, 0).
- forward(field)#
Modulate the field.
- abstract modulation_profile()#
Return the modulation profile.
- Return type:
- visualize(**kwargs)#
Visualize the modulation profile.
- Parameters:
**kwargs – Additional keyword arguments for visualization.
- Return type:
matplotlib.figure.Figure | None
- class torchoptics.elements.Modulator(modulation, z=0, spacing=None, offset=None)#
Bases:
torchoptics.elements.elements.ModulationElementModulator element.
The modulator is described by a complex modulation profile.
- Parameters:
modulation (Tensor) – Complex modulation profile.
z (Scalar) – Position along the z-axis. Default: 0.
spacing (Vector2 | None) – Distance between grid points along planar dimensions. Default: if None, uses a global default (see
torchoptics.set_default_spacing()).offset (Vector2 | None) – Center coordinates of the plane. Default: (0, 0).
- modulation_profile()#
Return the modulation profile.
- Return type:
- class torchoptics.elements.PhaseModulator(phase, z=0, spacing=None, offset=None)#
Bases:
torchoptics.elements.elements.ModulationElementPhase-only modulator element.
The phase modulator is described by a phase profile.
- Parameters:
phase (Tensor) – Phase profile (real-valued tensor).
z (Scalar) – Position along the z-axis. Default: 0.
spacing (Vector2 | None) – Distance between grid points along planar dimensions. Default: if None, uses a global default (see
torchoptics.set_default_spacing()).offset (Vector2 | None) – Center coordinates of the plane. Default: (0, 0).
- modulation_profile()#
Return the modulation profile.
- Return type:
- class torchoptics.elements.PolarizedAmplitudeModulator(amplitude, z=0, spacing=None, offset=None)#
Bases:
torchoptics.elements.elements.PolarizedModulationElementPolarized amplitude-only modulator element.
The polarized amplitude modulator is described by an amplitude profile.
- Parameters:
amplitude (Tensor) – Amplitude profile (real-valued 3x3 tensor).
z (Scalar) – Position along the z-axis. Default: 0.
spacing (Vector2 | None) – Distance between grid points along planar dimensions. Default: if None, uses a global default (see
torchoptics.set_default_spacing()).offset (Vector2 | None) – Center coordinates of the plane. Default: (0, 0).
- polarized_modulation_profile()#
Return the polarized modulation profile.
- Return type:
- class torchoptics.elements.PolarizedModulationElement(shape, z=0, spacing=None, offset=None)#
Bases:
ElementBase class for elements that modulate the polarized field.
The
polarized_modulation_profileproperty must be implemented by the subclass.- Parameters:
shape (Vector2) – Number of grid points along the planar dimensions.
z (Scalar) – Position along the z-axis. Default: 0.
spacing (Vector2 | None) – Distance between grid points along planar dimensions. Default: if None, uses a global default (see
torchoptics.set_default_spacing()).offset (Vector2 | None) – Center coordinates of the plane. Default: (0, 0).
- forward(field)#
Modulate the polarized field.
- abstract polarized_modulation_profile()#
Return the polarized modulation profile.
- Return type:
- visualize(*index, **kwargs)#
Visualize the polarized modulation profile.
- Parameters:
*index (int) – Index of the tensor to visualize.
**kwargs – Additional keyword arguments for visualization.
- Return type:
matplotlib.figure.Figure | None
- class torchoptics.elements.PolarizedModulator(polarized_modulation, z=0, spacing=None, offset=None)#
Bases:
torchoptics.elements.elements.PolarizedModulationElementPolarized modulator element.
The polarized modulator is described by a complex polarized modulation profile.
- Parameters:
polarized_modulation_profile (Tensor) – Complex 3x3 polarized modulation profile.
z (Scalar) – Position along the z-axis. Default: 0.
spacing (Vector2 | None) – Distance between grid points along planar dimensions. Default: if None, uses a global default (see
torchoptics.set_default_spacing()).offset (Vector2 | None) – Center coordinates of the plane. Default: (0, 0).
polarized_modulation (torch.Tensor)
- polarized_modulation_profile()#
Return the polarized modulation profile.
- Return type:
- class torchoptics.elements.PolarizedPhaseModulator(phase, z=0, spacing=None, offset=None)#
Bases:
torchoptics.elements.elements.PolarizedModulationElementPolarized phase-only modulator element.
The polarized phase modulator is described by a polarized phase profile.
- Parameters:
phase (Tensor) – Phase profile (real-valued 3x3 tensor).
z (Scalar) – Position along the z-axis. Default: 0.
spacing (Vector2 | None) – Distance between grid points along planar dimensions. Default: if None, uses a global default (see
torchoptics.set_default_spacing()).offset (Vector2 | None) – Center coordinates of the plane. Default: (0, 0).
- polarized_modulation_profile()#
Return the polarized modulation profile.
- Return type:
- class torchoptics.elements.PolarizingBeamSplitter(shape, z=0, spacing=None, offset=None)#
Bases:
torchoptics.elements.elements.ElementPolarizing beam splitter element.
The polarizing beam splitter splits the input field into two orthogonal polarizations.
- Parameters:
shape (torchoptics.types.Vector2)
z (torchoptics.types.Scalar)
spacing (torchoptics.types.Vector2 | None)
offset (torchoptics.types.Vector2 | None)
- class torchoptics.elements.PolychromaticModulationElement(shape, z=0, spacing=None, offset=None)#
Bases:
ElementBase class for elements that modulate the field based on the wavelength.
The
modulation_profile()property must be implemented by the subclass.- Parameters:
shape (Vector2) – Number of grid points along the planar dimensions.
z (Scalar) – Position along the z-axis. Default: 0.
spacing (Vector2 | None) – Distance between grid points along planar dimensions. Default: if None, uses a global default (see
torchoptics.set_default_spacing()).offset (Vector2 | None) – Center coordinates of the plane. Default: (0, 0).
- forward(field)#
Modulate the field.
- abstract modulation_profile(wavelength=None)#
Return the modulation profile for the given wavelength.
- Parameters:
wavelength (torchoptics.types.Scalar | None)
- Return type:
- visualize(wavelength=None, **kwargs)#
Visualize the modulation profile.
- Parameters:
wavelength (Scalar | None) – Wavelength for the modulation profile.
**kwargs – Additional keyword arguments for visualization.
- Return type:
matplotlib.figure.Figure | None
- class torchoptics.elements.PolychromaticPhaseModulator(thickness, n, z=0, spacing=None, offset=None)#
Bases:
torchoptics.elements.elements.PolychromaticModulationElementPhase-only modulator element that modulates the optical field based on physical thickness.
The modulation is applied according to:
\[\mathcal{M}(x, y) = \exp\left(i \frac{2 \pi}{\lambda} \left[ n\left(\lambda\right) - 1 \right] t(x, y)\right)\]where:
\(\mathcal{M}\) is the modulation profile applied to the optical field.
\(\lambda\) is the wavelength of the light.
\(n(\lambda)\) is the wavelength-dependent refractive index of the medium.
\(t(x, y)\) is the physical thickness of the medium at each point.
- Parameters:
thickness (Tensor) – Physical thickness of the medium (real-valued tensor).
n (Scalar | Callable[[Scalar], Scalar]) – Refractive index. Can be a scalar (constant) or a callable that takes the wavelength and returns the refractive index (for dispersive media).
z (Scalar) – Position along the z-axis. Default: 0.
spacing (Vector2 | None) – Distance between grid points along planar dimensions. Default: if None, uses a global default (see
torchoptics.set_default_spacing()).offset (Vector2 | None) – Center coordinates of the plane. Default: (0, 0).
- modulation_profile(wavelength=None)#
Return the modulation profile.
- Parameters:
wavelength (torchoptics.types.Scalar | None)
- Return type:
- class torchoptics.elements.QuarterWaveplate(shape, theta, z=0, spacing=None, offset=None)#
Bases:
torchoptics.elements.elements.PolarizedModulationElementQuarter Waveplate element.
The quarter waveplate is described by the following polarization matrix:
\[\begin{split}J = \begin{bmatrix} \cos^2(\theta) + i \sin^2(\theta) & (1 - i) \cos(\theta) \sin(\theta) & 0 \\ (1 - i) \cos(\theta) \sin(\theta) & \sin^2(\theta) + i \cos^2(\theta) & 0 \\ 0 & 0 & 1 \end{bmatrix}\end{split}\]- where
\(\theta\) is the fast axis angle.
- Parameters:
shape (Vector2) – Number of grid points along the planar dimensions.
z (Scalar) – Position along the z-axis. Default: 0.
theta (Scalar) – Fast axis angle of the waveplate.
spacing (Vector2 | None) – Distance between grid points along planar dimensions. Default: if None, uses a global default (see
torchoptics.set_default_spacing()).offset (Vector2 | None) – Center coordinates of the plane. Default: (0, 0).
- polarized_modulation_profile()#
Return the polarized modulation profile.
- Return type:
- class torchoptics.elements.RightCircularPolarizer(shape, z=0, spacing=None, offset=None)#
Bases:
torchoptics.elements.elements.PolarizedModulationElementRight circular polarizer element.
The right circular polarizer is described by the following polarization matrix:
\[\begin{split}J = \begin{bmatrix} \frac{1}{2} & \frac{i}{2} & 0 \\ \frac{-i}{2} & \frac{1}{2} & 0 \\ 0 & 0 & 1 \end{bmatrix}\end{split}\]- Parameters:
shape (Vector2) – Number of grid points along the planar dimensions.
z (Scalar) – Position along the z-axis. Default: 0.
spacing (Vector2 | None) – Distance between grid points along planar dimensions. Default: if None, uses a global default (see
torchoptics.set_default_spacing()).offset (Vector2 | None) – Center coordinates of the plane. Default: (0, 0).
- polarized_modulation_profile()#
Return the polarized modulation profile.
- Return type:
- class torchoptics.elements.Waveplate(shape, phi, theta, z=0, spacing=None, offset=None)#
Bases:
torchoptics.elements.elements.PolarizedModulationElementWaveplate element.
The waveplate is described by the following polarization matrix:
\[\begin{split}J = \begin{bmatrix} \cos^2(\theta) + e^{i \phi} \sin^2(\theta) & (1 - e^{i \phi}) \cos(\theta) \sin(\theta) & 0 \\ (1 - e^{i \phi}) \cos(\theta) \sin(\theta) & \sin^2(\theta) + e^{i \phi} \cos^2(\theta) & 0 \\ 0 & 0 & 1 \end{bmatrix}\end{split}\]- where
\(\theta\) is the fast axis angle, and
\(\phi\) is the phase delay between the fast and slow axes.
Note
A quarter waveplate (QWP) is obtained by setting \(\phi = \pi/2\).
A half waveplate (HWP) is obtained by setting \(\phi = \pi\).
- Parameters:
shape (Vector2) – Number of grid points along the planar dimensions.
z (Scalar) – Position along the z-axis. Default: 0.
phi (Scalar) – Phase delay of the waveplate.
theta (Scalar) – Fast axis angle of the waveplate.
spacing (Vector2 | None) – Distance between grid points along planar dimensions. Default: if None, uses a global default (see
torchoptics.set_default_spacing()).offset (Vector2 | None) – Center coordinates of the plane. Default: (0, 0).
- polarized_modulation_profile()#
Return the polarized modulation profile.
- Return type: