# sf.ops.Fock¶

class Fock(n=0)[source]

Bases: strawberryfields.ops.Preparation

Prepare a mode in a Fock basis state.

The prepared mode is traced out and replaced with the Fock state $$\ket{n}$$. As a result the state of the other subsystems may have to be described using a density matrix.

Warning

The Fock basis is non-Gaussian, and thus can only be used in the Fock backends, not the Gaussian backend.

Parameters

n (int) – Fock state to prepare

Definition

A single mode state can be decomposed into the Fock basis as follows:

$\ket{\psi} = \sum_n c_n \ket{n}$

if there exists a unique integer $$m$$ such that $$\begin{cases}c_n=1& n=m\\c_n=0&n\neq m\end{cases}$$, then the single mode is simply a Fock state or $$n$$ photon state.

Tip

Available in Strawberry Fields as a NumPy array by strawberryfields.utils.fock_state()

Arbitrary states in the Fock basis can be applied in Strawberry Fields using the state preparation operator strawberryfields.ops.Ket

 measurement_deps Extra dependencies due to parameters that depend on measurements. ns
measurement_deps

Extra dependencies due to parameters that depend on measurements.

Returns

dependencies

Return type

set[RegRef]

ns = 1
 apply(reg, backend, **kwargs) Ask a local backend to execute the operation on the current register state right away. decompose(reg, **kwargs) Decompose the operation into elementary operations supported by the backend API. merge(other) Merge the operation with another (acting on the exact same set of subsystems).
apply(reg, backend, **kwargs)

Ask a local backend to execute the operation on the current register state right away.

Takes care of parameter evaluations and any pending formal transformations (like dagger) and then calls Operation._apply().

Parameters
• reg (Sequence[RegRef]) – subsystem(s) the operation is acting on

• backend (BaseBackend) – backend to execute the operation

Returns

the result of self._apply

Return type

Any

decompose(reg, **kwargs)

Decompose the operation into elementary operations supported by the backend API.

See strawberryfields.backends.base.

Parameters

reg (Sequence[RegRef]) – subsystems the operation is acting on

Returns

decomposition as a list of operations acting on specific subsystems

Return type

list[Command]

merge(other)

Merge the operation with another (acting on the exact same set of subsystems).

Note

For subclass overrides: merge may return a newly created object, or self, or other, but it must never modify self or other because the same Operation objects may be also used elsewhere.

Parameters

other (Operation) – operation to merge this one with

Returns

other * self. The return value None represents the identity gate (doing nothing).

Return type

Operation, None

Raises

MergeFailure – if the two operations cannot be merged