sf.utils.samples_expectation¶

samples_expectation(samples, modes=None)[source]

Uses samples obtained by a measurement operator to return the expectation value of the operator.

In case samples were obtained for multiple modes, it is assumed that the same measurement operator was used for each mode.

Using PNR samples to obtain number expectation

If applied to a single mode, this simply corresponds to mean photon number $$\langle n_i\rangle$$.

For multiple modes, the expectation value of the tensor product of number operator, $$\langle n_{i_0} \otimes n_{i_1} \otimes \cdots \otimes n_{i_m}\rangle$$ is returned.

Example:

>>> samples = np.array([[2, 0], [2, 2], [2, 0], [0, 0]])
>>> samples_expectation(samples)
1.0


Using homodyne samples to obtain expectation of the quadrature operators

Assuming that samples were obtained after measuring either the hat{x} or hat{p} operator.

If applied to a single mode, this simply corresponds to the expectation value of the given quadrature operator. For example for samples obtained by measuring in the position basis, for a single mode we have $$\langle \hat{x}_i\rangle$$,

For multiple modes, the expectation value of the tensor product of the momentum operator is obtained: $$\langle \hat{x}_{i_0} \otimes \hat{x}_{i_1} \otimes \cdots \otimes \hat{x}_{i_m}\rangle$$.

Example:

>>> samples = np.array([[1.23, 0], [12.32, 0.32], [0.3222, 6.34], [0, 3.543]])
>>> samples_expectation(samples)
1.4962870000000001

Parameters
• samples (array) – samples with a shape of (shots, modes)

• modes (Sequence) – indices of modes to compute the expectation value over

Returns

the expectation value from the samples

Return type

float