Skip to content

Nonlinear Element

svetlanna.elements.NonlinearElement

NonlinearElement(
    simulation_parameters: SimulationParameters,
    response_function: Callable[[Wavefront], Wavefront],
)

Bases: Element

Nonlinear optical element with a given response function. The response function takes an incident wavefront and returns the modified wavefront.

Examples:

Suppose the response function is defined as \(E^\text{out} = \sqrt{|E^\text{in}|}e^{i \arg(E^\text{in})}\):

1
2
3
4
5
6
7
8
9
import svetlanna as sv
import torch

sim_params = sv.SimulationParameters(...)

sv.elements.NonlinearElement(
    simulation_parameters=sim_params,
    response_function = lambda E: torch.polar(torch.sqrt(E.abs()), E.angle())
)

If you want to optimize the parameters of the response function, you can use svetlanna.PartialWithParameters to wrap the response function with trainable parameters. For example, if the response function is defined as \(E^\text{out} = |E^\text{in}|^a e^{i b \arg(E^\text{in})}\), where \(0<a<1\) and \(b\) are trainable, you can define the nonlinear element as follows:

def response_function(E, a, b):
    return torch.polar(E.abs()**a, b * E.angle())

sv.elements.NonlinearElement(
    simulation_parameters=sim_params,
    response_function = sv.PartialWithParameters(
        response_function,
        a=sv.ConstrainedParameter(0.5, min_value=0.0, max_value=1.0),
        b=sv.Parameter(1.0),
    ),
)

You can also train a neural network inside the nonlinear element!

1
2
3
4
sv.elements.NonlinearElement(
    simulation_parameters=sim_params,
    response_function=my_neural_network,
)

Parameters:

  • simulation_parameters (SimulationParameters) –

    Simulation parameters.

  • response_function (Callable[[Wavefront], Wavefront]) –

    Function that describes the nonlinear response of the element.