sf.backends.tfbackend.states.FockStateTF¶
-
class
FockStateTF
(state_data, num_modes, pure, cutoff_dim, batched=False, mode_names=None, dtype=tf.complex64)[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
batched (bool) – (optional) default False means no batching
mode_names (Sequence) – (optional) this argument contains a list providing mode names for each mode in the state
dtype (tf.DType) – (optional) complex Tensorflow Tensor type representation, either
tf.complex64
(default) ortf.complex128
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 circuit dtype
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
= 1e-10¶
-
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,|D-1\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.
-
dtype
¶ The circuit dtype
-
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 Fock-basis states for the state.
diagonal_expectation
(modes, values)Calculates the expectation value of an operator that is diagonal in the number basis
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 Fock-basis 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.
number_expectation
(modes)Calculates the expectation value of a product of number operators acting on given modes
p_quad_values
(mode, xvec, pvec)Calculates the discretized p-quadrature probability distribution of the specified mode.
parity_expectation
(modes)Calculates the expectation value of a product of parity operators acting on given modes
poly_quad_expectation
(A[, d, k, phi])The multi-mode 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.
x_quad_values
(mode, xvec, pvec)Calculates the discretized x-quadrature probability distribution of the specified mode.
-
all_fock_probs
(**kwargs)[source]¶ Compute the probabilities of all possible Fock-basis 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]
Args:
- Returns
the numerical values, or an unevaluated Tensor object, for the Fock-basis probabilities.
- Return type
array/Tensor
-
diagonal_expectation
(modes, values)¶ Calculates the expectation value of an operator that is diagonal in the number basis
-
dm
(**kwargs)[source]¶ Computes the density matrix representation of the state. May be numerical or symbolic.
Args:
- 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
- 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
- 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.
Args:
- 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 Fock-basis 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
- Returns
the numerical values, or an unevaluated Tensor object, for the Fock-state 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.
- 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.
Args:
- 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
- Returns
tuple containing the numerical value, or an unevaluated Tensor object, for the mean photon number and variance.
- Return type
tuple(float/Tensor)
-
number_expectation
(modes)¶ Calculates the expectation value of a product of number operators acting on given modes
-
p_quad_values
(mode, xvec, pvec)¶ Calculates the discretized p-quadrature probability distribution of the specified mode.
- Parameters
mode (int) – the mode to calculate the p-quadrature probability values of
xvec (array) – array of discretized \(x\) quadrature values
pvec (array) – array of discretized \(p\) quadrature values
- Returns
1D array of size len(pvec), containing reduced p-quadrature probability values for a specified range of x and p.
- Return type
array
-
parity_expectation
(modes)¶ Calculates the expectation value of a product of parity operators acting on given modes
-
poly_quad_expectation
(A, d=None, k=0, phi=0, **kwargs)[source]¶ The multi-mode expectation values and variance of arbitrary 2nd order polynomials of quadrature operators.
Warning
Calculation of multi-mode 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 second-order 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 length-2N 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.
- 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
- 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.
- 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.
- 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
-
x_quad_values
(mode, xvec, pvec)¶ Calculates the discretized x-quadrature probability distribution of the specified mode.
- Parameters
mode (int) – the mode to calculate the x-quadrature probability values of
xvec (array) – array of discretized \(x\) quadrature values
pvec (array) – array of discretized \(p\) quadrature values
- Returns
1D array of size len(xvec), containing reduced x-quadrature probability values for a specified range of x and p.
- Return type
array