sf.backends.tfbackend.states.FockStateTF¶

class
FockStateTF
(state_data, num_modes, pure, cutoff_dim, graph, batched=False, mode_names=None, eval=True)[source]¶ Bases:
strawberryfields.backends.states.BaseFockState
Class for the representation of quantum states in the Fock basis using the TFBackend.
 Parameters
state_data (array) – the state representation in the Fock basis
num_modes (int) – the number of modes in the state
pure (bool) – True if the state is a pure state, false if the state is mixed
cutoff_dim (int) – the Fock basis truncation size
mode_names (Sequence) – (optional) this argument contains a list providing mode names for each mode in the state.
eval (bool) – indicates the default return behaviour for the class instance (symbolic when eval=False, numerical when eval=True)
Attributes
The number of batches.
The numerical truncation of the Fock space used by the underlying state.
Returns the underlying numerical (or symbolic) representation of the state.
The computational graph.
Returns the value of \(\hbar\) used in the generation of the state.
Checks whether the state is a pure state.
Returns a dictionary mapping the mode names to mode indices.
Returns a dictionary mapping the mode index to mode names.
Gets the number of modes that the state represents.

EQ_TOLERANCE
= 1e10¶

batched
¶ The number of batches.

cutoff_dim
¶ The numerical truncation of the Fock space used by the underlying state. Note that a cutoff of D corresponds to the Fock states \(\{0\rangle,\dots,D1\rangle\}\)
 Returns
the cutoff dimension
 Return type
int

data
¶ Returns the underlying numerical (or symbolic) representation of the state. The form of this data differs for different backends.

graph
¶ The computational graph.

hbar
¶ Returns the value of \(\hbar\) used in the generation of the state.
The value of \(\hbar\) is a convention chosen in the definition of \(\x\) and \(\p\). See Operators for more details.
 Returns
\(\hbar\) value.
 Return type
float

is_pure
¶ Checks whether the state is a pure state.
 Returns
True if and only if the state is pure.
 Return type
bool

mode_indices
¶ Returns a dictionary mapping the mode names to mode indices.
The mode names are determined from the initialization argument
mode_names
. If these were not supplied, the names are generated automatically based on the mode indices. Returns
dictionary of the form
{"mode name":i,...}
 Return type
dict

mode_names
¶ Returns a dictionary mapping the mode index to mode names.
The mode names are determined from the initialization argument
mode_names
. If these were not supplied, the names are generated automatically based on the mode indices. Returns
dictionary of the form
{i:"mode name",...}
 Return type
dict

num_modes
¶ Gets the number of modes that the state represents.
 Returns
the number of modes in the state
 Return type
int
Methods
all_fock_probs
(**kwargs)Compute the probabilities of all possible Fockbasis states for the state.
dm
(**kwargs)Computes the density matrix representation of the state.
fidelity
(other_state, mode, **kwargs)Compute the fidelity of the reduced state (on the specified mode) with the state.
fidelity_coherent
(alpha_list, **kwargs)Compute the fidelity of the state with the coherent states specified by alpha_list.
fidelity_vacuum
(**kwargs)Compute the fidelity of the state with the vacuum state.
fock_prob
(n, **kwargs)Compute the probabilities of a specific Fockbasis matrix element for the state.
is_vacuum
([tol])Computes a boolean which indicates whether the state is the vacuum state.
ket
(**kwargs)Computes the ket representation of the state.
mean_photon
(mode, **kwargs)Compute the mean photon number for the reduced state on the specified mode.
poly_quad_expectation
(A[, d, k, phi])The multimode expectation values and variance of arbitrary 2nd order polynomials of quadrature operators.
quad_expectation
(mode[, phi])Compute the expectation value of the quadrature operator \(\hat{x}_\phi\) for the reduced state on the specified mode.
reduced_dm
(modes, **kwargs)Computes the reduced density matrix representation of the state.
trace
(**kwargs)Computes the trace of the state.
wigner
(mode, xvec, pvec)Calculates the discretized Wigner function of the specified mode.

all_fock_probs
(**kwargs)[source]¶ Compute the probabilities of all possible Fockbasis states for the state. May be numerical or symbolic.
For example, in the case of 3 modes, this method allows the Fock state probability \(\braketD{0,2,3}{\psi}^2\) to be returned via
probs = state.all_fock_probs() probs[0,2,3]
 Parameters
**kwargs –
Optional keyword arguments.
If this contains the key
eval
, then the corresponding argument will be used to determine the return behaviour of this function. Wheneval=True
, the return value is numerical; wheneval=False
, it is symbolic.If eval is not present in kwargs, then state falls back to the an internal evaluation behaviour, which is specified at initialization.
A Tensorflow Session or feed_dict may also be passed via the keys
session
orfeed_dict
, respectively. If a Session is supplied, theneval
is overriden and the numerical evaluation takes place in the provided Session. If session and/or feed_dict are not given, then a temporary session and/or empty feed_dict will be used.
 Returns
the numerical values, or an unevaluated Tensor object, for the Fockbasis probabilities.
 Return type
array/Tensor

dm
(**kwargs)[source]¶ Computes the density matrix representation of the state. May be numerical or symbolic.
 Parameters
**kwargs –
Optional keyword arguments.
If this contains the key
eval
, then the corresponding argument will be used to determine the return behaviour of this function. Wheneval=True
, the return value is numerical; wheneval=False
, it is symbolic.If eval is not present in kwargs, then state falls back to the an internal evaluation behaviour, which is specified at initialization.
A Tensorflow Session or feed_dict may also be passed via the keys
session
orfeed_dict
, respectively. If a Session is supplied, theneval
is overriden and the numerical evaluation takes place in the provided Session. If session and/or feed_dict are not given, then a temporary session and/or empty feed_dict will be used.
 Returns
the numerical value, or an unevaluated Tensor object, for the density matrix.
 Return type
array/Tensor

fidelity
(other_state, mode, **kwargs)[source]¶ Compute the fidelity of the reduced state (on the specified mode) with the state. May be numerical or symbolic.
 Parameters
other_state (array) – state vector (ket) to compute the fidelity with respect to
mode (int) – which subsystem to use for the fidelity computation
**kwargs –
Optional keyword arguments.
If this contains the key
eval
, then the corresponding argument will be used to determine the return behaviour of this function. Wheneval=True
, the return value is numerical; wheneval=False
, it is symbolic.If eval is not present in kwargs, then state falls back to the an internal evaluation behaviour, which is specified at initialization.
A Tensorflow Session or feed_dict may also be passed via the keys
session
orfeed_dict
, respectively. If a Session is supplied, theneval
is overriden and the numerical evaluation takes place in the provided Session. If session and/or feed_dict are not given, then a temporary session and/or empty feed_dict will be used.
 Returns
the numerical value, or an unevaluated Tensor object, for the fidelity.
 Return type
float/Tensor

fidelity_coherent
(alpha_list, **kwargs)[source]¶ Compute the fidelity of the state with the coherent states specified by alpha_list. May be numerical or symbolic.
 Parameters
alpha_list (Sequence[complex]) – list of coherence parameter values, one for each mode
**kwargs –
Optional keyword arguments.
If this contains the key
eval
, then the corresponding argument will be used to determine the return behaviour of this function. Wheneval=True
, the return value is numerical; wheneval=False
, it is symbolic.If eval is not present in kwargs, then state falls back to the an internal evaluation behaviour, which is specified at initialization.
A Tensorflow Session or feed_dict may also be passed via the keys
session
orfeed_dict
, respectively. If a Session is supplied, theneval
is overriden and the numerical evaluation takes place in the provided Session. If session and/or feed_dict are not given, then a temporary session and/or empty feed_dict will be used.
 Returns
the numerical value, or an unevaluated Tensor object, for the fidelity \(\bra{\vec{\alpha}}\rho\ket{\vec{\alpha}}\).
 Return type
float/Tensor

fidelity_vacuum
(**kwargs)[source]¶ Compute the fidelity of the state with the vacuum state. May be numerical or symbolic.
 Parameters
**kwargs –
Optional keyword arguments.
If this contains the key
eval
, then the corresponding argument will be used to determine the return behaviour of this function. Wheneval=True
, the return value is numerical; wheneval=False
, it is symbolic.If eval is not present in kwargs, then state falls back to the an internal evaluation behaviour, which is specified at initialization.
A Tensorflow Session or feed_dict may also be passed via the keys
session
orfeed_dict
, respectively. If a Session is supplied, theneval
is overriden and the numerical evaluation takes place in the provided Session. If session and/or feed_dict are not given, then a temporary session and/or empty feed_dict will be used.
 Returns
the numerical value, or an unevaluated Tensor object, for the fidelity \(\bra{\vec{0}}\rho\ket{\vec{0}}\).
 Return type
float/Tensor

fock_prob
(n, **kwargs)[source]¶ Compute the probabilities of a specific Fockbasis matrix element for the state. May be numerical or symbolic.
 Parameters
n (Sequence[int]) – the Fock state \(\ket{\vec{n}}\) that we want to measure the probability of
**kwargs –
Optional keyword arguments.
If this contains the key
eval
, then the corresponding argument will be used to determine the return behaviour of this function. Wheneval=True
, the return value is numerical; wheneval=False
, it is symbolic.If eval is not present in kwargs, then state falls back to the an internal evaluation behaviour, which is specified at initialization.
A Tensorflow Session or feed_dict may also be passed via the keys
session
orfeed_dict
, respectively. If a Session is supplied, theneval
is overriden and the numerical evaluation takes place in the provided Session. If session and/or feed_dict are not given, then a temporary session and/or empty feed_dict will be used.
 Returns
the numerical values, or an unevaluated Tensor object, for the Fockstate probabilities.
 Return type
float/Tensor

is_vacuum
(tol=0.0, **kwargs)[source]¶ Computes a boolean which indicates whether the state is the vacuum state. May be numerical or symbolic.
 Parameters
tol – numerical tolerance. If the state has fidelity with vacuum within tol, then this method returns True.
**kwargs –
Optional keyword arguments.
If this contains the key
eval
, then the corresponding argument will be used to determine the return behaviour of this function. Wheneval=True
, the return value is numerical; wheneval=False
, it is symbolic.If eval is not present in kwargs, then state falls back to the an internal evaluation behaviour, which is specified at initialization.
A Tensorflow Session or feed_dict may also be passed via the keys
session
orfeed_dict
, respectively. If a Session is supplied, theneval
is overriden and the numerical evaluation takes place in the provided Session. If session and/or feed_dict are not given, then a temporary session and/or empty feed_dict will be used.
 Returns
the boolean value, or an unevaluated Tensor object, for whether the state is in vacuum.
 Return type
bool/Tensor

ket
(**kwargs)[source]¶ Computes the ket representation of the state. May be numerical or symbolic.
 Parameters
**kwargs –
Optional keyword arguments.
If this contains the key
eval
, then the corresponding argument will be used to determine the return behaviour of this function. Wheneval=True
, the return value is numerical; wheneval=False
, it is symbolic.If eval is not present in kwargs, then state falls back to the an internal evaluation behaviour, which is specified at initialization.
A Tensorflow Session or feed_dict may also be passed via the keys
session
orfeed_dict
, respectively. If a Session is supplied, theneval
is overriden and the numerical evaluation takes place in the provided Session. If session and/or feed_dict are not given, then a temporary session and/or empty feed_dict will be used.
 Returns
the numerical value, or an unevaluated Tensor object, for the ket.
 Return type
array/Tensor

mean_photon
(mode, **kwargs)[source]¶ Compute the mean photon number for the reduced state on the specified mode. May be numerical or symbolic.
 Parameters
mode (int) – which subsystem to take the mean photon number of
**kwargs –
Optional keyword arguments.
If this contains the key
eval
, then the corresponding argument will be used to determine the return behaviour of this function. Wheneval=True
, the return value is numerical; wheneval=False
, it is symbolic.If eval is not present in kwargs, then state falls back to the an internal evaluation behaviour, which is specified at initialization.
A Tensorflow Session or feed_dict may also be passed via the keys
session
orfeed_dict
, respectively. If a Session is supplied, theneval
is overriden and the numerical evaluation takes place in the provided Session. If session and/or feed_dict are not given, then a temporary session and/or empty feed_dict will be used.
 Returns
tuple containing the numerical value, or an unevaluated Tensor object, for the mean photon number and variance.
 Return type
tuple(float/Tensor)

poly_quad_expectation
(A, d=None, k=0, phi=0, **kwargs)[source]¶ The multimode expectation values and variance of arbitrary 2nd order polynomials of quadrature operators.
Warning
Calculation of multimode quadratic expectation values is currently only supported if
eval=True
andbatched=False
.An arbitrary 2nd order polynomial of quadrature operators over $N$ modes can always be written in the following form:
\[P(\mathbf{r}) = \mathbf{r}^T A\mathbf{r} + \mathbf{r}^T \mathbf{d} + k I\]where:
\(A\in\mathbb{R}^{2N\times 2N}\) is a symmetric matrix representing the quadratic coefficients,
\(\mathbf{d}\in\mathbb{R}^{2N}\) is a real vector representing the linear coefficients,
\(k\in\mathbb{R}\) represents the constant term, and
\(\mathbf{r} = (\x_1,\dots,\x_N,\p_1,\dots,\p_N)\) is the vector of quadrature operators in \(xp\)ordering.
This method returns the expectation value of this secondorder polynomial,
\[\langle P(\mathbf{r})\rangle,\]as well as the variance
\[\Delta P(\mathbf{r})^2 = \langle P(\mathbf{r})^2\rangle  \braket{P(\mathbf{r})}^2\] Parameters
A (array) – a real symmetric 2Nx2N NumPy array, representing the quadratic coefficients of the second order quadrature polynomial.
d (array) – a symmetric length2N NumPy array, representing the linear coefficients of the second order quadrature polynomial. Defaults to the zero vector.
k (float) – the constant term. Default 0.
phi (float) – quadrature angle, clockwise from the positive \(x\) axis. If provided, the vector of quadrature operators \(\mathbf{r}\) is first rotated by angle \(\phi\) in the phase space.
**kwargs –
Optional keyword arguments.
If this contains the key
eval
, then the corresponding argument will be used to determine the return behaviour of this function. Wheneval=True
, the return value is numerical; wheneval=False
, it is symbolic.If eval is not present in kwargs, then state falls back to the an internal evaluation behaviour, which is specified at initialization.
A Tensorflow Session or feed_dict may also be passed via the keys
session
orfeed_dict
, respectively. If a Session is supplied, theneval
is overriden and the numerical evaluation takes place in the provided Session. If session and/or feed_dict are not given, then a temporary session and/or empty feed_dict will be used.
 Returns
expectation value and variance
 Return type
tuple (float, float)

quad_expectation
(mode, phi=0.0, **kwargs)[source]¶ Compute the expectation value of the quadrature operator \(\hat{x}_\phi\) for the reduced state on the specified mode. May be numerical or symbolic.
 Parameters
mode (int) – which subsystem to take the expectation value of
phi (float) – rotation angle for the quadrature operator
**kwargs –
Optional keyword arguments.
If this contains the key
eval
, then the corresponding argument will be used to determine the return behaviour of this function. Wheneval=True
, the return value is numerical; wheneval=False
, it is symbolic.If eval is not present in kwargs, then state falls back to the an internal evaluation behaviour, which is specified at initialization.
A Tensorflow Session or feed_dict may also be passed via the keys
session
orfeed_dict
, respectively. If a Session is supplied, theneval
is overriden and the numerical evaluation takes place in the provided Session. If session and/or feed_dict are not given, then a temporary session and/or empty feed_dict will be used.
 Returns
the numerical value, or an unevaluated Tensor object, for the expectation value
 Return type
float/Tensor

reduced_dm
(modes, **kwargs)[source]¶ Computes the reduced density matrix representation of the state. May be numerical or symbolic.
 Parameters
modes (int or Sequence[int]) – specifies the mode(s) to return the reduced density matrix for.
**kwargs –
Optional keyword arguments.
If this contains the key
eval
, then the corresponding argument will be used to determine the return behaviour of this function. Wheneval=True
, the return value is numerical; wheneval=False
, it is symbolic.If eval is not present in kwargs, then state falls back to the an internal evaluation behaviour, which is specified at initialization.
A Tensorflow Session or feed_dict may also be passed via the keys
session
orfeed_dict
, respectively. If a Session is supplied, theneval
is overriden and the numerical evaluation takes place in the provided Session. If session and/or feed_dict are not given, then a temporary session and/or empty feed_dict will be used.
 Returns
the numerical value, or an unevaluated Tensor object, for the density matrix.
 Return type
array/Tensor

trace
(**kwargs)[source]¶ Computes the trace of the state. May be numerical or symbolic.
 Parameters
**kwargs –
Optional keyword arguments.
If this contains the key
eval
, then the corresponding argument will be used to determine the return behaviour of this function. Wheneval=True
, the return value is numerical; wheneval=False
, it is symbolic.If eval is not present in kwargs, then state falls back to the an internal evaluation behaviour, which is specified at initialization.
A Tensorflow Session or feed_dict may also be passed via the keys
session
orfeed_dict
, respectively. If a Session is supplied, theneval
is overriden and the numerical evaluation takes place in the provided Session. If session and/or feed_dict are not given, then a temporary session and/or empty feed_dict will be used.
 Returns
the numerical value, or an unevaluated Tensor object, for the trace.
 Return type
float/Tensor

wigner
(mode, xvec, pvec)[source]¶ Calculates the discretized Wigner function of the specified mode.
Warning
Calculation of the Wigner function is currently only supported if
eval=True
andbatched=False
.Note
This code is a modified version of the ‘iterative’ method of the wigner function provided in QuTiP, which is released under the BSD license, with the following copyright notice:
Copyright (C) 2011 and later, P.D. Nation, J.R. Johansson, A.J.G. Pitchford, C. Granade, and A.L. Grimsmo. All rights reserved.
 Parameters
mode (int) – the mode to calculate the Wigner function for
xvec (array) – array of discretized \(x\) quadrature values
pvec (array) – array of discretized \(p\) quadrature values
 Returns
2D array of size [len(xvec), len(pvec)], containing reduced Wigner function values for specified x and p values.
 Return type
array
Downloads