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.

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 multi-mode expectation values and variance of arbitrary 2nd order polynomials of quadrature operators.

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.

reduced_dm(modes, **kwargs)

Returns the reduced density matrix in the Fock basis for a particular mode.

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.

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.

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.