Callbacks#
Base class#
- class torchgpe.utils.callbacks.Callback[source]#
Base class for callbacks.
Before a simulation starts, it is provided with the instance of the
gpe.bec2D.gas.Gas
(stored in thegpe.utils.callbacks.Callback.gas
variable) and with a dictionary of parameters for the simulation (stored ingpe.utils.callbacks.Callback.propagation_params
)Attributes
The instance of the
gpe.bec2D.gas.Gas
class.A dictionary of parameters for the simulation.
Methods
Function called by the
gpe.bec2D.gas.Gas
class before the simulation beginsFunction called by the
gpe.bec2D.gas.Gas
at the beginning of each epochFunction called by the
gpe.bec2D.gas.Gas
at the end of each epochFunction called by the
gpe.bec2D.gas.Gas
class after the simulation ends
Implemented callbacks#
Dimensionality dependent callbacks#
- class torchgpe.utils.callbacks.LInfNorm(compute_every=1, print_every=1)[source]#
Callback computing the \(L_\infty\) norm of the wavefunction
The \(L_\infty\) norm is defined as:
\[L_\infty = \text{max}_{(x,y)}|\Psi_t - \Psi_{t+\Delta t}|\]- Parameters:
compute_every (int) – Optional. The number of epochs after which the norm is computed. Defaults to 1.
print_every (int) – Optional. The number of epochs after which, if computed, the norm is also printed. Defaults to 1.
Attributes
A list of the computed norms
- class torchgpe.utils.callbacks.L1Norm(compute_every=1, print_every=1)[source]#
Callback computing the \(L_1\) norm of the wavefunction
The \(L_1\) norm is defined as:
\[L_1 = \sum_{(x,y)}|\Psi_t - \Psi_{t+\Delta t}| \, dx \, dy\]- Parameters:
compute_every (int) – Optional. The number of epochs after which the norm is computed. Defaults to 1.
print_every (int) – Optional. The number of epochs after which, if computed, the norm is also printed. Defaults to 1.
Attributes
A list of the computed norms
- class torchgpe.utils.callbacks.L2Norm(compute_every=1, print_every=1)[source]#
Callback computing the \(L_2\) norm of the wavefunction
The \(L_2\) norm is defined as:
\[L_2 = \sqrt{\sum_{(x,y)}|\Psi_t - \Psi_{t+\Delta t}|^2 \, dx \, dy}\]- Parameters:
compute_every (int) – Optional. The number of epochs after which the norm is computed. Defaults to 1.
print_every (int) – Optional. The number of epochs after which, if computed, the norm is also printed. Defaults to 1.
Attributes
A list of the computed norms
2D specific callbacks#
- class torchgpe.bec2D.callbacks.CavityMonitor(dispersive_cavity, save_every=1)[source]#
Callback monitoring the time dependent parameters of a dispersive cavity and its field.
During the simulation, the values of cavity detuning, pump strength and cavity field are stored. Once the simulation is finished, the saved parameters are accessible via the
gpe.bec2D.callbacks.CavityMonitor.alpha
,gpe.bec2D.callbacks.CavityMonitor.pump
andgpe.bec2D.callbacks.CavityMonitor.cavity_detuning
tensors.- Parameters:
dispersive_cavity (DispersiveCavity) – The cavity to be monitored.
save_every (int) – Optional. The number of epochs after which the parameters should be saved. Defaults to 1.
Attributes
A list of the pump strengths.
A list of the cavity detunings.
A list of the cavity field amplitudes.
A list of the times at which the parameters were saved.
- class torchgpe.bec2D.callbacks.Animation(output_file, save_every=1, fps=25, cores=1, density=True, phase=True, densityk=False, potentials=False, cavities=[], time_dependent_variables=[])[source]#
Callback generating an animation of the propagation of the wavefunction.
- Parameters:
output_file (str) – The path where to store the mp4 animation.
save_every (int) – Optional. The number of epochs after which a frame of the animation is saved. Defaults to 1.
fps (int) – Optional. The number of frames per second of the animation. Defaults to 25.
cores (int) – Optional. The number of cores to use for the generation of the images. Defaults to 1.
density (bool) – Optional. Whether to plot the real space density. Defaults to True.
phase (bool) – Optional. Whether to plot the phase. Defaults to True.
densityk (bool) – Optional. Whether to plot the momentum space density. Defaults to False.
potentials (bool) – Optional. Whether to plot the potential landscape. Defaults to False.
cavities (list) – Optional. A list of
gpe.bec2D.potentials.DispersiveCavity
objects to monitor. Defaults to [].time_dependent_variables (list) – Optional. A list of tuples of the form (label, function) where label is a string and function is a function of time returning a float. The value of the function will be plotted as a function of time. Defaults to [].