Quantum algorithms

This submodule provides access to various utility functions that act on Gaussian quantum states.

For more details on how the hafnian relates to various properties of Gaussian quantum states, see:

Fock states and tensors

pure_state_amplitude(mu, cov, i[, …])

Returns the \(\langle i | \psi\rangle\) element of the state ket of a Gaussian state defined by covariance matrix cov.

state_vector(mu, cov[, post_select, …])

Returns the state vector of a (PNR post-selected) Gaussian state.

density_matrix_element(mu, cov, i, j[, …])

Returns the \(\langle i | \rho | j \rangle\) element of the density matrix of a Gaussian state defined by covariance matrix cov.

density_matrix(mu, cov[, post_select, …])

Returns the density matrix of a (PNR post-selected) Gaussian state.

fock_tensor(S, alpha, cutoff[, choi_r, …])

Calculates the Fock representation of a Gaussian unitary parametrized by the symplectic matrix S and the displacements alpha up to cutoff in Fock space.

probabilities(mu, cov, cutoff[, parallel, …])

Generate the Fock space probabilities of a Gaussian state up to a Fock space cutoff.

loss_mat(eta, cutoff)

Constructs a binomial loss matrix with transmission eta up to n photons.

update_probabilities_with_loss(etas, probs)

Given a list of transmissivities a tensor of probabilitites, calculate an updated tensor of probabilities after loss is applied.

update_probabilities_with_noise(probs_noise, …)

Given a list of noise probability distributions for each of the modes and a tensor of probabilitites, calculate an updated tensor of probabilities after noise is applied.

find_classical_subsystem(cov[, hbar, atol])

Find the largest integer k so that subsystem in modes [0,1,...,k-1] is a classical state.

tvd_cutoff_bounds(mu, cov, cutoff[, hbar, …])

Gives bounds of the total variation distance between the exact Gaussian Boson Sampling distribution extending to infinity in Fock space and the ones truncated by any value between 0 and the user provided cutoff.

n_body_marginals(mean, cov, cutoff, n[, hbar])

Calculates the first n-body marginals of a Gaussian state.

Adjacency matrices

adj_scaling(A, n_mean)

Returns the scaling parameter by which the adjacency matrix A should be rescaled so that the Gaussian state that endodes it has a total mean photon number n_mean.

adj_scaling_torontonian(A, c_mean)

Returns the scaling parameter by which the adjacency matrix A should be rescaled so that the Gaussian state that encodes it has give a mean number of clicks equal to c_mean when measured with threshold detectors.

adj_to_qmat(A, n_mean)

Returns the Qmat xp-covariance matrix associated to a graph with adjacency matrix \(A\) and with mean photon number \(n_{mean}\).

Gaussian checks

is_valid_cov(cov[, hbar, rtol, atol])

Checks if the covariance matrix is a valid quantum covariance matrix.

is_pure_cov(cov[, hbar, rtol, atol])

Checks if the covariance matrix is a valid quantum covariance matrix that corresponds to a quantum pure state

is_classical_cov(cov[, hbar, atol])

Checks if the covariance matrix can be efficiently sampled.

fidelity(mu1, cov1, mu2, cov2[, hbar, rtol, …])

Calculates the fidelity between two Gaussian quantum states.

Conversions

reduced_gaussian(mu, cov, modes)

Returns the vector of means and the covariance matrix of the specified modes.

Xmat(N)

Returns the matrix \(X_n = \begin{bmatrix}0 & I_n\\ I_n & 0\end{bmatrix}\)

Qmat(cov[, hbar])

Returns the \(Q\) Husimi matrix of the Gaussian state.

Covmat(Q[, hbar])

Returns the Wigner covariance matrix in the \(xp\)-ordering of the Gaussian state.

Amat(cov[, hbar, cov_is_qmat])

Returns the \(A\) matrix of the Gaussian state whose hafnian gives the photon number probabilities.

complex_to_real_displacements(mu[, hbar])

Returns the vector of complex displacements and conjugate displacements.

real_to_complex_displacements(beta[, hbar])

Returns the vector of real quadrature displacements.

Means and variances

photon_number_mean(mu, cov, j[, hbar])

Calculate the mean photon number of mode j of a Gaussian state.

photon_number_mean_vector(mu, cov[, hbar])

Calculate the mean photon number of each of the modes in a Gaussian state

photon_number_covar(mu, cov, j, k[, hbar])

Calculate the variance/covariance of the photon number distribution of a Gaussian state.

photon_number_covmat(mu, cov[, hbar])

Calculate the covariance matrix of the photon number distribution of a Gaussian state.

photon_number_expectation(mu, cov, modes[, hbar])

Calculates the expectation value of the product of the number operator of the modes in a Gaussian state.

photon_number_squared_expectation(mu, cov, modes)

Calculates the expectation value of the square of the product of the number operator of the modes in a Gaussian state.

normal_ordered_expectation(mu, cov, rpt[, hbar])

Calculates the expectation value of the normal ordered product \(\prod_{i=0}^{N-1} a_i^{\dagger n_i} \prod_{j=0}^{N-1} a_j^{m_j}\) with respect to an N-mode Gaussian state, where \(\text{rpt}=(n_0, n_1, \ldots, n_{N-1}, m_0, m_1, \ldots, m_{N-1})\).

photon_number_moment(mu, cov, indices[, hbar])

Calculates the expectation value of product of powers of photon number operators of a Gaussian state.

s_ordered_expectation(mu, cov, rpt[, hbar, s])

Calculates the expectation value of the s-ordered product obtained by taking deirvatives of the characteristic function of a Gaussian states, Here, \(\text{rpt}=(n_0, n_1, \ldots, n_{N-1}, m_0, m_1, \ldots, m_{N-1})\).

mean_clicks(cov[, hbar])

Calculates the total mean number of clicks when a zero-mean gaussian state is measured using threshold detectors.

variance_clicks(cov[, hbar])

Calculates the variance of the total number of clicks when a zero-mean gaussian state is measured using threshold detectors.

photon_number_cumulant(mu, cov, modes[, hbar])

Calculates the cumulant of the modes in the Gaussian state.

Photon number distributions

pure_state_distribution(cov[, cutoff, hbar, …])

Calculates the total photon number distribution of a pure state with zero mean.

total_photon_number_distribution(n, k, s, eta)

Probability of observing a total of \(n\) photons when \(k\) identical single-mode squeezed vacua with squeezing parameter \(s\) undergo loss by transmission \(\eta\).

characteristic_function(k, s, eta, mu[, …])

Calculates the expectation value of the characteristic function \(\langle n^m \exp(mu n) \rangle\) where \(n\) is the total photon number of \(k\) identical single-mode squeezed vacua with squeezing parameter \(s\) undergoing loss by transmission \(\eta\).

Details

Amat(cov, hbar=2, cov_is_qmat=False)[source]

Returns the \(A\) matrix of the Gaussian state whose hafnian gives the photon number probabilities.

Parameters
  • cov (array) – \(2N\times 2N\) covariance matrix

  • hbar (float) – the value of \(\hbar\) in the commutation relation \([\x,\p]=i\hbar\).

  • cov_is_qmat (bool) – if True, it is assumed that cov is in fact the Q matrix.

Returns

the \(A\) matrix.

Return type

array

Covmat(Q, hbar=2)[source]

Returns the Wigner covariance matrix in the \(xp\)-ordering of the Gaussian state. This is the inverse function of Qmat.

Parameters
  • Q (array) – \(2N\times 2N\) Husimi Q matrix

  • hbar (float) – the value of \(\hbar\) in the commutation relation \([\x,\p]=i\hbar\).

Returns

the \(xp\)-ordered covariance matrix in the xp-ordering.

Return type

array

Qmat(cov, hbar=2)[source]

Returns the \(Q\) Husimi matrix of the Gaussian state.

Parameters
  • cov (array) – \(2N\times 2N xp-\) Wigner covariance matrix

  • hbar (float) – the value of \(\hbar\) in the commutation relation \([\x,\p]=i\hbar\).

Returns

the \(Q\) matrix.

Return type

array

Xmat(N)[source]

Returns the matrix \(X_n = \begin{bmatrix}0 & I_n\\ I_n & 0\end{bmatrix}\)

Parameters

N (int) – positive integer

Returns

\(2N\times 2N\) array

Return type

array

adj_scaling(A, n_mean)[source]

Returns the scaling parameter by which the adjacency matrix A should be rescaled so that the Gaussian state that endodes it has a total mean photon number n_mean.

Parameters
  • A (array) – Adjacency matrix

  • n_mean (float) – Mean photon number of the Gaussian state

Returns

Scaling parameter

Return type

float

adj_scaling_torontonian(A, c_mean)[source]

Returns the scaling parameter by which the adjacency matrix A should be rescaled so that the Gaussian state that encodes it has give a mean number of clicks equal to c_mean when measured with threshold detectors.

Parameters
  • A (array) – adjacency matrix

  • c_mean (float) – mean photon number of the Gaussian state

Returns

scaling parameter

Return type

float

adj_to_qmat(A, n_mean)[source]

Returns the Qmat xp-covariance matrix associated to a graph with adjacency matrix \(A\) and with mean photon number \(n_{mean}\).

Parameters
  • A (array) – a \(N\times N\) np.float64 (symmetric) adjacency matrix

  • n_mean (float) – mean photon number of the Gaussian state

Returns

the \(2N\times 2N\) Q matrix.

Return type

array

characteristic_function(k, s, eta, mu, max_iter=10000, delta=1e-14, poly_corr=None)[source]

Calculates the expectation value of the characteristic function \(\langle n^m \exp(mu n) \rangle\) where \(n\) is the total photon number of \(k\) identical single-mode squeezed vacua with squeezing parameter \(s\) undergoing loss by transmission \(\eta\).

Parameters
  • k (int) – number of squeezed modes

  • s (float) – squeezing parameter

  • eta (float) – transmission parameter, between 0 and 1 inclusive

  • mu (float) – value at which to evaluate the characteristic function

  • max_iter (int) – maximum number of terms allowed in the sum

  • delta (float) – fractional change in the sum after which the sum is stopped

  • poly_corr (int) – give the value of the exponent \(m\) of the polynomial correction

Returns

the expected value of the moment generation function

Return type

(float)

complex_to_real_displacements(mu, hbar=2)[source]

Returns the vector of complex displacements and conjugate displacements.

Parameters
  • mu (array) – length-\(2N\) means vector

  • hbar (float) – the value of \(\hbar\) in the commutation relation \([\x,\p]=i\hbar\).

Returns

the expectation values \([\langle a_1\rangle, \langle a_2\rangle,\dots,\langle a_N\rangle, \langle a^\dagger_1\rangle, \dots, \langle a^\dagger_N\rangle]\)

Return type

array

fidelity(mu1, cov1, mu2, cov2, hbar=2, rtol=1e-05, atol=1e-08)[source]

Calculates the fidelity between two Gaussian quantum states. For two pure states \(|\psi_1 \rangle, \ |\psi_2 \rangle\) the fidelity is given by \(|\langle \psi_1|\psi_2 \rangle|^2\)

Note that if the covariance matrices correspond to pure states this function reduces to the modulus square of the overlap of their state vectors. For the derivation see ‘Quantum Fidelity for Arbitrary Gaussian States’, Banchi et al..

The actual implementation used here corresponds to the square of Eq. 96 of ‘Gaussian states and operations - a quick reference’, Brask.

Parameters
  • mu1 (array) – vector of means of the first state

  • cov1 (array) – covariance matrix of the first state

  • mu2 (array) – vector of means of the second state

  • cov2 (array) – covariance matrix of the second state

  • hbar (float) – value of hbar in the uncertainty relation

  • rtol (float) – the relative tolerance parameter used in np.allclose

  • atol (float) – the absolute tolerance parameter used in np.allclose

Returns

value of the fidelity between the two states

Return type

(float)

find_classical_subsystem(cov, hbar=2, atol=1e-08)[source]

Find the largest integer k so that subsystem in modes [0,1,...,k-1] is a classical state.

Parameters
  • cov (array) – a covariance matrix

  • hbar (float) – value of hbar in the uncertainty relation

  • atol (float) – the absolute tolerance parameter used when determining if the state is classical

Returns

the largest k so that modes [0,1,...,k-1] are in a classical state.

Return type

int

fock_tensor(S, alpha, cutoff, choi_r=0.881373587019543, check_symplectic=True, sf_order=False, rtol=1e-05, atol=1e-08)[source]

Calculates the Fock representation of a Gaussian unitary parametrized by the symplectic matrix S and the displacements alpha up to cutoff in Fock space.

Parameters
  • S (array) – symplectic matrix

  • alpha (array) – complex vector of displacements

  • cutoff (int) – cutoff in Fock space

  • choi_r (float) – squeezing parameter used for the Choi expansion

  • check_symplectic (boolean) – checks whether the input matrix is symplectic

  • sf_order (boolean) – reshapes the tensor so that it follows the sf ordering of indices

  • rtol (float) – the relative tolerance parameter used in np.allclose

  • atol (float) – the absolute tolerance parameter used in np.allclose

Returns

Tensor containing the Fock representation of the Gaussian unitary

Return type

(array)

is_classical_cov(cov, hbar=2, atol=1e-08)[source]

Checks if the covariance matrix can be efficiently sampled.

Parameters
  • cov (array) – a covariance matrix

  • hbar (float) – value of hbar in the uncertainty relation

  • atol (float) – the absolute tolerance parameter used in np.allclose

Returns

whether the given covariance matrix corresponds to a classical state

Return type

(bool)

is_pure_cov(cov, hbar=2, rtol=1e-05, atol=1e-08)[source]

Checks if the covariance matrix is a valid quantum covariance matrix that corresponds to a quantum pure state

Parameters
  • cov (array) – a covariance matrix

  • hbar (float) – value of hbar in the uncertainty relation

  • rtol (float) – the relative tolerance parameter used in np.allclose

  • atol (float) – the absolute tolerance parameter used in np.allclose

Returns

whether the given covariance matrix corresponds to a pure state

Return type

(bool)

is_valid_cov(cov, hbar=2, rtol=1e-05, atol=1e-08)[source]

Checks if the covariance matrix is a valid quantum covariance matrix.

Parameters
  • cov (array) – a covariance matrix

  • hbar (float) – value of hbar in the uncertainty relation

  • rtol (float) – the relative tolerance parameter used in np.allclose

  • atol (float) – the absolute tolerance parameter used in np.allclose

Returns

whether the given covariance matrix is a valid covariance matrix

Return type

(bool)

loss_mat(eta, cutoff)[source]

Constructs a binomial loss matrix with transmission eta up to n photons.

Parameters
  • eta (float) – Transmission coefficient. eta=0.0 corresponds to complete loss and eta=1.0 corresponds to no loss.

  • cutoff (int) – cutoff in Fock space.

Returns

\(n\times n\) matrix representing the loss.

Return type

array

mean_clicks(cov, hbar=2)[source]

Calculates the total mean number of clicks when a zero-mean gaussian state is measured using threshold detectors.

Args

cov (array): \(2N\times 2N\) covariance matrix in xp-ordering hbar (float): the value of \(\hbar\) in the commutation relation \([\x,\p]=i\hbar\)

Returns

float: mean number of clicks

n_body_marginals(mean, cov, cutoff, n, hbar=2)[source]

Calculates the first n-body marginals of a Gaussian state.

For an M-mode Gaussian state there exists a photon number distribution with probability mass function \(p[i_0,i_1,\ldots, i_{M-1}]\). The function n_body_marginals calculates the first n-body marginals of the (all-mode) probability distribution \(p\). The \(n=1\) marginals or single body marginals are simply the probability that mode \(k\) has \(i\) photons, i.e. \(p_k[i]\). For \(n=2\) one obtains the two-body probabilities. For two modes \(k\) and \(l\) this is a two dimensional probability distribution \(p_{k,l}[i,j]\). Note that these marginals have interesting permutation properties, for example \(p_{k,l}[i,j] = p_{l,k}[j,i]\).

The function provided here takes advantage of these symmetries to minimize the amount of calculations. The return of this function is a list of tensors where the first entry contains the one-body marginals of the \(M\) modes (giving a tensor of shape (M, cutoff)), the second entry contains the two-body marginals (giving a tensor of shape (M,M,cutoff, cutoff)) and so on and so forth.

To be clever about not calculating things that can be obtained by permutations it checks whether the index vector representing the modes is sorted. From the way itertools.product works we know that it will always produce a sorted index vector before generating any of its unordered permutations. Thus whenever the index vector is ordered we perform the numerical calculation.

If it is an unsorted index vector it realizes, in the if statement, that it can be obtained by permuting the marginal distribution of something that has already been calculated.

Parameters
  • mean (array) – length-\(2N\) quadrature displacement vector

  • cov (array) – length-\(2N\) covariance matrix

  • cutoff (int) – cutoff in Fock space

  • n (int) – order of the correlations

  • hbar (float) – the value of \(\hbar\) in the commutation relation \([\x,\p]=i\hbar\).

Returns

List with arrays containing the \(1,..,n\) body marginal

distributions of the modes

Return type

list[array]

normal_ordered_expectation(mu, cov, rpt, hbar=2)[source]

Calculates the expectation value of the normal ordered product \(\prod_{i=0}^{N-1} a_i^{\dagger n_i} \prod_{j=0}^{N-1} a_j^{m_j}\) with respect to an N-mode Gaussian state, where \(\text{rpt}=(n_0, n_1, \ldots, n_{N-1}, m_0, m_1, \ldots, m_{N-1})\).

Parameters
  • mu (array) – length-\(2N\) means vector in xp-ordering.

  • cov (array) – \(2N\times 2N\) covariance matrix in xp-ordering.

  • rpt (list) – integers specifying the terms to calculate.

  • hbar (float) – value of hbar in the uncertainty relation.

Returns

expectation value of the normal ordered product of operators

Return type

(float)

photon_number_covar(mu, cov, j, k, hbar=2)[source]

Calculate the variance/covariance of the photon number distribution of a Gaussian state.

Implements the covariance matrix of the photon number distribution of a Gaussian state according to the Last two eq. of Part II. in ‘Multidimensional Hermite polynomials and photon distribution for polymode mixed light’, Dodonov et al.

\[\begin{split}\sigma_{n_j n_j} &= \frac{1}{2}\left(T_j^2 - 2d_j - \frac{1}{2}\right) + \left<\mathbf{Q}_j\right>\mathcal{M}_j\left<\mathbf{Q}_j\right>, \\ \sigma_{n_j n_k} &= \frac{1}{2}\mathrm{Tr}\left(\Lambda_j \mathbf{M} \Lambda_k \mathbf{M}\right) + \left<\mathbf{Q}\right>\Lambda_j \mathbf{M} \Lambda_k\left<\mathbf{Q}\right>,\end{split}\]

where \(T_j\) and \(d_j\) are the trace and the determinant of \(2 \times 2\) matrix \(\mathcal{M}_j\) whose elements coincide with the nonzero elements of matrix \(\mathbf{M}_j = \Lambda_j \mathbf{M} \Lambda_k\) while the two-vector \(\mathbf{Q}_j\) has the components \((q_j, p_j)\). \(2N \times 2N\) projector matrix \(\Lambda_j\) has only two nonzero elements: \(\left(\Lambda_j\right)_{jj} = \left(\Lambda_j\right)_{j+N,j+N} = 1\). Note that the convention for mu used here differs from the one used in Dodonov et al., They both provide the same results in this particular case. Also note that the original reference of Dodonov et al. has an incorrect prefactor of 1/2 in the last terms of the last equation above.

Parameters
  • mu (array) – vector of means of the Gaussian state using the ordering \([q_1, q_2, \dots, q_n, p_1, p_2, \dots, p_n]\)

  • cov (array) – the covariance matrix of the Gaussian state

  • j (int) – the j th mode

  • k (int) – the k th mode

  • hbar (float) – the hbar convention used in the commutation relation \([q, p]=i\hbar\)

Returns

the covariance for the photon numbers at modes \(j\) and \(k\).

Return type

float

photon_number_covmat(mu, cov, hbar=2)[source]

Calculate the covariance matrix of the photon number distribution of a Gaussian state.

Parameters
  • mu (array) – vector of means of the Gaussian state using the ordering \([q_1, q_2, \dots, q_n, p_1, p_2, \dots, p_n]\)

  • cov (array) – the covariance matrix of the Gaussian state

  • hbar (float) – the hbar convention used in the commutation relation \([q, p]=i\hbar\)

Returns

the covariance matrix of the photon number distribution

Return type

array

photon_number_cumulant(mu, cov, modes, hbar=2)[source]

Calculates the cumulant of the modes in the Gaussian state.

Parameters
  • mu (array) – length-\(2N\) means vector in xp-ordering.

  • cov (array) – \(2N\times 2N\) covariance matrix in xp-ordering.

  • modes (list or array) – list of modes. Note that it can have repetitions.

  • hbar (float) – value of hbar in the uncertainty relation.

Returns

the cumulant

Return type

(float)

photon_number_expectation(mu, cov, modes, hbar=2)[source]

Calculates the expectation value of the product of the number operator of the modes in a Gaussian state.

Parameters
  • mu (array) – length-\(2N\) means vector in xp-ordering.

  • cov (array) – \(2N\times 2N\) covariance matrix in xp-ordering.

  • modes (list) – list of modes

  • hbar (float) – value of hbar in the uncertainty relation.

Returns

expectation value of the product of the number operators of the modes.

Return type

(float)

photon_number_mean(mu, cov, j, hbar=2)[source]

Calculate the mean photon number of mode j of a Gaussian state.

Parameters
  • mu (array) – vector of means of the Gaussian state using the ordering \([q_1, q_2, \dots, q_n, p_1, p_2, \dots, p_n]\)

  • cov (array) – the covariance matrix of the Gaussian state

  • j (int) – the j th mode

  • hbar (float) – the hbar convention used in the commutation relation \([q, p]=i\hbar\)

Returns

the mean photon number in mode \(j\).

Return type

float

photon_number_mean_vector(mu, cov, hbar=2)[source]

Calculate the mean photon number of each of the modes in a Gaussian state

Parameters
  • mu (array) – vector of means of the Gaussian state using the ordering \([q_1, q_2, \dots, q_n, p_1, p_2, \dots, p_n]\)

  • cov (array) – the covariance matrix of the Gaussian state

  • hbar (float) – the hbar convention used in the commutation relation \([q, p]=i\hbar\)

Returns

the vector of means of the photon number distribution

Return type

array

photon_number_moment(mu, cov, indices, hbar=2)[source]

Calculates the expectation value of product of powers of photon number operators of a Gaussian state. The powers are specified by a dictionary with modes as keys and powers as values.

The calculation is performed by first writing any power of the photon number as

\((a^\dagger a)^m = \sum_{k=1}^m c_k a^{\dagger k} a^k\)

where the coefficients \(c_i\) are provided by the function _coeff_normal_ordered.

Parameters
  • mu (array) – length-\(2N\) means vector in xp-ordering.

  • cov (array) – \(2N\times 2N\) covariance matrix in xp-ordering.

  • indices (dictionary) – specification of the different modes and their power of their photon number

  • hbar (float) – value of hbar in the uncertainty relation.

Returns

the expectation value of the photon number powers.

Return type

float

photon_number_squared_expectation(mu, cov, modes, hbar=2)[source]

Calculates the expectation value of the square of the product of the number operator of the modes in a Gaussian state.

Parameters
  • mu (array) – length-\(2N\) means vector in xp-ordering.

  • cov (array) – \(2N\times 2N\) covariance matrix in xp-ordering.

  • modes (list) – list of modes

  • hbar (float) – value of hbar in the uncertainty relation.

Returns

expectation value of the square of the product of the number operator of the modes.

Return type

(float)

probabilities(mu, cov, cutoff, parallel=False, hbar=2.0, rtol=1e-05, atol=1e-08)[source]

Generate the Fock space probabilities of a Gaussian state up to a Fock space cutoff.

Note

Individual density matrix elements are computed using multithreading by OpenMP. Setting parallel=True will further result in multiple density matrix elements being computed in parallel.

When setting parallel=True, OpenMP will need to be turned off by setting the environment variable OMP_NUM_THREADS=1 (forcing single threaded use for individual matrix elements). Remove the environment variable or set it to OMP_NUM_THREADS='' to again use multithreading with OpenMP.

Parameters
  • mu (array) – vector of means of length 2*n_modes

  • cov (array) – covariance matrix of shape [2*n_modes, 2*n_modes]

  • cutoff (int) – cutoff in Fock space

  • parallel (bool) – if True, uses dask for parallelization instead of OpenMP

  • hbar (float) – value of \(\hbar\) in the commutation relation :math;`[hat{x}, hat{p}]=ihbar`

  • rtol (float) – the relative tolerance parameter used in np.allclose

  • atol (float) – the absolute tolerance parameter used in np.allclose

Returns

Fock space probabilities up to cutoff. The shape of this tensor is [cutoff]*num_modes.

Return type

(array)

pure_state_distribution(cov, cutoff=50, hbar=2, padding_factor=2)[source]

Calculates the total photon number distribution of a pure state with zero mean.

Parameters
  • cov (array) – \(2N\times 2N\) covariance matrix in xp-ordering

  • cutoff (int) – Fock cutoff

  • tol (float) – tolerance for determining if displacement is negligible

  • hbar (float) – the value of \(\hbar\) in the commutation

  • padding_factor (int) – expanded size of the photon distribution to avoid accumulation of errors

Returns

Total photon number distribution

Return type

(array)

real_to_complex_displacements(beta, hbar=2)[source]

Returns the vector of real quadrature displacements.

Parameters
  • beta (array) – length-\(2N\) means bivector

  • hbar (float) – the value of \(\hbar\) in the commutation relation \([\x,\p]=i\hbar\).

Returns

the quadrature expectation values \([\langle q_1\rangle, \langle q_2\rangle,\dots,\langle q_N\rangle, \langle p_1\rangle, \dots, \langle p_N\rangle]\)

Return type

array

reduced_gaussian(mu, cov, modes)[source]

Returns the vector of means and the covariance matrix of the specified modes.

Parameters
  • mu (array) – a length-\(2N\) np.float64 vector of means.

  • cov (array) – a \(2N\times 2N\) np.float64 covariance matrix representing an \(N\) mode quantum state.

  • modes (int of Sequence[int]) – indices of the requested modes

Returns

where means is an array containing the vector of means, and cov is a square array containing the covariance matrix.

Return type

tuple (means, cov)

s_ordered_expectation(mu, cov, rpt, hbar=2, s=0)[source]

Calculates the expectation value of the s-ordered product obtained by taking deirvatives of the characteristic function of a Gaussian states, Here, \(\text{rpt}=(n_0, n_1, \ldots, n_{N-1}, m_0, m_1, \ldots, m_{N-1})\). indicates how many derivatives are taken with respect to the complex argument and its conjugate. The values \(s=\{1,0,-1\}\) correspond respectively to normal, symmetric and antinormal order.

Parameters
  • mu (array) – length-\(2N\) means vector in xp-ordering.

  • cov (array) – \(2N\times 2N\) covariance matrix in xp-ordering.

  • rpt (list) – integers specifying the terms to calculate.

  • hbar (float) – value of hbar in the uncertainty relation.

  • s (float) – value setting the ordering it must be between -1 and 1.

Returns

expectation value of the normal ordered product of operators

Return type

(float)

total_photon_number_distribution(n, k, s, eta, pref=1.0)[source]

Probability of observing a total of \(n\) photons when \(k\) identical single-mode squeezed vacua with squeezing parameter \(s\) undergo loss by transmission \(\eta\).

For the derivation see Appendix E of ‘Quantum Computational Supremacy via High-Dimensional Gaussian Boson Sampling’, Deshpande et al..

Parameters
  • n (int) – number of photons

  • k (int) – number of squeezed modes

  • s (float) – squeezing parameter

  • eta (float) – transmission parameter, between 0 and 1 inclusive

  • pref (float) – use to return the probability times pref**n

Returns

probability of observing a total of n photons or the probability times pref ** n.

Return type

(float)

tvd_cutoff_bounds(mu, cov, cutoff, hbar=2, check_is_valid_cov=True, rtol=1e-05, atol=1e-08)[source]

Gives bounds of the total variation distance between the exact Gaussian Boson Sampling distribution extending to infinity in Fock space and the ones truncated by any value between 0 and the user provided cutoff.

For the derivation see Appendix B of ‘Exact simulation of Gaussian boson sampling in polynomial space and exponential time’, Quesada and Arrazola.

Parameters
  • mu (array) – vector of means of the Gaussian state

  • cov (array) – covariance matrix of the Gaussian state

  • cutoff (int) – cutoff in Fock space

  • check_is_valid_cov (bool) – verify that the covariance matrix is physical

  • hbar (float) – value of hbar in the uncertainty relation

  • rtol (float) – the relative tolerance parameter used in np.allclose

  • atol (float) – the absolute tolerance parameter used in np.allclose

Returns

values of the bound for different local Fock space dimensions up to cutoff

Return type

(array)

update_probabilities_with_loss(etas, probs)[source]

Given a list of transmissivities a tensor of probabilitites, calculate an updated tensor of probabilities after loss is applied.

Parameters
  • etas (list) – List of transmissitivities describing the loss in each of the modes

  • probs (array) – Array of probabilitites in the different modes

Returns

List of loss-updated probabilities with the same shape as probs.

Return type

array

update_probabilities_with_noise(probs_noise, probs)[source]

Given a list of noise probability distributions for each of the modes and a tensor of probabilitites, calculate an updated tensor of probabilities after noise is applied.

Parameters
  • probs_noise (list) – List of probability distributions describing the noise in each of the modes

  • probs (array) – Array of probabilitites in the different modes

Returns

List of noise-updated probabilities with the same shape as probs.

Return type

array

variance_clicks(cov, hbar=2)[source]

Calculates the variance of the total number of clicks when a zero-mean gaussian state is measured using threshold detectors.

Args

cov (array): \(2N\times 2N\) covariance matrix in xp-ordering hbar (float): the value of \(\hbar\) in the commutation relation \([\x,\p]=i\hbar\)

Returns

float: variance in the total number of clicks