Spatial Light Modulator
svetlanna.elements.SpatialLightModulator
SpatialLightModulator(
simulation_parameters: SimulationParameters,
mask: OptimizableTensor,
height: float,
width: float,
lut_function: _F = identity,
center: Tuple[float, float] = (0.0, 0.0),
mode: Literal[
"nearest",
"bilinear",
"bicubic",
"area",
"nearest-exact",
] = "nearest",
)
Bases: Element, Generic[_F]
Spatial Light Modulator (SLM) element implementation.
SLM supports pixel size that differs from the simulation grid size.
The lookup table function (lut_function) allows applying a non-linear transformation to the mask values, for example, to implement quantization.
Parameters:
-
simulation_parameters(SimulationParameters) –Simulation parameters.
-
mask(OptimizableTensor) –Mask tensor of the shape
(Ny_mask, Nx_mask), whereNy_maskandNx_maskare the height and width of the mask in pixels. It can be different from the simulation grid shape(Ny, Nx); interpolation is applied to fit the mask to the SLM area. -
height(float) –Height of the SLM.
-
width(float) –Width of the SLM.
-
lut_function(_F, default:identity) –Lookup table function applied to the mask values, by default
identity. -
center(Tuple[float, float], default:(0.0, 0.0)) –Center coordinate
(x, y)of the SLM in the simulation grid coordinates, by default(0.0, 0.0). -
mode(Literal['nearest', 'bilinear', 'bicubic', 'area', 'nearest-exact'], default:'nearest') –Interpolation mode for resizing the mask, by default
'nearest'. Seetorch.nn.functional.interpolatedocumentation for more details.
svetlanna.elements.slm.QuantizerFromStepFunction
QuantizerFromStepFunction(
N: int,
max_value: float,
one_step_function: Callable[
Concatenate[Tensor, Params], Tensor
],
) -> Callable[Concatenate[Tensor, Params], Tensor]
Create a quantizer function from a given one-step function.
The resulting quantizer function takes a tensor of values from 0 to max_value and returns a tensor of values from 0 to max_value with N quantization levels.
Each level is defined as the output of the one-step function at the fractional part of the input value, divided by max_value and multiplied by N.
Parameters:
-
N(int) –Number of quantization levels.
-
max_value(float) –Maximum value of the input tensor.
-
one_step_function(Callable[Concatenate[Tensor, Params], Tensor]) –The one-step function that takes a tensor of values from 0 to 1 as the first argument and returns a tensor of values from 0 to 1. The function should have a steep transition from 0 to 1, and the steepness can be controlled by an additional parameter (for example, alpha). The function should satisfy the following conditions: \(f(0) = 0\), \(f(1)=1\), and \(f'(0) = f'(1)\) to ensure that the quantizer function is continuous and smooth.
Examples:
Returns:
-
Callable[Concatenate[Tensor, Params], Tensor]–Quantizer function that takes the same parameters as the one-step function and applies quantization to the input tensor.
svetlanna.elements.slm.one_step_tanh
A one-step function that can be used in QuantizerFromStepFunction. This function is defined as
The parameter \(\alpha \in [0, +\infty)\) controls the steepness of the transition. \(\alpha=0\) corresponds to a linear function.
Parameters:
-
x(Tensor) –Input tensor with values from 0 to 1.
-
alpha(Tensor) –Steepness control parameter.
Returns:
-
Tensor–Output tensor with values from 0 to 1.
svetlanna.elements.slm.one_step_cos
A one-step function that can be used in QuantizerFromStepFunction. This function is defined as
The parameter \(\alpha \in [0, +\infty)\) controls the steepness of the transition. \(\alpha=0\) corresponds to a function with a smooth transition, but not linear, and as \(\alpha\) increases, the transition becomes steeper.
Parameters:
-
x(Tensor) –Input tensor with values from 0 to 1.
-
alpha(Tensor) –Steepness control parameter.
Returns:
-
Tensor–Output tensor with values from 0 to 1.