Gaussian simulator backend

Module name: strawberryfields.backends.gaussianbackend

The GaussianBackend implements a simulation of quantum optical circuits using the Gaussian formalism. The primary component of the GaussianBackend is a GaussianModes object which is used to simulate a multi-mode quantum optical system. GaussianBackend provides the basic API-compatible interface to the simulator, while the GaussianModes object actually carries out the mathematical simulation.

The GaussianModes simulators maintains an internal covariance matrix – vector of means representation of a multi-mode quantum optical system.

Note that unlike commonly used covariance matrix representations we encode our state in two complex matrices \(N\) and \(M\) that are defined as follows \(N_{i,j} = \langle a^\dagger _i a_j \rangle\) \(M_{i,j} = \langle a _i a_j \rangle\) and a vector of means \(\alpha_i =\langle a_i \rangle\)

Basic quantum simulator methods

The GaussianBackend simulator implements a number of state preparations, gates, and measurements (listed below).

begin_circuit(num_subsystems[, cutoff_dim, …]) Create a quantum circuit (initialized in vacuum state) with number of modes equal to num_subsystems.
prepare_vacuum_state(mode) Prepare the vacuum state on the specified mode.
prepare_coherent_state(alpha, mode) Prepare a coherent state with parameter alpha on the specified mode.
prepare_squeezed_state(r, phi, mode) Prepare a coherent state with parameters (r, phi) on the specified mode.
prepare_displaced_squeezed_state(alpha, r, …) Prepare a displaced squezed state with parameters (alpha, r, phi) on the specified mode.
prepare_fock_state(n, mode)
prepare_ket_state(state, mode)
rotation(phi, mode) Perform a phase-space rotation by angle phi on the specified mode.
displacement(alpha, mode) Perform a displacement operation on the specified mode.
squeeze(z, mode) Perform a squeezing operation on the specified mode.
beamsplitter(t, r, mode1, mode2) Perform a beamsplitter operation on the specified modes.
loss(T, mode) Perform a loss channel operation on the specified mode.
measure_fock(modes[, select])
measure_homodyne(phi, mode[, select]) Perform a homodyne measurement on the specified modes.
measure_heterodyne(mode[, select]) Perform a heterodyne measurement on the specified modes.
is_vacuum([tol]) Numerically check that the fidelity of the circuit state with vacuum is within tol of 1.
del_mode(modes) Trace out the specified modes from the underlying circuit state.
add_mode([n]) Add n new modes to the underlying circuit state.
get_modes() Return the indices of the modes that are active (the ones that have not been deleted).
reset([pure]) Resets the circuit state back to an all-vacuum state.
state([modes]) Returns the vector of means and the covariance matrix of the specified modes.

Code details

class strawberryfields.backends.gaussianbackend.GaussianBackend[source]

Gaussian backend implementation

begin_circuit(num_subsystems, cutoff_dim=None, hbar=2, pure=None, **kwargs)[source]

Create a quantum circuit (initialized in vacuum state) with number of modes equal to num_subsystems.

Parameters:
  • num_subsystems (int) – number of modes the circuit should begin with
  • hbar (float) – The value of \(\hbar\) to initialise the circuit with, depending on the conventions followed. By default, \(\hbar=2\). See Conventions and formulas for more details.
add_mode(n=1)[source]

Add n new modes to the underlying circuit state. Indices for new modes always occur at the end of the covariance matrix.

Note: this will increase the number of indices used for the state representation.

Parameters:n (int) – the number of modes to be added to the circuit.
del_mode(modes)[source]

Trace out the specified modes from the underlying circuit state.

Note: this will reduce the number of indices used for the state representation.

Parameters:modes (list[int]) – the modes to be removed from the circuit.
get_modes()[source]

Return the indices of the modes that are active (the ones that have not been deleted).

Returns:the active modes in the circuit
Return type:active modes (list[int])
reset(pure=True, **kwargs)[source]

Resets the circuit state back to an all-vacuum state.

prepare_thermal_state(nbar, mode)[source]

Prepare the vacuum state on the specified mode.

Note: this may convert the state representation to mixed.

Parameters:
  • nbar (float) – mean number of photons in the mode
  • mode (int) – index of mode where state is prepared
prepare_vacuum_state(mode)[source]

Prepare the vacuum state on the specified mode.

Note: this may convert the state representation to mixed.

Parameters:mode (int) – index of mode where state is prepared
prepare_coherent_state(alpha, mode)[source]

Prepare a coherent state with parameter alpha on the specified mode.

Parameters:
  • alpha (complex) – coherent state displacement parameter
  • mode (int) – index of mode where state is prepared
prepare_squeezed_state(r, phi, mode)[source]

Prepare a coherent state with parameters (r, phi) on the specified mode.

Parameters:
  • r (float) – squeezing amplitude
  • phi (float) – squeezing phase
  • mode (int) – index of mode where state is prepared
rotation(phi, mode)[source]

Perform a phase-space rotation by angle phi on the specified mode.

Parameters:
  • phi (float) –
  • mode (int) – index of mode where operation is carried out
displacement(alpha, mode)[source]

Perform a displacement operation on the specified mode.

Parameters:
  • alpha (float) – displacement parameter
  • mode (int) – index of mode where operation is carried out
squeeze(z, mode)[source]

Perform a squeezing operation on the specified mode.

Parameters:
  • z (complex) – squeezing parameter
  • mode (int) – index of mode where operation is carried out
prepare_displaced_squeezed_state(alpha, r, phi, mode)[source]

Prepare a displaced squezed state with parameters (alpha, r, phi) on the specified mode. Note: this may convert the state representation to mixed.

Parameters:
  • alpha (complex) – displacement parameter
  • r (float) – squeezing amplitude
  • phi (float) – squeezing phase
  • mode (int) – index of mode where state is prepared
beamsplitter(t, r, mode1, mode2)[source]

Perform a beamsplitter operation on the specified modes.

It is assumed that \(|r|^2+|t|^2 = t^2+|r|^2=1\), i.e that t is real.

Parameters:
  • t (float) – transmittivity parameter
  • r (complex) – reflectivity parameter
  • mode1 (int) – index of first mode where operation is carried out
  • mode2 (int) – index of second mode where operation is carried out
measure_homodyne(phi, mode, select=None, **kwargs)[source]

Perform a homodyne measurement on the specified modes.

Note

The rotation has its sign flipped since the rotation in this case is defined to act on the measurement effect and not in the state

Parameters:
  • phi (float) – angle (relative to x-axis) for the measurement
  • mode (int) – index of mode where operation is carried out
  • **kwargs – Can be used to (optionally) pass user-specified numerical parameter eps. Homodyne amounts to projection onto a quadrature eigenstate. This eigenstate is approximated by a squeezed state whose variance has been squeezed to the amount eps, V_(meas) = eps**2. Perfect homodyning is obtained when eps o 0.
Returns:

measurement outcomes

Return type:

float or Tensor

measure_heterodyne(mode, select=None)[source]

Perform a heterodyne measurement on the specified modes.

Parameters:mode (int) – index of mode where operation is carried out
Returns:measurement outcome
Return type:complex
prepare_gaussian_state(r, V, modes)[source]

Prepare the given Gaussian state (via the provided vector of means and the covariance matrix) in the specified modes.

The requested mode(s) is/are traced out and replaced with the given Gaussian state.

Parameters:
  • r (array) – the vector of means in xp ordering.
  • V (array) – the covariance matrix in xp ordering.
  • modes (int or Sequence[int]) – which mode to prepare the state in If the modes are not sorted, this is take into account when preparing the state. i.e., when a two mode state is prepared in modes=[3,1], then the first mode of state goes into mode 3 and the second mode goes into mode 1 of the simulator.
is_vacuum(tol=0.0, **kwargs)[source]

Numerically check that the fidelity of the circuit state with vacuum is within tol of 1.

Parameters:tol (float) – value of the tolerance.
loss(T, mode)[source]

Perform a loss channel operation on the specified mode.

Parameters:
  • T (float) – loss parameter
  • mode (int) – index of mode where operation is carried out
thermal_loss(T, nbar, mode)[source]

Perform a thermal loss channel operation on the specified mode.

Parameters:
  • T (float) – loss parameter
  • nbar (float) – mean photon number of the environment thermal state
  • mode (int) – index of mode where operation is carried out
state(modes=None, **kwargs)[source]

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

Parameters:modes (list[int]) – indices of the requested modes. If none, all modes returned.
Returns:tuple (means, covmat) where means is a numpy array containing the mean values of the qaudratures and covmats is a numpy square array containing the covariance matrix of said modes

Gaussian state

This class which represents the quantum state returned by a Gaussian backend. It extends BaseGaussianState.

For other methods available, see the Quantum states API.

reduced_dm(modes, **kwargs) Returns the reduced density matrix in the Fock basis for a particular mode.

Code details

class strawberryfields.backends.gaussianbackend.GaussianState(state_data, num_modes, qmat, Amat, hbar=2.0, mode_names=None)[source]

Class for the representation of quantum states using Gaussian representation.

Parameters:
  • state_data (tuple(mu, cov)) – A tuple containing the vector of means mu and the covariance matrix cov.
  • num_modes (int) – the number of modes in the state
  • qmat (array) – The covariance matrix for the Q function
  • Amat (array) – The A matrix from Hamilton’s paper
  • hbar (float) – (default 2) The value of \(\hbar\) in the commutation relation \([\x,\p]=i\hbar\)
  • mode_names (Sequence) – (optional) this argument contains a list providing mode names for each mode in the state
reduced_dm(modes, **kwargs)[source]

Returns the reduced density matrix in the Fock basis for a particular mode.

Parameters:
  • modes (int) – specifies the mode. For the Gaussian backend, only a single mode reduced density matrix can be returned.
  • **kwargs
    • cutoff (int): (default 10) specifies where to truncate the returned density matrix. Note that the cutoff argument only applies for Gaussian representation; states represented in the Fock basis will use their own internal cutoff dimension.
Returns:

the reduced density matrix for the specified modes

Return type:

array

fock_prob(n, **kwargs)[source]

Probability of a particular Fock basis state.

Computes the probability \(|\braket{\vec{n}|\psi}|^2\) of measuring the given multi-mode Fock state based on the state \(\ket{\psi}\).

Warning

Computing the Fock probabilities of states has exponential scaling in the Gaussian representation (for example states output by a Gaussian backend as a BaseGaussianState). This shouldn’t affect small-scale problems, where only a few Fock basis state probabilities need to be calculated, but will become evident in larger scale problems.

Parameters:
  • n (Sequence[int]) – the Fock state \(\ket{\vec{n}}\) that we want to measure the probability of
  • **kwargs
    • cutoff (int): (default 10) specifies the fock basis truncation when calculating of the fock basis probabilities. Note that the cutoff argument only applies for Gaussian representation; states represented in the Fock basis will use their own internal cutoff dimension.
Returns:

measurement probability

Return type:

float

mean_photon(mode, **kwargs)[source]

Returns the mean photon number of a particular mode.

Parameters:
  • mode (int) – specifies the mode
  • **kwargs
    • cutoff (int): (default 10) Fock basis trunction for calculation of mean photon number. Note that the cutoff argument only applies for Gaussian representation; states represented in the Fock basis will use their own internal cutoff dimension.
Returns:

the mean photon number and variance

Return type:

tuple

fidelity(other_state, mode, **kwargs)[source]

Fidelity of the reduced state in the specified mode with a user supplied state. Note that this method only supports single-mode states.

Parameters:other_state – a pure state vector array represented in the Fock basis (for Fock backends) or a Sequence (mu, cov) containing the means and covariance matrix (for Gaussian backends)
Returns:The fidelity of the circuit state with other_state.
fidelity_vacuum(**kwargs)[source]

The fidelity of the state with the vacuum state.

Returns:the fidelity of the state with the vacuum
Return type:float
fidelity_coherent(alpha_list, **kwargs)[source]

The fidelity of the state with a product of coherent states.

The fidelity is defined by

\[\bra{\vec{\alpha}}\rho\ket{\vec{\alpha}}\]
Parameters:alpha_list (Sequence[complex]) – list of coherent state parameters, one for each mode
Returns:the fidelity value
Return type:float