The Quantum Exact Simulation Toolkit v4.2.0
Loading...
Searching...
No Matches

Functions for calculating single-state properties like normalisation and purity. More...

Functions

qreal calcPurity (Qureg qureg)
 
qreal calcTotalProb (Qureg qureg)
 

Detailed Description

Functions for calculating single-state properties like normalisation and purity.

Function Documentation

◆ calcPurity()

qreal calcPurity ( Qureg qureg)

Calculates the purity of qureg, which is a measure of its mixedness.

Formulae

Let \(N\) be the number of qubits in qureg.

  • When qureg is a density matrix \( \dmrho \) (as expected), this function returns

    \[ \tr{ \dmrho^2 } = \sum\limits_{i,j} \left| \dmrho_{ij} \right|^2 \]

    where \( \dmrho_{ij} \) is the \((i,j)\)-th element of \( \dmrho \).

    A purity of 1 indicates that the matrix is pure and can be expressed as

    \[ \dmrho \equiv \ketbra{\phi}{\phi} \]

    where \( \ket{\phi} \) is some pure state expressible as a statevector.

    In contrast, a purity less than 1 indicates the matrix is mixed and can be understood as a convex combination of multiple (at least two) pure states. That is,

    \[ \dmrho \equiv \sum\limits_n p_n \ketbra{\phi}{\phi}_n, \]

    where \(p_n \in [0,1]\) and sum to 1 whenever \(\dmrho\) is a valid and correctly normalised density matrix. Mixedness can result, for example, from Decoherence.

    The minimum purity of an \(N\)-qubit density matrix is \( 1/2^N \), which is admitted only by the maximally-mixed state \( \dmrho = \hat{\id} / 2^N \).

  • When qureg is a statevector \( \svpsi \), this function returns

    \[ \tr{ \ketbra{\psi}{\psi} \; \ketbra{\psi}{\psi} } = \left( \sum\limits_i |\psi_i|^2 \right)^2 \]

    where \(\psi_i\) is the \(i\)-th amplitude of \(\svpsi\). This is always 1 for any valid statevector, and is otherwise equivalent to the output of calcTotalProb(), squared.
Constraints
  • The output of this function is only a reliable measure of purity when qureg is correctly normalised. For example, an invalid density matrix can return a purity of 1, such as the \(N\)-qubit maximally-mixed state scaled by factor \( 2^N \). Note that the function calcTotalProb() alone cannot be used to validate validity since it only consults diagonal elements, whereas the purity is informed by all elements.
Equivalences
  • When qureg is a valid density matrix (specifically, Hermitian), this function is faster than, but mathematically equivalent to, calling calcInnerProduct() and passing qureg twice.
    qcomp out = calcInnerProduct(qureg, qureg);
    qreal pur = real(out); // im=0
    qcomp calcInnerProduct(Qureg qureg, Qureg other)
  • When qureg is a statevector, this function returns the output of calcTotalProb(), squared.
Example
// = 1
qreal purity1 = calcPurity(qureg);
reportScalar("purity1", purity1);
mixTwoQubitDepolarising(qureg, 0, 1, 0.5);
// < 1
qreal purity2 = calcPurity(qureg);
reportScalar("purity2", purity2);
qreal calcPurity(Qureg qureg)
void mixTwoQubitDepolarising(Qureg qureg, int target1, int target2, qreal prob)
void initRandomPureState(Qureg qureg)
Qureg createDensityQureg(int numQubits)
Definition qureg.cpp:291
void reportScalar(const char *label, qcomp num)
Definition types.cpp:51
Definition qureg.h:49
Parameters
[in]quregthe reference state, which is unchanged.
Returns
The purity of qureg.
Exceptions
error
  • if qureg is uninitialised.
Attention
This function's input validation has not yet been unit tested, so erroneous usage may produce unexpected output. Please use with caution!
See also
Author
Tyson Jones

Definition at line 293 of file calculations.cpp.

293 {
294 validate_quregFields(qureg, __func__);
295
296 // assuming Hermiticity, Tr(rho^2) = sum_ij |rho_ij|^2,
297 // and Tr(|x><x|x><x|) = (sum_i |x_i|^2)^2
298 qreal prob = localiser_statevec_calcTotalProb(qureg);
299 return (qureg.isDensityMatrix)? prob : prob * prob;
300}

Referenced by TEST_CASE(), TEST_CASE(), TEST_CASE(), and TEST_CASE().

◆ calcTotalProb()

qreal calcTotalProb ( Qureg qureg)

Calculates the probability normalisation of the given qureg. This is the probability of the qureg being in any outcome state, which is expected to equal 1.

Formulae

Let \(N\) be the number of qubits in qureg.

  • When qureg is a statevector \( \svpsi \) with \(i\)-th amplitude \(\psi_i\), this function returns

    \[ \sum\limits_{i=0}^{2^N-1} |\psi_i|^2. \]

  • When qureg is a density matrix \( \dmrho \) with \(i\)-th diagonal element \( \dmrho_{ii} \), this function returns

    \[ \sum\limits_{i=0}^{2^N-1} \re{ \rho_{ii} } \]

Constraints
  • As above, only the real components of the diagonal elements of a density matrix are consulted; these are the only amplitudes consulted by functions which calculate probabilities in the computational basis. As such, this function gives no indication of the general validity of density matrices, such as whether they are Hermitian, whether the diagonals are real, and whether the off-diagoanl elements are valid.
Equivalences
Example
initRandomMixedState(qureg, 1<<5);
// differs from 1 by numerical error
qreal totalProb = calcTotalProb(qureg);
qreal calcTotalProb(Qureg qureg)
void initRandomMixedState(Qureg qureg, qindex numPureStates)
Parameters
[in]quregthe reference state, which is unchanged.
Returns
The probability normalisation of qureg.
Exceptions
error
  • if qureg is uninitialised.
Attention
This function's input validation has not yet been unit tested, so erroneous usage may produce unexpected output. Please use with caution!
See also
Author
Tyson Jones

Definition at line 278 of file calculations.cpp.

278 {
279 validate_quregFields(qureg, __func__);
280
281 return (qureg.isDensityMatrix)?
282 localiser_densmatr_calcTotalProb(qureg):
283 localiser_statevec_calcTotalProb(qureg);
284}

Referenced by setQuregToRenormalized(), TEST_CASE(), TEST_CASE(), TEST_CASE(), and TEST_CASE().