Skip to Content

Elements

Оптические элементы: линзы, апертуры, дифракционные слои, SLM и др.

from svetlanna.elements import ...

Классы

MulElement

Наследует: Element ABC

Class that generalize all elements with E->T@E like forward function, where T is transmission function

Свойства

transmission_function_axes

Axes of the transmission function.

Методы

get_transmission_function

get_transmission_function(self) -> torch.Tensor

Method which returns the transmission function of the element

📤 Возвращает

torch.Tensor

transmission function

forward

forward(self, incident_wavefront: Wavefront) -> Wavefront

Calculate the field after propagating through the element

📥 Параметры

ПараметрТипОписание
input_fieldWavefrontField incident on the aperture

📤 Возвращает

Wavefront

The field after propagating through the element

Aperture

Наследует: MulElement

Aperture of the optical element with transmission function, which takes the value 0 or 1

Свойства

transmission_function_axes

Методы

__init__ constructor

__init__(self, simulation_parameters: SimulationParameters, mask: OptimizableTensor)

Aperture of the optical element defined by mask tensor.

📥 Параметры

ПараметрТипОписание
simulation_parametersSimulationParametersClass exemplar that describes the optical system
masktorch.TensorTwo-dimensional tensor representing the aperture mask. Each element must be either 0 (blocks light) or 1 (allows light).

get_transmission_function

get_transmission_function(self) -> torch.Tensor

to_specs

to_specs(self) -> Iterable[ParameterSpecs]

RectangularAperture

Наследует: MulElement

A rectangle-shaped aperture with a transmission function taking either a value of 0 or 1

Свойства

transmission_function_axes

Методы

__init__ constructor

__init__(self, simulation_parameters: SimulationParameters, height: float, width: float)

Constructor method

📥 Параметры

ПараметрТипОписание
simulation_parametersSimulationParametersClass exemplar, that describes optical system
heightfloataperture height
widthfloataperture width

get_transmission_function

get_transmission_function(self) -> torch.Tensor

to_specs

to_specs(self) -> Iterable[ParameterSpecs]

RoundAperture

Наследует: MulElement

A round-shaped aperture with a transmission function taking either a value of 0 or 1

Свойства

transmission_function_axes

Методы

__init__ constructor

__init__(self, simulation_parameters: SimulationParameters, radius: float)

Constructor method

📥 Параметры

ПараметрТипОписание
simulation_parametersSimulationParametersClass exemplar, that describes optical system
radiusfloatRadius of the round-shaped aperture

get_transmission_function

get_transmission_function(self) -> torch.Tensor

to_specs

to_specs(self) -> Iterable[ParameterSpecs]

DiffractiveLayer

Наследует: Element

A class that described the field after propagating through the passive diffractive layer with a given phase mask

Свойства

transmission_function

Методы

__init__ constructor

__init__(self, simulation_parameters: SimulationParameters, mask: OptimizableTensor, mask_norm: float = 2 * torch.pi)

Constructor method

📥 Параметры

ПараметрТипОписание
simulation_parametersSimulationParametersSimulation parameters
maskOptimizableTensorPhase mask
mask_normfloat, optionalThis value will be used as following: the phase addition is equal to 2*torch.pi * mask / mask_norm. By default, 2*torch.pi

forward

forward(self, incident_wavefront: Wavefront) -> Wavefront

Method that calculates the field after propagating through the SLM

📥 Параметры

ПараметрТипОписание
input_fieldWavefrontField incident on the SLM

📤 Возвращает

Wavefront

The field after propagating through the SLM

reverse

reverse(self, transmission_wavefront: Wavefront) -> Wavefront

Method that calculates the field after passing the SLM in back propagation

📥 Параметры

ПараметрТипОписание
transmitted_fieldWavefrontField incident on the SLM in back propagation (transmitted field in forward propagation)

📤 Возвращает

Wavefront

Field transmitted on the SLM in back propagation (incident field in forward propagation)

to_specs

to_specs(self) -> Iterable[ParameterSpecs]

_BufferedValueContainer

Наследует: tuple

Internal class that marks buffered values.

It is used to prevent double setattr calls with the same value in patterns like self.x = self.make_buffer('x', x_value). Inheriting from tuple is used for performance reasons, so the __slots__. This approach was identified by GPT as the fastest one.

Element

Наследует: nn.Module

A class that describes each element of the system

Методы

__init__ constructor

__init__(self, simulation_parameters: SimulationParameters) -> None

A class that describes each element of the system

📥 Параметры

ПараметрТипОписание
simulation_parametersSimulationParametersClass exemplar that describes the optical system

forward

forward(self, incident_wavefront: Wavefront) -> Wavefront

Forward propagation through the optical element

to_specs

to_specs(self) -> Iterable[ParameterSpecs | SubelementSpecs]

Create specs

make_buffer

make_buffer(self, name: str, value: _T, persistent: bool = False) -> _T

Make buffer for internal use.

Use case:

self.mask = make_buffer('mask', some_tensor)

This allow torch to properly process .to method on Element by marking that mask should be transferred to required device.

📥 Параметры

ПараметрТипОписание
namestrname of the new buffer (it is more convenient to use name of new attribute)
value_Ttensor to be buffered
persistentbool, optionalsee torch docs on buffers, by default False

📤 Возвращает

_T

the value passed to the method

process_parameter

process_parameter(self, name: str, value: _V) -> _V

Process element parameter passed by user. Automatically registers buffer for non-parametric tensors.

Use case:

self.mask = process_parameter('mask', some_tensor)

📥 Параметры

ПараметрТипОписание
namestrname of the new buffer (it is more convenient to use name of new attribute)
value_Vthe value of the element parameter

📤 Возвращает

_V

the value passed to the method

FreeSpace

Наследует: Element

A class that describes a propagation of the field in free space between two optical elements

Методы

__init__ constructor

__init__(self, simulation_parameters: SimulationParameters, distance: OptimizableFloat, method: Literal['fresnel', 'AS'])

Free space element.

📥 Параметры

ПараметрТипОписание
simulation_parametersSimulationParametersAn instance describing the optical system’s simulation parameters.
distancefloatThe distance of the free space propagation.
methodLiteral['fresnel', 'AS']Method describing propagation in free space (1) ‘AS’ - angular spectrum method, (2) ‘fresnel’ - fresnel approximation,

impulse_response_angular_spectrum

impulse_response_angular_spectrum(self) -> torch.Tensor

Creates the impulse response function for angular spectrum method

📤 Возвращает

torch.Tensor

2d impulse response function for angular spectrum method

impulse_response_fresnel

impulse_response_fresnel(self) -> torch.Tensor

Creates the impulse response function for fresnel approximation

📤 Возвращает

torch.Tensor

2d impulse response function for fresnel approximation

forward

forward(self, incident_wavefront: Wavefront) -> Wavefront

Calculates the field after propagating in the free space

📥 Параметры

ПараметрТипОписание
input_fieldWavefrontField before propagation in free space

📤 Возвращает

Wavefront

Field after propagation in free space

⚠️ Исключения

  • ValueError — Occurs when a non-existent direct distribution method is chosen

reverse

reverse(self, transmission_wavefront: Wavefront) -> Wavefront

Calculate the field after it propagates in the free space in the backward direction.

📥 Параметры

ПараметрТипОписание
transmission_fieldWavefrontField to be propagated in the backward direction

📤 Возвращает

Wavefront

Propagated in the backward direction field

to_specs

to_specs(self) -> Iterable[ParameterSpecs]

ThinLens

Наследует: Element

A class that described the field after propagating through the thin lens.

Свойства

transmission_function

Методы

__init__ constructor

__init__(self, simulation_parameters: SimulationParameters, focal_length: OptimizableFloat, radius: float = torch.inf)

Thin lens element.

📥 Параметры

ПараметрТипОписание
simulation_parametersSimulationParametersAn instance describing the optical system’s simulation parameters.
focal_lengthOptimizableFloatThe focal length of the lens. Must be greater than 0 for a converging lens.
radiusfloatThe radius of the thin lens.

get_transmission_function

get_transmission_function(self) -> torch.Tensor

Returns the transmission function of the thin lens.

📤 Возвращает

torch.Tensor

The transmission function of the thin lens.

forward

forward(self, incident_wavefront: Wavefront) -> Wavefront

Calculates the field after propagation through the thin lens.

📥 Параметры

ПараметрТипОписание
input_fieldWavefrontThe field incident on the thin lens.

📤 Возвращает

Wavefront

The field after propagation through the thin lens.

reverse

reverse(self, transmission_wavefront: Wavefront) -> Wavefront

Calculates the field after passing through the lens during back propagation.

📥 Параметры

ПараметрТипОписание
transmission_fieldWavefrontThe field incident on the lens during back propagation. This corresponds to the transmitted field in forward propagation.

📤 Возвращает

Wavefront

The field transmitted through the lens during back propagation. This corresponds to the incident field in forward propagation.

to_specs

to_specs(self) -> Iterable[ParameterSpecs]

FunctionModule

Наследует: torch.nn.Module

A class for transforming an arbitrary function with multiple parameters. Allows training function parameters

Методы

__init__ constructor

__init__(self, function: Callable[[torch.Tensor], torch.Tensor], function_parameters: Dict | None) -> None

Constructor method

📥 Параметры

ПараметрТипОписание
functionCallable[[torch.Tensor], torch.Tensor]Arbitrary function with several parameters
function_parameters`DictNone`

forward

forward(self, function_argument: torch.Tensor) -> torch.Tensor

forward method for a class inherited from torch.nn.Module

📥 Параметры

ПараметрТипОписание
function_argumenttorch.TensorArgument of the function

📤 Возвращает

torch.Tensor

Function with trainable parameters

NonlinearElement

Наследует: Element

A class representing a nonlinear optical element with a given amplitude response function. Preserves the phase distribution of the incident wavefront

Методы

__init__ constructor

__init__(self, simulation_parameters: SimulationParameters, response_function: Callable[[torch.Tensor], torch.Tensor], response_parameters: Dict | None = None)

Constructor method

📥 Параметры

ПараметрТипОписание
simulation_parametersSimulationParametersClass exemplar, that describes optical system
response_functionCallable[[torch.Tensor], torch.Tensor]Intensity response function
response_parametersDict, optionalParameters of the response_function. Parameters converted to svetlanna.Parameter(value) will be trained, by default None

forward

forward(self, incident_wavefront: Wavefront) -> Wavefront

Method calculating the wavefront after passing a nonlinear optical element

📥 Параметры

ПараметрТипОписание
incident_wavefrontWavefrontWavefront before the nonlinear optical element

📤 Возвращает

Wavefront

Wavefront passing through a nonlinear optical element

SimpleReservoir

Наследует: Element

Reservoir element.

Методы

__init__ constructor

__init__(self, simulation_parameters: SimulationParameters, nonlinear_element: Union[Element, 'LinearOpticalSetup'], delay_element: Union[Element, 'LinearOpticalSetup'], feedback_gain: OptimizableFloat, input_gain: OptimizableFloat, delay: int) -> None

Reservoir element. The main idea is explained in https://doi.org/10.1364/OE.20.022783 . The governing formula is:

x_{out}[i] = F_{NL}(eta x_{in}[i] + lpha F_{D}(x_{out}[i- au]))

where F_{NL} is the nonlinear element, F_{D} is the delay element, lpha is the feedback_gain, eta is the input_gain, au au is the delay in samples. The user should match the delay in samples with the actual light propagation time in F_{D}.

📥 Параметры

ПараметрТипОписание
simulation_parametersSimulationParametersAn instance describing the optical system’s simulation parameters.
nonlinear_element`ElementLinearOpticalSetup`
delay_element`ElementLinearOpticalSetup`
feedback_gainOptimizableFloatThe feedback (delay line) gain (lpha).
input_gainOptimizableFloatThe input gain eta
delayintThe delay time, measured in samples, that the light spends in the delay line.

append_feedback_queue

append_feedback_queue(self, field: Wavefront)

Append a new wavefront to the feedback queue.

📥 Параметры

ПараметрТипОписание
fieldWavefrontThe new wavefront to be added to the end of the queue.

pop_feedback_queue

pop_feedback_queue(self) -> None | Wavefront

Retrieve and remove the first element from the feedback queue if available.

📥 Параметры

ПараметрТипОписание
fieldWavefrontThe first wavefront in the queue, or None if the queue is empty or not full yet.

drop_feedback_queue

drop_feedback_queue(self) -> None

Clear all elements from the feedback queue.

forward

forward(self, incident_wavefront: Wavefront) -> Wavefront

to_specs

to_specs(self) -> Iterable[ParameterSpecs | SubelementSpecs]

SpatialLightModulator

Наследует: Element

A class that described the field after propagating through the Spatial Light Modulator with a given phase mask

📥 Параметры

ПараметрТипОписание
Element_type_description

Свойства

get_aperture

resized_mask

transmission_function

Методы

__init__ constructor

__init__(self, simulation_parameters: SimulationParameters, mask: torch.Tensor, height: OptimizableFloat, width: OptimizableFloat, location: Tuple = (0.0, 0.0), number_of_levels: int = 256, step_function: Callable[[torch.Tensor], torch.Tensor] = relu, mode: Literal['nearest', 'bilinear', 'bicubic', 'area', 'nearest-exact'] = 'nearest')

forward

forward(self, incident_wavefront: Wavefront) -> Wavefront

reverse

reverse(self, transmission_wavefront: Wavefront) -> Wavefront