sf.utils.samples_variance¶

samples_variance
(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 variance of the number operator
If applied to a single mode, this simply corresponds to mean photon number \(Var[ n_i ]\).
For multiple modes, the expectation value of the tensor product of number operator, \(Var[ n_{i_0} \otimes n_{i_1} \otimes \cdots \otimes n_{i_m} ]\) is returned.
Example:
>>> samples = np.array([[2, 0], [2, 2], [2, 0], [0, 0]]) >>> samples_variance(samples) 3.0
Using homodyne samples to obtain variance of the quadrature operator
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 \(Var[ \hat{x}_i]\)
For multiple modes, the variance of the tensor product of the momentum operator is obtained: \(Var[\hat{x}_{i_0} \otimes \hat{x}_{i_1} \otimes \cdots \otimes \hat{x}_{i_m}]\).
Example:
>>> samples = np.array([[1.23, 0], [12.32, 0.32], [0.3222, 6.34], [0, 3.543]]) >>> samples_variance(samples) 2.6899595015070004
 Parameters
homodyne_samples (ndarray) – the homodyne samples with a shape of (shots, modes)
modes (Sequence) – indices of modes to get the variance for
 Returns
the variance from the samples
 Return type
float
Downloads