Beampy modules¶
List of all the modules used in Beampy as of Dec 31, 2020 for the version 1.11
beampy.bpm¶
beampy.bpm code.
The bpm module contain the Bpm class used to simulate the light propagation - within low refractive index variation and small angle (paraxial approximation) - using the Beam Propagation Method.
This module was done by Jonathan Peltier during a master university course from the PAIP master of the université de Lorraine, under the directive of Pr. Nicolas Fressengeas.
The bpm codes are mainly based on a compilation of MatLab codes initialy developed by Régis Grasser during his PhD thesis[2], and later modified at the FEMTO-ST institute of the Université de Franche-Comté and at the LMOPS laboratory [3] of the Université de Lorraine.
[1] K. Okamoto, in Fundamentals of Optical Waveguides, 2nd ed., edited by K. Okamoto (Academic, Burlington, 2006), pp. 329–397.
[2] “Generation et propagation de reseaux periodiques de solitons spatiaux dans un milieu de kerr massif” PhD thesis, université de Franche-Comté 1998.
[3] H. Oukraou et. al., Broadband photonic transport between waveguides by adiabatic elimination Phys. Rev. A, 97 023811 (2018).
-
class
beampy.bpm.
Bpm
(no, lo, length_z, dist_z, nbr_z_disp, length_x, dist_x)¶ Bases:
object
The Bpm class is used to simulate light propagation - within small refractive index variation guides and small angle of propagation (paraxial) - using the Beam Propagation Method.
- Parameters
no (float) – Refractive index of the cladding.
lo (float) – Wavelength of the beam in vaccum (µm).
length_z (float) – Size of the compute window over z (µm).
dist_z (float) – Step over z (µm)
nbr_z_disp (int) – Number of points to display over z.
length_x (float) – Size of the compute window over x (µm).
dist_x (float) – Step over x (µm)
-
airy_light
(lobe_size, airy_zero, offset_light=0)¶ Create an Airy beam using scipy.special.airy(x).
- Parameters
lobe_size (float) – Size of the first lobe (µm).
airy_zero (int) – Cut the beam at the asked zero of the Airy function. n lobes will be displayed.
offset_light (float, optional) – Light offset from center in µm. 0 by default.
- Returns
field (array) – Amplitude values over x (µm).
airy_zero (int) – Number of lobes. Corrected if higher than the window size.
Notes
This methods uses the following variables defined in
Bpm
: nbr_x, length_x, dist_x, x.
-
all_modes
(width, delta_no, offset_light=0)¶ Compute all modes allowed by the guide and sum them into one field.
- Parameters
width (float) – Waveguide width (µm) at 1/e^2 intensity.
delta_no (float) – Difference of refractive index between the core and the cladding.
offset_light (float, optional) – Light offset from center in µm. 0 by default.
- Returns
field (array) – Sum of all possibles fields in the guide.
h (array, float) – Transverse propagation constant over x in µm of all modes.
gamma (array, float) – Extinction coefficient over z in µm of all modes.
beta (array, float) – Longitudinal constant of propagation over z in µm of all modes.
Notes
This methods uses the following variables defined in
Bpm
: nbr_x and the :meth`mode_light` method.
-
bpm_compute
(dn, n2=None, chi3=None, kerr_loop=1, variance_check=False)¶ Compute BPM principle : free_propag over dz/2, index modulation, free_propag over dz/2.
- Parameters
n2 (float, optional) – Nonlinear refractive index responsable for the optical Kerr effect in m^2/W. None by default.
chi3 (float, optional) – Value of the third term of the electric susceptibility tensor in m^2/V^2. None by default.
kerr (bool, optional) – Activate the kerr effect. False by default.
kerr_loop (int, optional) – Number of corrective loops for the Kerr effect. 1 by default.
variance_check (bool) – Check if the kerr effect converge fast enought. False by default.
- Returns
current_power – Power after the propagation over dz.
- Return type
array
Notes
This method uses the
Bpm
class variables: nbr_lost, i, field, dist_z, dn, nl_mat, phase_mat, epnc,kerr_effect()
.This method change the values of: field, dn, nl_mat, current_power.
-
check_modes
(width, delta_no)¶ Return the last possible mode number. Could be merged with
all_modes()
but would increase the needed time to compute just to display a number.- Parameters
width (float) – Waveguide width (µm) at 1/e^2 intensity.
delta_no (float) – Difference of refractive index between the core and the cladding.
- Returns
m – Number of the last possible mode for a squared guide.
- Return type
int
Notes
This methods uses the :meth`mode_light` method defined in
Bpm
.
-
create_curved_guides
(shape, width, delta_no, curve, half_delay, distance_factor, offset_guide=0)¶ Create two curved guides and one linear guide on the center (STIRAP).
The central positions over x and z are defined as follow:
Left guide: \(x_0-p_{min}-curve(z-length\_z/2-half\_delay)^2\)
Right guide: \(x_0+p_{min}+curve(z-length\_z/2+half\_delay)^2\)
Central guide: \(x_0\)
- Parameters
shape (method) –
square()
orgauss()
width (float) – Waveguide width (µm) at 1/e^2 intensity.
delta_no (float) – Difference of refractive index between the core and the cladding. Can contain the losses throught the imaginary part.
curve (float) – curvature factor in \(10^{-8} µm^{-2}\).
half_delay (float) – Half distance over z in µm bewteen the two external guides where they are the closest. In other words, the distance from the center and the minimum of one of the curved guides over z.
distance_factor (float) – Factor between the guide width and the minimal distance between the two guides =p_min/width. If distance_factor=1, the curved guides will touch the central guide (p_min=width).
offset_guide (float, optional) – Waveguide offset from the center (µm). 0 by default.
- Returns
peaks (array) – Central position of each guide as peaks[guide,z].
dn (array) – Difference of refractive index as dn[z,x]. Can contain the losses throught the imaginary part.
Notes
This methods uses the following variables defined in
Bpm
: length_z, nbr_z, nbr_x, x, dist_x.
-
create_guides
(shape, delta_no, nbr_p, p, offset_guide=0, z=0)¶ Create an array of guides over x using peaks positions and for a given shape.
- Parameters
shape (method) –
squared_guide()
,gauss_guide()
or any lambda function that takes one argument and return the relative refractive index for the input position.delta_no (float) – Difference of refractive index between the core and the cladding. Can contain the losses throught the imaginary part.
nbr_p (int) – Number of guides.
p (float) – Distance between two guides center (µm).
offset_guide (float, optional) – Guide offset from the center (µm). 0 by default.
z (list) – list [start, end] defining the waveguide length. Default length= windows length.
- Returns
peaks (array-like) – Central position of each guide [guide,z].
dn (array-like) – Difference of refractive index [z,x]. Can contain the losses throught the imaginary part.
Notes
This methods uses the following variables defined in
Bpm
: nbr_z, nbr_x, x, dist_x.
-
create_x_z
()¶ Create the x, z array and ajust the resolution variables.
- Returns
length_z (float) – Corrected value due to nbr_z being an int.
nbr_z (int) – Number of points computed over z.
nbr_z_disp (int) – Corrected value due to pas being an int.
length_x (float) – Corrected value due to nbr_x being an int.
nbr_x (int) – Number of point over x (µm).
x (array) – x values between [-length_x/2, length_x/2-dist_x] center on 0.
Notes
This method creates the following variables within the class
Bpm
:pas : Interval of computed points between each displayed points.
-
gauss_guide
(width, gauss_pow=1)¶ A lambda function than return a centered super-Gaussian shape.
\(e^{-(x/w)^{2P}}\)
The waist is defined as width/2 and correspond to the 1/e relative value.
See
example_guides_x()
for more details.- Parameters
width (float) – Waveguide width (µm) at 1/e^2 intensity.
gauss_pow (int, optional) – Index of the super-gaussian guide with 1 being a regural gaussian guide and 4 being the conventionnal super-gaussian guide used to describe realistic waveguides. See on en.wikipedia.org/wiki/Gaussian_function #Higher-order_Gaussian_or_super-Gaussian_function. 1 by Default.
-
gauss_light
(fwhm, offset_light=0)¶ Create a gaussien beam in amplitude.
\(E = e^{-((x-x_0)/w)^{2P}}\)
The waist is defined as fwhm/sqrt(2*log(2)) and correspond to the 1/e field value and 1/\(e^2\) intensity value.
- Parameters
fwhm (float) – Full width at half maximum (for intensity not amplitude) (µm).
offset_light (float, optional) – Light offset from center in µm. 0 by default.
- Returns
field – Amplitude values over x in µm.
- Return type
array
Notes
This methods uses the x and dist_x variables defined in
Bpm
.
-
guide_position
(peaks, guide, size)¶ Return the left and right position index over x of a given guide for each z.
- Parameters
peaks (array-like) – Central position of each guide [guide,z].
guide (int) – Number of the guide.
size (float) – Width (µm).
- Returns
x_beg (array) – Left indices position of the selected guide over z.
x_end (array) – Right indices position of the selected guide over z.
Notes
This methods uses the following variables defined in
Bpm
: nbr_z, x, length_x.
-
init_field
(field, theta_ext, irrad)¶ Initialize phase, field and power variables.
- Parameters
field (array, array-like) – Amplitude values for each beams over x (µm) [beam,E] or E
theta_ext (float) – Exterior inclinaison angle (°).
irrad (array, array-like) – Irradiance for each beam (\(W/m^2\)).
- Returns
progress_pow – Intensity values over x (µm).
- Return type
array
Notes
This method creates the following variables within the class
Bpm
:epnc: Convertion factor used to set unit of the field and irradiance.
phase_mat: Free propagation in Fourier space over dz/2.
current_power: Intensity for z=0.
field: Field value with the unit.
This methods uses the following variables defined in
Bpm
: no, x, dist_x, nbr_x, nbr_z_disp.
-
kerr_effect
(dn, n2=None, chi3=None, kerr_loop=1, variance_check=False, field_start=None, dn_start=None, phase_mat=None)¶ Kerr effect: refractive index modulation by the light intensity. See: https://optiwave.com/optibpm-manuals/bpm-non-linear-bpm-algorithm/
- Parameters
dn (array) – Difference of refractive index as dn[z,x]. Can contain the losses throught the imaginary part.
n2 (float, optional) – Nonlinear refractive index responsable for the optical Kerr effect in m^2/W. None by default.
chi3 (float, optional) – Value of the third term of the electric susceptibility tensor in m^2/V^2. None by default.
kerr_loop (int, optional) – Number of corrective loops for the Kerr effect. 1 by default.
variance_check (bool, optional) – Check if the kerr effect converge fast enought. False by default.
field_start (array, optional) – Field without kerr effect. If None were given, take the
main_compute()
field.dn_start (array, optional) – Refractive index without kerr effect. If None were given, take the
main_compute()
dn.phase_mat (array, optional) – Free propagation in Fourier space over dz/2. If None were given, take the
main_compute()
phase_mat.
- Returns
dn (array) – Refractive index with kerr effect.
nl_mat (array) – refractive index modulation with kerr effect.
field_x (array) – Field with the kerr effect at the self.i step.
cur_pow (array) – Beam power with the kerr effect after the dz propagation.
Notes
This methods uses the following variables defined in
Bpm
: i, epnc, no, ko, dist_z and thevariance()
method.
-
main_compute
(dn, n2=None, chi3=None, kerr_loop=1, variance_check=False, disp_progress=True)¶ main method used to compute propagation.
- Parameters
n2 (float, optional) – Nonlinear refractive index responsable for the optical Kerr effect in m^2/W. None by default.
chi3 (float, optional) – Value of the third term of the electric susceptibility tensor in m^2/V^2. None by default.
kerr (bool, optional) – Activate the kerr effect. False by default.
kerr_loop (int, optional) – Number of corrective loop for the Kerr effect. 1 by default.
variance_check (bool, optional) – Check if the kerr effect converge fast enought. False by default.
alpha (float, optional) – Absorption per µm. 0 by default
lost_beg (array-like, optional) – Left indices position of the selected waveguide over z. None by default.
lost_end (array-like, optional) – Right indices position of the selected waveguide over z. None by default.
- Returns
progress_pow – Intensity values (\(W/m^2\)) over x (µm) and z (µm).
- Return type
array
Notes
This method creates the following variables within the class
Bpm
: nl_mat: Refractive index modulation.This method uses the
Bpm
class variables: phase_mat, field, i, nbr_z, pas, current_power, dist_z, length_z, nbr_lost, dn, nl_mat, epnc and uses thebpm_compute()
,kerr_effect()
.This method change the values of the
Bpm
class variables: field and if kerr, dn and nl_mat.
-
mode_determ
(width, delta_no, mode)¶ Solve the transcendental equation tan=sqrt that give the modes allowed in a squared guide.
- Parameters
width (float) – Waveguide width (µm) at 1/e^2 intensity.
delta_no (float) – Difference of refractive index between the core and the cladding.
mode (int) – Number of the searched mode.
- Returns
h_m (float) – Transverse propagation constant over x (µm).
gamma_m (float) – Extinction coefficient over x (µm).
beta_m (float) – Longitudinal constant of propagation over z (µm).
- Raises
ValueError – if no mode exists.
Notes
This methods uses the following variables defined in
Bpm
: lo, no, ko.
-
mode_light
(width, delta_no, mode, offset_light=0)¶ Create light based on propagated mode inside a squared guide.
- Parameters
width (float) – Waveguide width (µm) at 1/e^2 intensity.
delta_no (float) – Difference of refractive index between the core and the cladding.
mode (int) – Number of the searched mode.
offset_light (float, optional) – Light offset from center (µm). 0 by default.
- Returns
field (array) – Amplitude values over x (µm).
h_m (float) – Transverse propagation constant over x (µm).
gamma_m (float) – Extinction coefficient over x (µm).
beta_m (float) – Longitudinal constant of propagation over z (µm).
Notes
This methods uses the following variables defined in
Bpm
: nbr_x, x and the :meth`mode_determ` method.
-
power_guide
(x_beg, x_end)¶ return the power over z in a given interval by integrating the beam irradiance.
- Parameters
x_beg (array) – Left indices position over z for a selected guide.
x_end (array) – Right indices position over z for a selected guide.
- Returns
P – Normalized power in the guide over z.
- Return type
array
Notes
This methods uses the following variables defined in
Bpm
: nbr_z_disp, progress_pow, pas.
-
squared_guide
(width)¶ A lambda function than returns a centered rectangular shape.
return 1 if \(x >= -width/2\) and \(x <= width/2\) else return 0.
- Parameters
width (float) – Waveguide width.
-
squared_light
(fwhm, offset_light=0)¶ Create a flat-top beam (squared).
- Parameters
fwhm (float) – Beam width in µm.
offset_light (float, optional) – Light offset from center in µm. 0 by default.
- Returns
field – Amplitude values over x in µm.
- Return type
array
Notes
This methods uses the following variables defined in
Bpm
: nbr_x, x.
-
variance
(initial, final)¶ This function alerts the user when the kerr effect don’t converge fast enough. Raise a ValueError when the power standard deviation exceed \(10^{-7}\).
- Parameters
initial (array) – Power of the kerr effect looped n-1 time.
final (array) – Power of the kerr effect looped n time.
- Raises
ValueError – when the power standard deviation exceed \(10^{-7}\).
-
beampy.bpm.
example_bpm
()¶ Version allowing to compute BPM without the user interface. Used for quick test.
beampy.interface¶
beampy.interface code.
beampy.user_interface¶
beampy.user_interface code.
The user_interface module is the main file of the beampy module. It contain the UserInterface class used to computed and displayed the bpm results onto the interface.
This module was at first developed by Marcel Soubkovsky for the implementation of the array of guides, of one gaussian beam and of the plotting methods. Then, continued by Jonathan Peltier.
-
class
beampy.user_interface.
UserInterface
¶ Bases:
PyQt5.QtWidgets.QMainWindow
,beampy.interface.Ui_MainWindow
This class connect the
Bpm
class from thebpm
module with thesetupUi()
method from theinterface
module. The interface seems to close itself when openning from spyder 3.5. In that case, open the interface in an external console.-
addmpl
(tab='guide', pow_index=0)¶ Add the selected plots on the waveguide, light or compute window.
- Parameters
tab (str, optional) – ‘guide’ or ‘light’. ‘guide’ by default.
pow_index (int, optional) – Add the first waveguide and light step if 0 or the last step if -1. Also display the propagation over (x,z) and guide power if -1 is choosen. 0 by default.
-
calculate_guide
()¶ Initialized the
Bpm
class and creates the guides.Notes
Creats many variables, including :
peaks : Central position of each waveguides [waveguide,z].
dn : Difference of reefractive index [z,x].
This method calls the following methods from
Bpm
:create_x_z()
,squared_guide()
,gauss_guide()
,create_guides()
,create_curved_guides()
.
-
calculate_light
()¶ Create the choosen beams.
Notes
Creates the progress_pow variable.
This method calls the following methods from the
Bpm
class:gauss_light()
,squared_light()
,all_modes()
,mode_light()
,airy_light()
,init_field()
.
-
calculate_propagation
()¶ Calculate the propagation based on the input light and guides shapes.
Notes
Creates the progress_pow variable.
Calls the following methods from
Bpm
:losses_position()
, meth`.main_compute`.
-
check_modes_display
()¶ Display on the interface the last mode that can propagated into a squared waveguide.
Connect the interface buttons to their corresponding functions:
on_click_guide()
,on_click_curved()
,on_click_light()
,on_click_compute()
,on_click_create_light()
,on_click_delete_light()
,save_light()
,get_guide()
,get_light()
,get_compute()
,show_estimate_time()
,check_modes_display()
.
Create a menu to open, save a file, or exit the app.
Notes
This method connect the following methods and function to the menu buttons:
open_file_name()
,save_quick()
,save_file_name()
,open_doc()
.
-
display_power
()¶ Display the power in each waveguide.
-
find_guide_number
(guide_number)¶ Return the waveguide group number for a given waveguide number.
- Parameters
guide_number (int) – Number of a waveguide
- Returns
guide_group_number – Number of the waveguide group
- Return type
int
-
get_compute
()¶ Set the saved values of the compute variables onto the interface.
-
get_guide
()¶ Set the saved values of the waveguide variables onto the interface.
-
get_light
()¶ Set the saved values of the light variables onto the interface.
-
main_compute
(dn, n2=None, chi3=None, kerr_loop=1, variance_check=False, disp_progress=True)¶ main method used to compute propagation.
- Parameters
n2 (float, optional) – Nonlinear refractive index responsable for the optical Kerr effect in m^2/W. None by default.
chi3 (float, optional) – Value of the third term of the electric susceptibility tensor in m^2/V^2. None by default.
kerr (bool, optional) – Activate the kerr effect. False by default.
kerr_loop (int, optional) – Number of corrective loop for the Kerr effect. 1 by default.
variance_check (bool, optional) – Check if the kerr effect converge fast enought. False by default.
alpha (float, optional) – Absorption per µm. 0 by default
lost_beg (array-like, optional) – Left indices position of the selected waveguide over z. None by default.
lost_end (array-like, optional) – Right indices position of the selected waveguide over z. None by default.
- Returns
progress_pow – Intensity values (\(W/m^2\)) over x (µm) and z (µm).
- Return type
array
Notes
This method creates the following variables within the class
Bpm
: nl_mat: Refractive index modulation.This method uses the
Bpm
class variables: phase_mat, field, i, nbr_z, pas, current_power, dist_z, length_z, nbr_lost, dn, nl_mat, epnc and uses thebpm_compute()
,kerr_effect()
.This method change the values of the
Bpm
class variables: field and if kerr, dn and nl_mat.
-
on_click_compute
()¶ Compute the propagation using the waveguides and bemas informations.
-
on_click_create_guide
()¶ Create a new waveguide with the displayed variables.
-
on_click_create_light
()¶ Create a new beam with the displayed variables.
-
on_click_delete_guide
()¶ Delete the current displayed waveguide and displayed the next one if exist else the previous one.
-
on_click_delete_light
()¶ Delete the current displayed beam and displayed the next one.
-
on_click_guide
()¶ Create and displayed the waguides.
-
on_click_light
()¶ Create the light and display it with the input profil waveguides.
-
open_file
(filename)¶ Set guides, beams and computes variables from a choosen file.
- Parameters
filename (str) – Name of the file.
-
open_file_name
()¶ Open a dialog window to select the file to open, and call
open_file()
to open the file.Source: https://pythonspot.com/pyqt5-file-dialog/
Notes
This method has a try/except implemented to check if the openned file contains all the variables.
-
rmmpl
(tab, pow_index=0)¶ Remove the selected plots
- Parameters
tab (str) – ‘guide’ or ‘light’.
pow_index (int, optional) – Remove the first light step if 0 or the last step if -1. 0 by default.
-
save_compute
()¶ Save the interface variables into the compute variables.
-
save_file
(filename)¶ Save guides, beams and computes variables into a choosen file.
- Parameters
filename (str) – Name of the file.
-
save_file_name
()¶ Open a dialog window to select the saved file name and call
save_file()
to save the file.
-
save_guide
(guide_selec=False)¶ Save the interface variables into the guides variables.
-
save_light
(beam_selec=False)¶ Save the interface variables into the lights variables.
- Parameters
beam_selec (int, bool, optional) – Number of the beam to save into the variables. False by default to get the currently displayed beam.
-
save_quick
()¶ Check if a file is already selected and if so, save into it. Else, call the
save_file_name()
to ask a filename.
-
show_estimate_time
()¶ Display - on the interface - the estimate time needed to compute the propagation, based on linearized experimental values. The estimation takes into account the looses, Kerr, and control parameters.
-
-
beampy.user_interface.
open_app
()¶ Function used to open the app. Can be called directly from beampy.
-
beampy.user_interface.
open_doc
()¶ Function that open the local html documentation - describing the beampy modules - if exist, or the online version otherwise.