gausstorch.libs package

Submodules

gausstorch.libs.qsyst module

Module constaining the Qsyst class. An instance contains the drive, detuning, coupling and dissipation parameters of a M mode system.

The Qsyst methods will then be used to compute the displacement and covariance matrices of the system after time evolutions under input encoding.

class gausstorch.libs.qsyst.Qsyst(init_pars: dict, learnable_vars: list = [], init_print: bool = False)[source]

Bases: Module

Class allowing for the simulation of coupled gaussian modes.

Parameters:
  • init_pars (dict) – Dict containing drive, detuning, coupling, dissipation parameters, and time interval. See the init_pars_default() function for a template.

  • learnable_vars (list, optional) – List containing the parameters to learn (with autograd enabled). By default, no parameter has gradient computation enabled.

  • init_print (bool, optional) – Bool checking whether to print a message during instance creation or not. Defaults to False.

init_pars

Deep copy of init_pars.

Type:

dict

learnable_vars

Deep copy of learnable_vars.

Type:

dict

syst_vars

Possibly trainable parameters of the system.

Type:

torch.nn.ParameterDict

other_pars

Parameters which are never trainable.

Type:

dict

M

Number of modes.

Type:

int

g_shape

Number of coupling combinations.

Type:

int

alpha0

Displacement vector of the vacuum.

Type:

torch.Tensor

sigma0

Covariance matrix of the vacuum

Type:

torch.Tensor

alpha_sigma_evolution(t: Tensor, alpha_i: Tensor, sigma_i: Tensor, theta_key: str, theta_encoded: Tensor) tuple[source]

Computes a gaussian state displacement and covariance matrix after a time evolution

Parameters:
  • t (torch.Tensor) – duration of evolution from gaussian state (d_i, sigma_i) state to measurement

  • alpha_i (torch.Tensor) – initial displacement

  • sigma_i (torch.Tensor) – initial covariance

  • theta_key (str) – key of the encoding parameter

  • theta_encoded (torch.Tensor) – value of the encoding parameter

  • t – Duration of evolution from gaussian state (d_i, sigma_i) state to measurement.

  • alpha_i – Initial displacement vector.

  • sigma_i – Initial covariance matrix.

  • theta_key – Name of the encoding parameter

  • theta_encoded – Value of the encoded parameter.

Returns:

new gaussian state (alpha_output, sigma_output)

Return type:

tuple

Returns:

New gaussian state (alpha_output, sigma_output).

Return type:

tuple

alpha_sigma_evolution_part_1(theta_key: str, theta_encoded: Tensor) tuple[source]

Diagonalize the coupling matrix with dissipations.

Parameters:
  • theta_key (str) – Key of the encoding parameters.

  • theta_encoded (torch.Tensor) – Value of the encoded parameter.

Returns:

lambda_F, U, Uinv, K_int, K_ext, the eigenvalue decomposition and dissipation matrices

Return type:

tuple

alpha_sigma_evolution_part_2(theta_key: str, theta_encoded: Tensor, t: Tensor, alpha_i: Tensor, sigma_i: Tensor, lambda_F: Tensor, U: Tensor, Uinv: Tensor, K_int: Tensor, K_ext: Tensor) tuple[source]

Computes the displacement (alpha) and covariance matrix (sigma) using the coupling matrix eigenvalue decomposition, and the evolution time t.

Parameters:
  • theta_key (str) – Key of the encoding parameter.

  • theta_encoded (torch.Tensor) – Encoded parameter value.

  • t (torch.Tensor) – Duration of the time evolution.

  • alpha_i (torch.Tensor) – Displacement value.

  • sigma_i (torch.Tensor) – Covariance matrix.

  • lambda_F (torch.Tensor) – Coupling matrix eigenvalue

  • U (torch.Tensor) – Coupling matrix eigenvectors (each column is an eigenvector)

  • Uinv (torch.Tensor) – Inverse of U

  • K_int (torch.Tensor) – Diagonal matrix containing internal dissipations

  • K_ext (torch.Tensor) – Diagonal matrix containing external dissipations

Returns:

Displacement vector and Covariance matrix

Return type:

tuple

create_coupling_matrices(detuning: Tensor, g_cplx: Tensor, gs_cplx: Tensor) Tensor[source]
Parameters:
  • detuning (torch.Tensor) – 1D tensor containing the detunings of the nearly resonant drives

  • g_cplx (torch.Tensor) – 1D tensor containing the photon conversion rates

  • gs_cplx (torch.Tensor) – 1D tensor containing the two-mode squeezing rates

Returns:

Coupling matrix (defined in my PhD thesis at equation 5.46)

Return type:

torch.Tensor

encode_theta(theta_0: Tensor, x_mask: Tensor, x_min: Tensor, x_max: Tensor, encode_phase: bool) Tensor[source]
Parameters:
  • theta_0 (torch.Tensor) – Encoding parameter value, before encoding the inputs x_mask

  • x_mask (torch.Tensor) – Input values, in a 1-D tensor of the same shape as theta_0

  • x_min (torch.Tensor) – Minimum input value (used to rescale the input between x_min and x_max)

  • x_max (torch.Tensor) – Maximum input value (used to rescale the input between x_min and x_max)

  • encode_phase (bool) – Bool deciding whether to encode into the absolute value or the phase of the encoding parameter (equations 5.105 and 5.106 in my thesis)

Returns:

Encoded parameter value

Return type:

torch.Tensor

evolution_N(theta_key: str = 'eA', x_val: Tensor = tensor(1), x_min: Tensor = tensor(0), x_max: Tensor = tensor(1), encode_phase: bool = False, res: int = 1000, compute_plot: bool = True, yscale: str = 'linear', show_plot: bool = True, inference_mode: bool = True, return_vals: bool = False, return_tspan: bool = False)[source]

Plots or computes the time evolution of the system during a time interval

Parameters:
  • x_val (torch.Tensor, optional) – Input value. Defaults to torch.tensor(1).

  • x_min (torch.Tensor, optional) – Minimum input value (for input rescaling). Defaults to torch.tensor(0).

  • x_max (torch.Tensor, optional) – Maximum input value (for input rescaling). Defaults to torch.tensor(1).

  • encode_phase (bool, optional) – If True, the input is encoded into the phase of the encoding parameter. Defaults to False.

  • res (int, optional) – Number of points to compute. Defaults to 1_000.

  • compute_plot (bool, optional) – If True, the plot is computed. Defaults to True.

  • yscale (str, optional) – Choice of yscale. Defaults to ‘linear’.

  • show_plot (bool, optional) – If True, plot is shown with plt.show(). Defaults to True.

  • inference_mode (bool, optional) – If True, no gradients are computed. Defaults to True.

  • return_vals (bool, optional) – If True, return photon number values. Defaults to False.

  • return_tspan (bool, optional) – If True, also return discrete time values. Defaults to False.

Returns:

Either None, or photon number values with discrete time values

evolution_fock(fock_combs_per_mode_comb: dict = None, theta_key: str = 'eA', x_val: Tensor = tensor(1), x_min: Tensor = tensor(0), x_max: Tensor = tensor(1), encode_phase: bool = False, res: int = 1000, compute_plot: bool = True, show_plot: bool = True, inference_mode: bool = True, return_vals: bool = False)[source]

Plots or compute the Fock state occupation probabilities during a time interval

Parameters:
  • fock_combs_per_mode_comb (dict, optional) – Fock state combinations to plot. Defaults to None.

  • theta_key (str, optional) – Name of the encoding parameter. Defaults to ‘eA’.

  • x_val (torch.Tensor, optional) – Input value. Defaults to torch.tensor(1).

  • x_min (torch.Tensor, optional) – Minimum input value (for input rescaling). Defaults to torch.tensor(0).

  • x_max (torch.Tensor, optional) – Maximum input value (for input rescaling). Defaults to torch.tensor(1).

  • encode_phase (bool, optional) – If True, input is encoded into the phase of the encoding parameter. Defaults to False.

  • res (int, optional) – Number of discrete time steps. Defaults to 1_000.

  • compute_plot (bool, optional) – If True, compute the plot. Defaults to True.

  • show_plot (bool, optional) – If True, plot is shown with plt.show(). Defaults to True.

  • inference_mode (bool, optional) – If True, gradient calculations are disabled. Defaults to True.

  • return_vals (bool, optional) – If True, return Fock states values. Defaults to False.

Returns:

Either None, or torch.Tensor containing Fock state

make_other_pars() dict[source]
Returns:

Dict containing parameters which can never be learned.

Return type:

dict

Note

Only includes the time interval t_i at the moment.

make_syst_vars() ParameterDict[source]
Returns:

Parameters to learn in key-value pairs.

Return type:

nn.ParameterDict

prob_gbs(alpha: Tensor, sigma: Tensor, n: list, n_shots: int = None) Tensor[source]

This function uses the global GBS formula to calculate a Fock state occupation probability from the field operator displacement vector alpha and covariance matrix sigma.

Parameters:
  • alpha (torch.Tensor) – Field operator displacement vector

  • sigma (torch.Tensor) – Field operator covariance matrix

  • n (list) – List containing the number of photons to measure in each mode

  • n_shots (int, optional) – Number of measurement shots. Defaults to None, in which case perfectly accurate estimations are considered.

Returns:

Fock state occupation probability

Return type:

torch.Tensor

prob_gbs_partial_trace(alpha: Tensor, sigma: Tensor, n: list, modes_kept: list, n_shots: int = None) Tensor[source]

This function uses the GBS formula to calculate P(n) from the 1st and 2nd moments. All the modes except the ones contained in modes_kept are traced. n is the list containing the photon combination to measure, after the partial trace.

Example

If M = 3, modes_kept = [0, 2], n = [2, 4],

This means you trace out mode 1, and compute the probability of measuring 2 photons in mode 0, and 4 photons in mode 2.

Parameters:
  • alpha (torch.Tensor) – Field operator displacement vector.

  • sigma (torch.Tensor) – Field operator covariance matrix.

  • n (list) – List containing the number of photons to measure in each considered mode

  • modes_kept (list) – List of considered modes

  • n_shots (int, optional) – Number of measurement shots. Defaults to None, in which case perfectly accurate estimations are considered.

Returns:

Fock state occupation probability

Return type:

torch.Tensor

static prob_with_shots(prob: Tensor, n_shots: int) Tensor[source]

Computes a probability for a given number of measurement shots with the binomial law

Parameters:
  • prob (torch.Tensor) – Probability of a Gaussian Boson Sampling (GBS) probability

  • n_shots (int) – Number of measurement shots

Returns:

GBS probability with shot measurement noise

Return type:

torch.Tensor

return_theta_xmask(theta_key: str) tuple[source]
Parameters:

theta_key (str) – Key of encoding parameter theta

Returns:

theta_0 the syst.syst_vars parameter associated to theta_key, and xmask_shape the shape of the encoding parameter, for the later linear encoding with xmask

Return type:

tuple

gausstorch.libs.qsyst.init_pars_default(M: int) dict[source]
Parameters:

M (int) – Number of modes.

Returns:

Default parameter values for M modes.

Return type:

dict

gausstorch.libs.test_qsyst module

Test module for the gausstorch.libs.qsyst module.

gausstorch.libs.test_qsyst.test_alpha_after_time_evolution_g_only() None[source]

Check the displacement matches its theoretical value, after a time evolution with only real photon conversion, and 2 bosonic modes.

Module contents