nifty7.probing module#

class StatCalculator[source]#

Bases: object

Helper class to compute mean and variance of a set of inputs.


  • The memory usage of this object is constant, i.e. it does not increase with the number of samples added.

  • The code computes the unbiased variance (which contains a 1./(n-1) term for n samples).


Adds a sample.


value (any type that supports multiplication by a scalar and) – element-wise addition/subtraction/multiplication.

property mean#

the mean of all samples added so far.


value type

property var#

the unbiased variance of all samples added so far.


value type

approximation2endo(op, nsamples)[source]#
probe_diagonal(op, nprobes, random_type='pm1')[source]#

Probes the diagonal of an endomorphic operator.

The operator is called on a user-specified number of randomly generated input vectors v_i, producing r_i. The estimated diagonal is the mean of r_i^\dagger v_i.

  • op (EndomorphicOperator) – The operator to be probed.

  • nprobes (int) – The number of probes to be used.

  • random_type (str) – The kind of random number distribution to be used for the probing. The default value pm1 causes the probing vector to be randomly filled with values of +1 and -1.


The estimated diagonal.

Return type:


probe_with_posterior_samples(op, post_op, nprobes, dtype)[source]#


  • op (EndomorphicOperator) – FIXME

  • post_op (Operator) – FIXME

  • nprobes (int) – Number of samples which shall be drawn.

  • dtype – the data type of the samples


List of two fields: the mean and the variance.

Return type:

List of Field