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 maintain 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\)

GaussianBackend methods

supports(name) Check whether the backend supports the given operating mode.
begin_circuit(num_subsystems, **kwargs) Instantiate a quantum circuit.
add_mode([n]) Add modes to the circuit.
del_mode(modes) Delete modes from the circuit.
get_modes() Return a list of the active modes for the circuit.
reset([pure]) Reset the circuit so that all the modes are in the vacuum state.
state([modes]) Returns the state of the quantum simulation.
is_vacuum([tol]) Test whether the current circuit state is vacuum (up to given tolerance).
prepare_vacuum_state(mode) Prepare the vacuum state in the specified mode.
prepare_coherent_state(alpha, mode) Prepare a coherent state in the specified mode.
prepare_squeezed_state(r, phi, mode) Prepare a squeezed vacuum state in the specified mode.
prepare_displaced_squeezed_state(alpha, r, …) Prepare a displaced squeezed state in the specified mode.
prepare_thermal_state(nbar, mode) Prepare a thermal state in the specified mode.
rotation(phi, mode) Apply the phase-space rotation operation to the specified mode.
displacement(alpha, mode) Apply the displacement operation to the specified mode.
squeeze(z, mode) Apply the squeezing operation to the specified mode.
beamsplitter(t, r, mode1, mode2) Apply the beamsplitter operation to the specified modes.
loss(T, mode) Perform a loss channel operation on the specified mode.
thermal_loss(T, nbar, mode) Perform a thermal loss channel operation on the specified mode.
measure_homodyne(phi, mode[, shots, select]) Measure a phase space quadrature of the given mode.
measure_heterodyne(mode[, shots, select]) Perform a heterodyne measurement on the given mode.

Code details

class strawberryfields.backends.gaussianbackend.GaussianBackend[source]

Gaussian backend implementation

begin_circuit(num_subsystems, **kwargs)[source]

Instantiate a quantum circuit.

Instantiates a representation of a quantum optical state with num_subsystems modes. The state is initialized to vacuum.

The modes in the circuit are indexed sequentially using integers, starting from zero. Once an index is assigned to a mode, it can never be re-assigned to another mode. If the mode is deleted its index becomes invalid. An operation acting on an invalid or unassigned mode index raises an IndexError exception.

Parameters:

num_subsystems (int) – number of modes in the circuit

Keyword Arguments:
 
  • cutoff_dim (int) – Hilbert space truncation dimension (for Fock basis backends only)
  • batch_size (int) – (optional) batch-axis dimension, enables batched operation if > 1 (for the TF backend only)
add_mode(n=1)[source]

Add modes to the circuit.

The new modes are initialized to the vacuum state. They are assigned mode indices sequentially, starting from the first unassigned index.

Parameters:n (int) – number of modes to add
Returns:indices of the newly added modes
Return type:list[int]
del_mode(modes)[source]

Delete modes from the circuit.

The deleted modes are traced out. As a result the state may have to be described using a density matrix.

The indices of the deleted modes become invalid for the lifetime of the circuit object. They will never be reassigned to other modes. Deleting a mode that has already been deleted raises an IndexError exception.

Parameters:modes (Sequence[int]) – mode numbers to delete
get_modes()[source]

Return a list of the active modes for the circuit.

A mode is active if it has been created and has not been deleted.

Returns:sorted list of active (assigned, not invalid) mode indices
Return type:list[int]
reset(pure=True, **kwargs)[source]

Reset the circuit so that all the modes are in the vacuum state.

After the reset the circuit is in the same state as it was after the last begin_circuit() call. It will have the original number of modes, all initialized in the vacuum state. Some circuit parameters may be changed during the reset, see the keyword args below.

Parameters:pure (bool) – if True, initialize the circuit in a pure state representation (will use a mixed state representation if pure is False)
Keyword Arguments:
 cutoff_dim (int) – new Hilbert space truncation dimension (for Fock basis backends only)
prepare_thermal_state(nbar, mode)[source]

Prepare a thermal state in the specified mode.

The requested mode is traced out and replaced with the thermal state \(\rho(nbar)\). As a result the state may have to be described using a density matrix.

Parameters:
  • nbar (float) – thermal population (mean photon number) of the mode
  • mode (int) – which mode to prepare the thermal state in
prepare_vacuum_state(mode)[source]

Prepare the vacuum state in the specified mode.

The requested mode is traced out and replaced with the vacuum state. As a result the state may have to be described using a density matrix.

Parameters:mode (int) – which mode to prepare the vacuum state in
prepare_coherent_state(alpha, mode)[source]

Prepare a coherent state in the specified mode.

The requested mode is traced out and replaced with the coherent state \(\ket{\alpha}\). As a result the state may have to be described using a density matrix.

Parameters:
  • alpha (complex) – coherent state displacement parameter
  • mode (int) – which mode to prepare the coherent state in
prepare_squeezed_state(r, phi, mode)[source]

Prepare a squeezed vacuum state in the specified mode.

The requested mode is traced out and replaced with the squeezed state \(\ket{z}\), where \(z=re^{i\phi}\). As a result the state may have to be described using a density matrix.

Parameters:
  • r (float) – squeezing amplitude
  • phi (float) – squeezing angle
  • mode (int) – which mode to prepare the squeezed state in
prepare_displaced_squeezed_state(alpha, r, phi, mode)[source]

Prepare a displaced squeezed state in the specified mode.

The requested mode is traced out and replaced with the displaced squeezed state state \(\ket{\alpha, z}\), where \(z=re^{i\phi}\). As a result the state may have to be described using a density matrix.

Parameters:
  • alpha (complex) – displacement parameter
  • r (float) – squeezing amplitude
  • phi (float) – squeezing angle
  • mode (int) – which mode to prepare the squeezed state in
rotation(phi, mode)[source]

Apply the phase-space rotation operation to the specified mode.

Parameters:
  • phi (float) – rotation angle
  • mode (int) – which mode to apply the rotation to
displacement(alpha, mode)[source]

Apply the displacement operation to the specified mode.

Parameters:
  • alpha (complex) – displacement parameter
  • mode (int) – which mode to apply the displacement to
squeeze(z, mode)[source]

Apply the squeezing operation to the specified mode.

Parameters:
  • z (complex) – squeezing parameter
  • mode (int) – which mode to apply the squeeze to
beamsplitter(t, r, mode1, mode2)[source]

Apply the beamsplitter operation to 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) – transmitted amplitude
  • r (complex) – reflected amplitude (with phase)
  • mode1 (int) – first mode that beamsplitter acts on
  • mode2 (int) – second mode that beamsplitter acts on
measure_homodyne(phi, mode, shots=1, select=None, **kwargs)[source]

Measure a phase space quadrature of the given mode.

See BaseBackend.measure_homodyne().

Keyword Arguments:
 eps (float) – 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_\text{meas} = \texttt{eps}^2\). Perfect homodyning is obtained when eps \(\to 0\).
Returns:measured value
Return type:float
measure_heterodyne(mode, shots=1, select=None)[source]

Perform a heterodyne measurement on the given mode.

Updates the current state of the circuit such that the measured mode is reset to the vacuum state.

Parameters:
  • mode (int) – which mode to measure
  • shots (int) – number of measurement samples to obtain
  • select (None or complex) – If not None: desired value of the measurement result. Enables post-selection on specific measurement results instead of random sampling.
Returns:

measured value

Return type:

complex

prepare_gaussian_state(r, V, modes)[source]

Prepare a Gaussian state.

The specified modes are traced out and replaced with a Gaussian state provided via a vector of means and a covariance matrix.

Note

This method is \(\hbar\) independent. The input arrays are the means and covariance of the \(a+a^\dagger\) and \(-i(a-a^\dagger)\) operators. They are obtained by dividing the xp means by \(\sqrt{\hbar/2}\) and the xp covariance by \(\hbar/2\).

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

Test whether the current circuit state is vacuum (up to given tolerance).

Returns True iff \(|\bra{0} \rho \ket{0} -1| \le\) tol, i.e., the fidelity of the current circuit state with the vacuum state is within the given tolerance from 1.

Parameters:tol (float) – numerical tolerance
Returns:True iff current state is vacuum up to tolerance tol
Return type:bool
loss(T, mode)[source]

Perform a loss channel operation on the specified mode.

Parameters:
  • T (float) – loss parameter, \(0\leq T\leq 1\).
  • 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, \(0\leq T\leq 1\).
  • nbar (float) – mean photon number of the environment thermal state
  • mode (int) – index of mode where operation is carried out
measure_fock(modes, shots=1, select=None)[source]

Measure the given modes in the Fock basis.

..note::
When :code:shots == 1, updates the current system state to the conditional state of that measurement result. When :code:shots > 1, the system state is not updated.
Parameters:
  • modes (Sequence[int]) – which modes to measure
  • shots (int) – number of measurement samples to obtain
  • select (None or Sequence[int]) – If not None: desired values of the measurement results. Enables post-selection on specific measurement results instead of random sampling. len(select) == len(modes) is required.
Returns:

measurement results

Return type:

tuple[int]

state(modes=None, **kwargs)[source]

Returns the state of the quantum simulation.

See BaseBackend.state().

Returns:state description
Return type:GaussianState

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, 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
  • 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