Fock simulator backend

Module name: strawberryfields.backends.fockbackend

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

The Circuit simulator maintains an internal tensor representation of the quantum state of a multi-mode quantum optical system using a (truncated) Fock basis representation. As its various state manipulation methods are called, the quantum state is updated to reflect these changes. The simulator will try to keep the internal state in a pure (vector) representation for as long as possible. Unitary gates will not change the type of representation, while state preparations and measurements will.

A number of factors determine the shape and dimensionality of the state tensor:

  • the underlying state representation being used (either a ket vector or a density matrix)
  • the number of modes \(n\) actively being simulated
  • the cutoff dimension \(D\) for the Fock basis

The state tensor corresponds to a multimode quantum system. If the representation is a pure state, the state tensor has shape \((\underbrace{D,...,D}_{n~\text{times}})\). In a mixed state representation, the state tensor has shape \((\underbrace{D,D,...,D,D}_{2n~\text{times}})\). Indices for the same mode appear consecutively. Hence, for a mixed state, the first two indices are for the first mode, the second are for the second mode, etc.

Basic quantum simulator methods

begin_circuit(num_subsystems[, cutoff_dim, …]) Create a quantum circuit (initialized in vacuum state) with the number of modes equal to num_subsystems and a Fock-space cutoff dimension of cutoff_dim.
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 squeezed vacuum state in 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 a Fock state on the specified mode.
prepare_ket_state(state, modes) Prepare an arbitrary pure state on the specified mode.
prepare_dm_state(state, modes) Prepare an arbitrary mixed state on the specified mode.
rotation(phi, mode) Apply the phase-space rotation operation to 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.
kerr_interaction(kappa, mode) Apply the Kerr interaction \(\exp{(i\kappa \hat{n}^2)}\) to the specified mode.
cross_kerr_interaction(kappa, mode1, mode2) Apply the two mode cross-Kerr interaction \(\exp{(i\kappa \hat{n}_1\hat{n}_2)}\) to the specified modes.
cubic_phase(gamma, mode) Apply the cubic phase operation to the specified mode.
loss(T, mode) Perform a loss channel operation on the specified mode.
measure_fock(modes[, select]) Perform a Fock measurement on the specified modes.
measure_homodyne(phi, mode[, select]) Perform a homodyne measurement on the specified mode.
del_mode(modes) Trace out the specified modes from the underlying circuit state.
add_mode([n]) Add num_modes new modes to the underlying circuit state.
get_modes() Return a list of the active mode indices for the circuit.
state([modes]) Returns the state of the quantum simulation, restricted to the subsystems defined by modes.

Auxiliary methods

reset([pure]) Resets the circuit state back to an all-vacuum state.
get_cutoff_dim() Returns the Hilbert space cutoff dimension used.

Code details

class strawberryfields.backends.fockbackend.FockBackend[source]

Backend in the Fock basis

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

Create a quantum circuit (initialized in vacuum state) with the number of modes equal to num_subsystems and a Fock-space cutoff dimension of cutoff_dim.

Parameters:
  • num_subsystems (int) – number of modes the circuit should begin with
  • cutoff_dim (int) – numerical cutoff dimension in Fock space for each mode. cutoff_dim=D represents the Fock states \(|0\rangle,\dots,|D-1\rangle\). This argument is required for the Fock backend.
  • 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.
  • pure (bool) – whether to begin the circuit in a pure state representation
add_mode(n=1)[source]

Add num_modes new modes to the underlying circuit state. Indices for new modes always occur at the end of the state tensor. 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, and also convert the state representation to mixed.

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

Return a list of the active mode indices for the circuit.

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

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

Parameters:pure (bool) – whether to use a pure state representation upon reset
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. Note: this may convert the state representation to mixed.

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 squeezed vacuum state in the specified mode. Note: this may convert the state representation to mixed.

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 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
prepare_thermal_state(nbar, mode)[source]

Prepare the thermal state with mean photon number nbar on the specified mode. Note: this may convert the state representation to mixed.

Parameters:
  • nbar (float) – mean thermal population of the mode
  • mode (int) – which mode to prepare the thermal 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]

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
beamsplitter(t, r, mode1, mode2)[source]

Perform a beamsplitter operation on the specified modes.

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
kerr_interaction(kappa, mode)[source]

Apply the Kerr interaction \(\exp{(i\kappa \hat{n}^2)}\) to the specified mode.

Parameters:
  • kappa (float) – strength of the interaction
  • mode (int) – which mode to apply it to
cross_kerr_interaction(kappa, mode1, mode2)[source]

Apply the two mode cross-Kerr interaction \(\exp{(i\kappa \hat{n}_1\hat{n}_2)}\) to the specified modes.

Parameters:
  • kappa (float) – strength of the interaction
  • mode1 (int) – first mode that cross-Kerr interaction acts on
  • mode2 (int) – second mode that cross-Kerr interaction acts on
cubic_phase(gamma, mode)[source]

Apply the cubic phase operation to the specified mode.

Warning

The cubic phase gate can suffer heavily from numerical inaccuracies due to finite-dimensional cutoffs in the Fock basis. The gate implementation in Strawberry Fields is unitary, but it does not implement an exact cubic phase gate. The Kerr gate provides an alternative non-Gaussian gate.

Parameters:
  • gamma (float) – cubic phase shift
  • mode (int) – which mode to apply it to
measure_homodyne(phi, mode, select=None, **kwargs)[source]

Perform a homodyne measurement on the specified mode.

Parameters:
  • phi (float) – angle (relative to x-axis) for the measurement
  • mode (int) – index of mode where operation is carried out
  • select (float) – (Optional) desired values of measurement results
  • **kwargs – Can be used to (optionally) pass user-specified numerical parameters max and num_bins. These are used numerically to build the probability distribution function (pdf) for the homdyne measurement Specifically, the pdf is discretized onto the 1D grid [-max,max], with num_bins equally spaced bins
Returns:

measurement outcome

Return type:

float

loss(T, mode)[source]

Perform a loss channel operation on the specified mode.

Parameters:
  • T – loss parameter
  • mode (int) – index of mode where operation is carried out
is_vacuum(tol=0.0, **kwargs)[source]

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

Parameters:tol (float) – numerical tolerance for how close state must be to true vacuum state
Returns:True if vacuum state up to tolerance tol
Return type:bool
get_cutoff_dim()[source]

Returns the Hilbert space cutoff dimension used.

Returns:cutoff dimension
Return type:int
state(modes=None, **kwargs)[source]

Returns the state of the quantum simulation, restricted to the subsystems defined by modes.

Parameters:modes (int, Sequence[int], None) – specifies the mode or modes to restrict the return state to. If none returns the state containing all modes.
Returns:an instance of the Strawberry Fields FockState class.
Return type:BaseFockState
prepare_fock_state(n, mode)[source]

Prepare a Fock state on the specified mode. Note: this may convert the state representation to mixed.

Parameters:
  • n (int) – number state to prepare
  • mode (int) – index of mode where state is prepared
prepare_ket_state(state, modes)[source]

Prepare an arbitrary pure state on the specified mode. Note: this may convert the state representation to mixed.

Parameters:
  • state (array) – vector representation of ket state to prepare
  • mode (int) – index of mode where state is prepared
prepare_dm_state(state, modes)[source]

Prepare an arbitrary mixed state on the specified mode. Note: this will convert the state representation to mixed.

Parameters:
  • state (array) – density matrix representation of state to prepare
  • mode (int) – index of mode where state is prepared
measure_fock(modes, select=None, **kwargs)[source]

Perform a Fock measurement on the specified modes.

Parameters:
  • modes (list[int]) – indices of mode where operation is carried out
  • select (list[int]) – (Optional) desired values of measurement results. The length of this list must match the length of the modes list.
Returns:

measurement outcomes

Return type:

list[int]