sf.backends.BaseState¶

class
BaseState
(num_modes, mode_names=None)[source]¶ Bases:
abc.ABC
Abstract base class for the representation of quantum states.
Attributes
Returns the underlying numerical (or symbolic) representation of the state.
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¶

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

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
fidelity
(other_state, mode, **kwargs)Fidelity of the reduced state in the specified mode with a user supplied state.
fidelity_coherent
(alpha_list, **kwargs)The fidelity of the state with a product of coherent states.
fidelity_vacuum
(**kwargs)The fidelity of the state with the vacuum state.
fock_prob
(n, **kwargs)Probability of a particular Fock basis state.
mean_photon
(mode, **kwargs)Returns the mean photon number of a particular 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])The \(\x_{\phi}\) operator expectation values and variance for the specified mode.
reduced_dm
(modes, **kwargs)Returns a reduced density matrix in the Fock basis.
wigner
(mode, xvec, pvec)Calculates the discretized Wigner function of the specified mode.

abstract
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
.

abstract
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

abstract
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

abstract
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

abstract
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

abstract
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)

abstract
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)

abstract
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

abstract
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

Downloads