States

In Strawberry Fields, the statevector simulator backends return state objects, which provide useful information and processing of the quantum state of the system. For example, consider the following program:

prog = sf.Program(3)

with prog.context as q:
    ops.Sgate(0.54) | q[0]
    ops.Sgate(0.54) | q[1]
    ops.Sgate(0.54) | q[2]
    ops.BSgate(0.43, 0.1) | (q[0], q[2])
    ops.BSgate(0.43, 0.1) | (q[1], q[2])

eng = sf.Engine("fock", backend_options={"cutoff_dim": 10})
result = eng.run(prog)
state = result.state

By executing this program on a local simulator backend, we can use the state object to determine the trace, return the density matrix, and calculate particular Fock basis state probabilities:

>>> state.trace()
0.9989783190545866
>>> rho = state.dm()
>>> state.fock_prob([0, 0, 2])
0.07933909728557098

These methods may differ depending on the backend, but there are a few that are implemented for all backends.

Common methods and attributes

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.

ket(**kwargs)

The numerical state vector for the quantum state in the Fock basis.

dm(**kwargs)

The numerical density matrix for the quantum state in the Fock basis.

reduced_dm(modes, **kwargs)

Returns a reduced density matrix in the Fock basis.

fock_prob(n, **kwargs)

Probability of a particular Fock basis state.

all_fock_probs(**kwargs)

Probabilities of all possible Fock basis states for the current circuit 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 multi-mode expectation values and variance of arbitrary 2nd order polynomials of quadrature operators.

number_expectation(modes)

Calculates the expectation value of the product of the number operators of the modes.

parity_expectation(modes)

Calculates the expectation value of a product of parity operators acting on given modes

p_quad_values(mode, xvec, pvec)

Calculates the discretized p-quadrature probability distribution of the specified mode.

x_quad_values(mode, xvec, pvec)

Calculates the discretized x-quadrature probability distribution of the specified mode.

Gaussian states

Backend that represent the quantum state using the Gaussian formalism (such as the gaussian backend) will return a GaussianState object, with the following methods and attributes.

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.

Fock states

Backend that represent the quantum state in the Fock basis (such as the fock or tf backends) will return a FockState object.

cutoff_dim

The numerical truncation of the Fock space used by the underlying state.

trace(**kwargs)

Trace of the density operator corresponding to the state.