Function calcTotalProb

Source
pub unsafe extern "C" fn calcTotalProb(qureg: Qureg) -> f64
Expand description

A debugging function which calculates the probability of the qubits in \p qureg being in any state, which should always be 1 for correctly normalised states (hence returning a real number). For state-vectors \f$ \psi \f$, this is the norm of the entire state-vector (the sum of the absolute-value-squared of every amplitude): \f[ \sum\limits_i |\psi_i|^2 \f] and for density matrices \f$ \rho \f$, it is the trace: \f[ \text{Trace}(\rho) = \sum\limits_i \rho_{i,i} ; \f]

For un-normalised density matrices (those directly modified or initialised by the user), this function returns the real component of the trace.

Note this calculation utilises Kahan summation for greater accuracy, and hence is not parallelised and so will be slower than other functions.

@ingroup calc @param[in] qureg object representing a set of qubits @return the total probability of the qubits in \p qureg being in any state @author Ania Brown (state-vector) @author Tyson Jones (density matrix, doc)