svetlanna.elements package
Submodules
svetlanna.elements.aperture module
- class svetlanna.elements.aperture.Aperture(simulation_parameters: SimulationParameters, mask: Tensor | Parameter | Parameter)
Bases:
MulElement
Aperture of the optical element with transmission function, which takes the value 0 or 1
- get_transmission_function() Tensor
Method which returns the transmission function of the element
Returns
- torch.Tensor
transmission function
- to_specs() Iterable[ParameterSpecs]
Create specs
- class svetlanna.elements.aperture.MulElement(simulation_parameters: SimulationParameters)
Bases:
Element
,ABC
Class that generalize all elements with E->T@E like forward function, where T is transmission function
- forward(incident_wavefront: Wavefront) Wavefront
Calculate the field after propagating through the element
Parameters
- input_fieldWavefront
Field incident on the aperture
Returns
- Wavefront
The field after propagating through the element
- class svetlanna.elements.aperture.RectangularAperture(simulation_parameters: SimulationParameters, height: float, width: float)
Bases:
MulElement
A rectangle-shaped aperture with a transmission function taking either a value of 0 or 1
- get_transmission_function() Tensor
Method which returns the transmission function of the element
Returns
- torch.Tensor
transmission function
- to_specs() Iterable[ParameterSpecs]
Create specs
- class svetlanna.elements.aperture.RoundAperture(simulation_parameters: SimulationParameters, radius: float)
Bases:
MulElement
A round-shaped aperture with a transmission function taking either a value of 0 or 1
- get_transmission_function() Tensor
Method which returns the transmission function of the element
Returns
- torch.Tensor
transmission function
- to_specs() Iterable[ParameterSpecs]
Create specs
svetlanna.elements.diffractive_layer module
- class svetlanna.elements.diffractive_layer.DiffractiveLayer(simulation_parameters: SimulationParameters, mask: Tensor | Parameter | Parameter, mask_norm: float = 6.283185307179586)
Bases:
Element
A class that described the field after propagating through the passive diffractive layer with a given phase mask
- forward(incident_wavefront: Wavefront) Wavefront
Method that calculates the field after propagating through the SLM
Parameters
- input_fieldWavefront
Field incident on the SLM
Returns
- Wavefront
The field after propagating through the SLM
- reverse(transmission_wavefront: Wavefront) Wavefront
Method that calculates the field after passing the SLM in back propagation
Parameters
- transmitted_fieldWavefront
Field incident on the SLM in back propagation (transmitted field in forward propagation)
Returns
- Wavefront
Field transmitted on the SLM in back propagation (incident field in forward propagation)
- to_specs() Iterable[ParameterSpecs]
Create specs
- property transmission_function: Tensor
svetlanna.elements.element module
- class svetlanna.elements.element.Element(simulation_parameters: SimulationParameters)
Bases:
Module
A class that describes each element of the system
Parameters
- nn_type_
_description_
- metaclass_type_, optional
_description_, by default ABCMeta
- abstract forward(incident_wavefront: Wavefront) Wavefront
Forward propagation through the optical element
- make_buffer(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.Parameters
- namestr
name of the new buffer (it is more convenient to use name of new attribute)
- value_T
tensor to be buffered
- persistentbool, optional
see torch docs on buffers, by default False
Returns
- _T
the value passed to the method
- process_parameter(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) `
Parameters
- namestr
name of the new buffer (it is more convenient to use name of new attribute)
- value_V
the value of the element parameter
Returns
- _V
the value passed to the method
- to_specs() Iterable[ParameterSpecs | SubelementSpecs]
Create specs
svetlanna.elements.free_space module
- class svetlanna.elements.free_space.FreeSpace(simulation_parameters: SimulationParameters, distance: float | Tensor | Parameter | Parameter, method: Literal['fresnel', 'AS'])
Bases:
Element
A class that describes a propagation of the field in free space between two optical elements
- forward(incident_wavefront: Wavefront) Wavefront
Calculates the field after propagating in the free space
Parameters
- input_fieldWavefront
Field before propagation in free space
Returns
- Wavefront
Field after propagation in free space
Raises
- ValueError
Occurs when a non-existent direct distribution method is chosen
- impulse_response_angular_spectrum() Tensor
Creates the impulse response function for angular spectrum method
Returns
- torch.Tensor
2d impulse response function for angular spectrum method
- impulse_response_fresnel() Tensor
Creates the impulse response function for fresnel approximation
Returns
- torch.Tensor
2d impulse response function for fresnel approximation
- reverse(transmission_wavefront: Wavefront) Wavefront
Calculate the field after it propagates in the free space in the backward direction.
Parameters
- transmission_fieldWavefront
Field to be propagated in the backward direction
Returns
- Wavefront
Propagated in the backward direction field
- to_specs() Iterable[ParameterSpecs]
Create specs
svetlanna.elements.lens module
- class svetlanna.elements.lens.ThinLens(simulation_parameters: SimulationParameters, focal_length: float | Tensor | Parameter | Parameter, radius: float = inf)
Bases:
Element
A class that described the field after propagating through the thin lens.
- forward(incident_wavefront: Wavefront) Wavefront
Calculates the field after propagation through the thin lens.
Parameters
- input_fieldWavefront
The field incident on the thin lens.
Returns
- Wavefront
The field after propagation through the thin lens.
- get_transmission_function() Tensor
Returns the transmission function of the thin lens.
Returns
- torch.Tensor
The transmission function of the thin lens.
- reverse(transmission_wavefront: Wavefront) Wavefront
Calculates the field after passing through the lens during back propagation.
Parameters
- transmission_fieldWavefront
The field incident on the lens during back propagation. This corresponds to the transmitted field in forward propagation.
Returns
- Wavefront
The field transmitted through the lens during back propagation. This corresponds to the incident field in forward propagation.
- to_specs() Iterable[ParameterSpecs]
Create specs
- property transmission_function: Tensor
svetlanna.elements.nonlinear_element module
- class svetlanna.elements.nonlinear_element.FunctionModule(function: Callable[[Tensor], Tensor], function_parameters: Dict | None)
Bases:
Module
A class for transforming an arbitrary function with multiple parameters. Allows training function parameters
- class svetlanna.elements.nonlinear_element.NonlinearElement(simulation_parameters: SimulationParameters, response_function: Callable[[Tensor], Tensor], response_parameters: Dict | None = None)
Bases:
Element
A class representing a nonlinear optical element with a given amplitude response function. Preserves the phase distribution of the incident wavefront
svetlanna.elements.reservoir module
- class svetlanna.elements.reservoir.SimpleReservoir(simulation_parameters: SimulationParameters, nonlinear_element: Element | LinearOpticalSetup, delay_element: Element | LinearOpticalSetup, feedback_gain: float | Tensor | Parameter | Parameter, input_gain: float | Tensor | Parameter | Parameter, delay: int)
Bases:
Element
Reservoir element.
- append_feedback_queue(field: Wavefront)
Append a new wavefront to the feedback queue.
Parameters
- fieldWavefront
The new wavefront to be added to the end of the queue.
- drop_feedback_queue() None
Clear all elements from the feedback queue.
- pop_feedback_queue() None | Wavefront
Retrieve and remove the first element from the feedback queue if available.
Parameters
- fieldWavefront
The first wavefront in the queue, or None if the queue is empty or not full yet.
- to_specs() Iterable[ParameterSpecs | SubelementSpecs]
Create specs
svetlanna.elements.slm module
- class svetlanna.elements.slm.SpatialLightModulator(simulation_parameters: ~svetlanna.simulation_parameters.SimulationParameters, mask: ~torch.Tensor, height: float | ~torch.Tensor | ~torch.nn.parameter.Parameter | ~svetlanna.parameters.Parameter, width: float | ~torch.Tensor | ~torch.nn.parameter.Parameter | ~svetlanna.parameters.Parameter, location: ~typing.Tuple = (0.0, 0.0), number_of_levels: int = 256, step_function: ~typing.Callable[[~torch.Tensor], ~torch.Tensor] = <function relu>, mode: ~typing.Literal['nearest', 'bilinear', 'bicubic', 'area', 'nearest-exact'] = 'nearest')
Bases:
Element
A class that described the field after propagating through the Spatial Light Modulator with a given phase mask
Parameters
- Element_type_
_description_
- property get_aperture: Tensor
- property resized_mask: Tensor
- property transmission_function: Tensor
Module contents
- class svetlanna.elements.Aperture(simulation_parameters: SimulationParameters, mask: Tensor | Parameter | Parameter)
Bases:
MulElement
Aperture of the optical element with transmission function, which takes the value 0 or 1
- get_transmission_function() Tensor
Method which returns the transmission function of the element
Returns
- torch.Tensor
transmission function
- to_specs() Iterable[ParameterSpecs]
Create specs
- class svetlanna.elements.DiffractiveLayer(simulation_parameters: SimulationParameters, mask: Tensor | Parameter | Parameter, mask_norm: float = 6.283185307179586)
Bases:
Element
A class that described the field after propagating through the passive diffractive layer with a given phase mask
- forward(incident_wavefront: Wavefront) Wavefront
Method that calculates the field after propagating through the SLM
Parameters
- input_fieldWavefront
Field incident on the SLM
Returns
- Wavefront
The field after propagating through the SLM
- reverse(transmission_wavefront: Wavefront) Wavefront
Method that calculates the field after passing the SLM in back propagation
Parameters
- transmitted_fieldWavefront
Field incident on the SLM in back propagation (transmitted field in forward propagation)
Returns
- Wavefront
Field transmitted on the SLM in back propagation (incident field in forward propagation)
- to_specs() Iterable[ParameterSpecs]
Create specs
- property transmission_function: Tensor
- class svetlanna.elements.Element(simulation_parameters: SimulationParameters)
Bases:
Module
A class that describes each element of the system
Parameters
- nn_type_
_description_
- metaclass_type_, optional
_description_, by default ABCMeta
- abstract forward(incident_wavefront: Wavefront) Wavefront
Forward propagation through the optical element
- make_buffer(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.Parameters
- namestr
name of the new buffer (it is more convenient to use name of new attribute)
- value_T
tensor to be buffered
- persistentbool, optional
see torch docs on buffers, by default False
Returns
- _T
the value passed to the method
- process_parameter(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) `
Parameters
- namestr
name of the new buffer (it is more convenient to use name of new attribute)
- value_V
the value of the element parameter
Returns
- _V
the value passed to the method
- to_specs() Iterable[ParameterSpecs | SubelementSpecs]
Create specs
- class svetlanna.elements.FreeSpace(simulation_parameters: SimulationParameters, distance: float | Tensor | Parameter | Parameter, method: Literal['fresnel', 'AS'])
Bases:
Element
A class that describes a propagation of the field in free space between two optical elements
- forward(incident_wavefront: Wavefront) Wavefront
Calculates the field after propagating in the free space
Parameters
- input_fieldWavefront
Field before propagation in free space
Returns
- Wavefront
Field after propagation in free space
Raises
- ValueError
Occurs when a non-existent direct distribution method is chosen
- impulse_response_angular_spectrum() Tensor
Creates the impulse response function for angular spectrum method
Returns
- torch.Tensor
2d impulse response function for angular spectrum method
- impulse_response_fresnel() Tensor
Creates the impulse response function for fresnel approximation
Returns
- torch.Tensor
2d impulse response function for fresnel approximation
- reverse(transmission_wavefront: Wavefront) Wavefront
Calculate the field after it propagates in the free space in the backward direction.
Parameters
- transmission_fieldWavefront
Field to be propagated in the backward direction
Returns
- Wavefront
Propagated in the backward direction field
- to_specs() Iterable[ParameterSpecs]
Create specs
- class svetlanna.elements.FunctionModule(function: Callable[[Tensor], Tensor], function_parameters: Dict | None)
Bases:
Module
A class for transforming an arbitrary function with multiple parameters. Allows training function parameters
- class svetlanna.elements.NonlinearElement(simulation_parameters: SimulationParameters, response_function: Callable[[Tensor], Tensor], response_parameters: Dict | None = None)
Bases:
Element
A class representing a nonlinear optical element with a given amplitude response function. Preserves the phase distribution of the incident wavefront
- class svetlanna.elements.RectangularAperture(simulation_parameters: SimulationParameters, height: float, width: float)
Bases:
MulElement
A rectangle-shaped aperture with a transmission function taking either a value of 0 or 1
- get_transmission_function() Tensor
Method which returns the transmission function of the element
Returns
- torch.Tensor
transmission function
- to_specs() Iterable[ParameterSpecs]
Create specs
- class svetlanna.elements.RoundAperture(simulation_parameters: SimulationParameters, radius: float)
Bases:
MulElement
A round-shaped aperture with a transmission function taking either a value of 0 or 1
- get_transmission_function() Tensor
Method which returns the transmission function of the element
Returns
- torch.Tensor
transmission function
- to_specs() Iterable[ParameterSpecs]
Create specs
- class svetlanna.elements.SimpleReservoir(simulation_parameters: SimulationParameters, nonlinear_element: Element | LinearOpticalSetup, delay_element: Element | LinearOpticalSetup, feedback_gain: float | Tensor | Parameter | Parameter, input_gain: float | Tensor | Parameter | Parameter, delay: int)
Bases:
Element
Reservoir element.
- append_feedback_queue(field: Wavefront)
Append a new wavefront to the feedback queue.
Parameters
- fieldWavefront
The new wavefront to be added to the end of the queue.
- drop_feedback_queue() None
Clear all elements from the feedback queue.
- pop_feedback_queue() None | Wavefront
Retrieve and remove the first element from the feedback queue if available.
Parameters
- fieldWavefront
The first wavefront in the queue, or None if the queue is empty or not full yet.
- to_specs() Iterable[ParameterSpecs | SubelementSpecs]
Create specs
- class svetlanna.elements.SpatialLightModulator(simulation_parameters: ~svetlanna.simulation_parameters.SimulationParameters, mask: ~torch.Tensor, height: float | ~torch.Tensor | ~torch.nn.parameter.Parameter | ~svetlanna.parameters.Parameter, width: float | ~torch.Tensor | ~torch.nn.parameter.Parameter | ~svetlanna.parameters.Parameter, location: ~typing.Tuple = (0.0, 0.0), number_of_levels: int = 256, step_function: ~typing.Callable[[~torch.Tensor], ~torch.Tensor] = <function relu>, mode: ~typing.Literal['nearest', 'bilinear', 'bicubic', 'area', 'nearest-exact'] = 'nearest')
Bases:
Element
A class that described the field after propagating through the Spatial Light Modulator with a given phase mask
Parameters
- Element_type_
_description_
- property get_aperture: Tensor
- property resized_mask: Tensor
- property transmission_function: Tensor
- class svetlanna.elements.ThinLens(simulation_parameters: SimulationParameters, focal_length: float | Tensor | Parameter | Parameter, radius: float = inf)
Bases:
Element
A class that described the field after propagating through the thin lens.
- forward(incident_wavefront: Wavefront) Wavefront
Calculates the field after propagation through the thin lens.
Parameters
- input_fieldWavefront
The field incident on the thin lens.
Returns
- Wavefront
The field after propagation through the thin lens.
- get_transmission_function() Tensor
Returns the transmission function of the thin lens.
Returns
- torch.Tensor
The transmission function of the thin lens.
- reverse(transmission_wavefront: Wavefront) Wavefront
Calculates the field after passing through the lens during back propagation.
Parameters
- transmission_fieldWavefront
The field incident on the lens during back propagation. This corresponds to the transmitted field in forward propagation.
Returns
- Wavefront
The field transmitted through the lens during back propagation. This corresponds to the incident field in forward propagation.
- to_specs() Iterable[ParameterSpecs]
Create specs
- property transmission_function: Tensor