Skip to content

Logging

svetlanna.debug_logging.set_debug_logging

set_debug_logging(
    mode: bool, type: Literal["logging", "print"] = "print"
)

Enable or disable debug logging for elements.

Logs information about element registration (parameters, buffers, submodules) and forward pass execution. This helps debug and trace data flow through the optical setup.

Parameters:

  • mode (bool) –

    Whether to enable debug logging.

  • type (Literal['logging', 'print'], default: 'print' ) –

    Output method: 'print' uses print(), 'logging' writes to the svetlanna.logging logger at DEBUG level, by default 'print'.

Raises:

  • ValueError

    If type is not 'logging' or 'print'.

Examples:

import svetlanna as sv
import torch
from svetlanna import set_debug_logging

set_debug_logging(True)

sim_params = sv.SimulationParameters(...)

diffractive_layer = sv.elements.DiffractiveLayer(
    simulation_parameters=sim_params,
    mask=torch.rand(Ny, Nx),
)
input_wavefront = sv.Wavefront.plane_wave(sim_params)
diffractive_layer(input_wavefront)

Output:

Buffer of DiffractiveLayer was registered with name mask:
   <class 'torch.Tensor'> shape=torch.Size([512, 512]), dtype=torch.float32, device=cpu
The forward method of DiffractiveLayer was computed
   input 0: <class 'svetlanna.wavefront.Wavefront'> shape=torch.Size([512, 512]), dtype=torch.complex64, device=cpu
   output 0: <class 'svetlanna.wavefront.Wavefront'> shape=torch.Size([512, 512]), dtype=torch.complex64, device=cpu