Quantum states API¶
Module name: strawberryfields.backends.states
This module provides classes which represent the quantum state
returned by a simulator backend via Engine
.
Base quantum state¶
An abstract base class for the representation of quantum states. This class should not be instantiated on its own, instead all states will be represented by one of the inheriting subclasses.
This class contains all methods that should be supported by all inheriting classes.
Note
In the following, keyword arguments are denoted **kwargs
, and allow additional
options to be passed to the underlying State class  these are documented where
available. For more details on relevant keyword arguments, please
consult the backend documentation directly.
data 
Returns the underlying numerical (or symbolic) representation of the state. 
hbar 
Returns the value of \(\hbar\) used in the generation of the state. 
is_pure 
Checks whether the state is a pure state. 
num_modes 
Gets the number of modes that the state represents. 
mode_names 
Returns a dictionary mapping the mode index to mode names. 
mode_indices 
Returns a dictionary mapping the mode names to mode indices. 
reduced_dm (modes, **kwargs) 
Returns a reduced density matrix in the Fock basis. 
fock_prob (n, **kwargs) 
Probability of a particular Fock basis state. 
mean_photon (mode, **kwargs) 
Returns the mean photon number of a particular mode. 
fidelity (other_state, mode, **kwargs) 
Fidelity of the reduced state in the specified mode with a user supplied state. 
fidelity_vacuum (**kwargs) 
The fidelity of the state with the vacuum state. 
fidelity_coherent (alpha_list, **kwargs) 
The fidelity of the state with a product of coherent states. 
wigner (mode, xvec, pvec) 
Calculates the discretized Wigner function of the specified mode. 
quad_expectation (mode[, phi]) 
The \(\x_{\phi}\) operator expectation values and variance for the specified mode. 
poly_quad_expectation (A[, d, k, phi]) 
The multimode expectation values and variance of arbitrary 2nd order polynomials of quadrature operators. 
Base Gaussian state¶
Class for the representation of quantum states using the Gaussian formalism.
This class extends the class BaseState
with additional methods
unique to Gaussian states.
Note that backends using the Gaussian state representation may extend this class with
additional methods particular to the backend, for example GaussianState
in the Gaussian simulator backend.
means () 
The vector of means describing the Gaussian state. 
cov () 
The covariance matrix describing the Gaussian state. 
reduced_gaussian (modes) 
Returns the vector of means and the covariance matrix of the specified modes. 
is_coherent (mode[, tol]) 
Returns True if the Gaussian state of a particular mode is a coherent state. 
is_squeezed (mode[, tol]) 
Returns True if the Gaussian state of a particular mode is a squeezed state. 
displacement ([modes]) 
Returns the displacement parameter \(\alpha\) of the modes specified. 
squeezing ([modes]) 
Returns the squeezing parameters \((r,\phi)\) of the modes specified. 
Base Fock state¶
Class for the representation of quantum states in the Fock basis.
This class extends the class BaseState
with additional methods
unique to states in the Fockbasis representation.
Note that backends using Fockbasis representation may extend this class with
additional methods particular to the backend, for example FockStateTF
in the Tensorflow simulator backend.
cutoff_dim 
The numerical truncation of the Fock space used by the underlying state. 
ket (**kwargs) 
The numerical state vector for the quantum state. 
dm (**kwargs) 
The numerical density matrix for the quantum state. 
trace (**kwargs) 
Trace of the density operator corresponding to the state. 
all_fock_probs (**kwargs) 
Probabilities of all possible Fock basis states for the current circuit state. 
Code details¶

class
strawberryfields.backends.states.
BaseState
(num_modes, mode_names=None)[source]¶ Abstract base class for the representation of quantum states.

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

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

num_modes
¶ Gets the number of modes that the state represents.
Returns: the number of modes in the state Return type: int

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

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

reduced_dm
(modes, **kwargs)[source]¶ Returns a reduced density matrix in the Fock basis.
Parameters:  modes (int or Sequence[int]) – specifies the mode(s) to return the reduced density matrix for.
 **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 multimode 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 smallscale 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 singlemode 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

wigner
(mode, xvec, pvec)[source]¶ Calculates the discretized Wigner function of the specified mode.
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

quad_expectation
(mode, phi=0, **kwargs)[source]¶ The \(\x_{\phi}\) operator expectation values and variance for the specified mode.
The \(\x_{\phi}\) operator is defined as follows,
\[\x_{\phi} = \cos\phi~\x + \sin\phi~\p\]with corresponding expectation value
\[\bar{x_{\phi}}=\langle x_{\phi}\rangle = \text{Tr}(\x_{\phi}\rho_{mode})\]and variance
\[\Delta x_{\phi}^2 = \langle x_{\phi}^2\rangle  \braket{x_{\phi}}^2\]Parameters:  mode (int) – the requested mode
 phi (float) –
quadrature angle, clockwise from the positive \(x\) axis.
 \(\phi=0\) corresponds to the \(x\) expectation and variance (default)
 \(\phi=\pi/2\) corresponds to the \(p\) expectation and variance
Returns: expectation value and variance
Return type: tuple (float, float)

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.
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 = \braket{P(\mathbf{r})^2}  \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 real 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 vectori 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)


class
strawberryfields.backends.states.
BaseFockState
(state_data, num_modes, pure, cutoff_dim, mode_names=None)[source]¶ Class for the representation of quantum states in the Fock basis.
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

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

ket
(**kwargs)[source]¶ The numerical state vector for the quantum state. Note that if the state is mixed, this method returns None.
Returns: the numerical state vector. Returns None if the state is mixed. Return type: array/None

dm
(**kwargs)[source]¶ The numerical density matrix for the quantum state.
Returns: the numerical density matrix in the Fock basis Return type: array

trace
(**kwargs)[source]¶ Trace of the density operator corresponding to the state.
For pure states the trace corresponds to the squared norm of the ket vector.
For physical states this should always be 1, any deviations from this value are due to numerical errors and Hilbert space truncation artefacts.
Returns: trace of the state Return type: float

all_fock_probs
(**kwargs)[source]¶ Probabilities of all possible Fock basis states for the current circuit state.
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]
Returns:  array of dimension \(\underbrace{D\times D\times D\cdots\times D}_{\text{num modes}}\)
 containing the Fock state probabilities, where \(D\) is the Fock basis cutoff truncation
Return type: array

reduced_dm
(modes, **kwargs)[source]¶ Returns a reduced density matrix in the Fock basis.
Parameters:  modes (int or Sequence[int]) – specifies the mode(s) to return the reduced density matrix for.
 **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 multimode 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 smallscale 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 singlemode 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

wigner
(mode, xvec, pvec)[source]¶ Calculates the discretized Wigner function of the specified mode.
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

quad_expectation
(mode, phi=0, **kwargs)[source]¶ The \(\x_{\phi}\) operator expectation values and variance for the specified mode.
The \(\x_{\phi}\) operator is defined as follows,
\[\x_{\phi} = \cos\phi~\x + \sin\phi~\p\]with corresponding expectation value
\[\bar{x_{\phi}}=\langle x_{\phi}\rangle = \text{Tr}(\x_{\phi}\rho_{mode})\]and variance
\[\Delta x_{\phi}^2 = \langle x_{\phi}^2\rangle  \braket{x_{\phi}}^2\]Parameters:  mode (int) – the requested mode
 phi (float) –
quadrature angle, clockwise from the positive \(x\) axis.
 \(\phi=0\) corresponds to the \(x\) expectation and variance (default)
 \(\phi=\pi/2\) corresponds to the \(p\) expectation and variance
Returns: expectation value and variance
Return type: tuple (float, float)

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.
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 = \braket{P(\mathbf{r})^2}  \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 real 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 vectori 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)

class
strawberryfields.backends.states.
BaseGaussianState
(state_data, num_modes, mode_names=None)[source]¶ Class for the representation of quantum states using the Gaussian formalism.
Note that this class uses the Gaussian representation convention
\[\bar{\mathbf{r}} = (\bar{x}_1,\bar{x}_2,\dots,\bar{x}_N,\bar{p}_1,\dots,\bar{p}_N)\]Parameters:  state_data (tuple(mu, cov)) – A tuple containing the vector of means array
mu
and the covariance matrix arraycov
, in terms of the complex displacement.  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
 mode_names (Sequence) – (optional) this argument contains a list providing mode names for each mode in the state

means
()[source]¶ The vector of means describing the Gaussian state.
For a \(N\) mode state, this has the form
\[\bar{\mathbf{r}} = \left(\bar{x}_0,\dots,\bar{x}_{N1},\bar{p}_0,\dots,\bar{p}_{N1}\right)\]where \(\bar{x}_i\) and \(\bar{p}_i\) refer to the mean position and momentum quadrature of mode \(i\) respectively.
Returns: a length \(2N\) array containing the vector of means. Return type: array

cov
()[source]¶ The covariance matrix describing the Gaussian state.
The diagonal elements of the covariance matrix correspond to the variance in the position and momentum quadratures:
\[\begin{split}\mathbf{V}_{ii} = \begin{cases} (\Delta x_i)^2, & 0\leq i\leq N1\\ (\Delta p_{iN})^2, & N\leq i\leq 2(N1) \end{cases}\end{split}\]where \(\Delta x_i\) and \(\Delta p_i\) refer to the position and momentum quadrature variance of mode \(i\) respectively.
Note that if the covariance matrix is purely diagonal, then this corresponds to squeezing \(z=re^{i\phi}\) where \(\phi=0\), and \(\Delta x_i = e^{2r}\), \(\Delta p_i = e^{2r}\).
Returns: the \(2N\times 2N\) covariance matrix. Return type: array

reduced_gaussian
(modes)[source]¶ Returns the vector of means and the covariance matrix of the specified modes.
Parameters: modes (int of Sequence[int]) – indices of the requested modes Returns: where means is an array containing the vector of means, and cov is a square array containing the covariance matrix. Return type: tuple (means, cov)

is_coherent
(mode, tol=1e10)[source]¶ Returns True if the Gaussian state of a particular mode is a coherent state.
Parameters:  mode (int) – the specified mode
 tol (float) – the numerical precision in determining if squeezing is not present
Returns: True if and only if the state is a coherent state.
Return type: bool

displacement
(modes=None)[source]¶ Returns the displacement parameter \(\alpha\) of the modes specified.
Parameters: modes (int or Sequence[int]) – modes specified Returns: sequence of complex displacements \(\alpha\) corresponding to the list of specified modes Return type: Sequence[complex]

is_squeezed
(mode, tol=1e06)[source]¶ Returns True if the Gaussian state of a particular mode is a squeezed state.
Parameters:  mode (int) – the specified mode
 tol (float) – the numerical precision in determining if squeezing is present
Returns: True if and only if the state is a squeezed state.
Return type: bool

squeezing
(modes=None)[source]¶ Returns the squeezing parameters \((r,\phi)\) of the modes specified.
Parameters: modes (int or Sequence[int]) – modes specified Returns: sequence of tuples containing the squeezing parameters \((r,\phi)\) of the specified modes. Return type: List[(float, float)]

wigner
(mode, xvec, pvec)[source]¶ Calculates the discretized Wigner function of the specified mode.
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

quad_expectation
(mode, phi=0, **kwargs)[source]¶ The \(\x_{\phi}\) operator expectation values and variance for the specified mode.
The \(\x_{\phi}\) operator is defined as follows,
\[\x_{\phi} = \cos\phi~\x + \sin\phi~\p\]with corresponding expectation value
\[\bar{x_{\phi}}=\langle x_{\phi}\rangle = \text{Tr}(\x_{\phi}\rho_{mode})\]and variance
\[\Delta x_{\phi}^2 = \langle x_{\phi}^2\rangle  \braket{x_{\phi}}^2\]Parameters:  mode (int) – the requested mode
 phi (float) –
quadrature angle, clockwise from the positive \(x\) axis.
 \(\phi=0\) corresponds to the \(x\) expectation and variance (default)
 \(\phi=\pi/2\) corresponds to the \(p\) expectation and variance
Returns: expectation value and variance
Return type: tuple (float, float)

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.
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 = \braket{P(\mathbf{r})^2}  \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 real 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 vectori 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)

reduced_dm
(modes, **kwargs)[source]¶ Returns a reduced density matrix in the Fock basis.
Parameters:  modes (int or Sequence[int]) – specifies the mode(s) to return the reduced density matrix for.
 **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 multimode 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 smallscale 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 singlemode 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
 state_data (tuple(mu, cov)) – A tuple containing the vector of means array