![]() |
The Quantum Exact Simulation Toolkit v4.2.0
|
Functions for calculating expected values of Hermitian observables. More...
Functions | |
qreal | calcExpecFullStateDiagMatr (Qureg qureg, FullStateDiagMatr matr) |
qreal | calcExpecFullStateDiagMatrPower (Qureg qureg, FullStateDiagMatr matrix, qreal exponent) |
qcomp | calcExpecNonHermitianFullStateDiagMatr (Qureg qureg, FullStateDiagMatr matr) |
qcomp | calcExpecNonHermitianFullStateDiagMatrPower (Qureg qureg, FullStateDiagMatr matrix, qcomp exponent) |
qcomp | calcExpecNonHermitianPauliStrSum (Qureg qureg, PauliStrSum sum) |
qreal | calcExpecPauliStr (Qureg qureg, PauliStr str) |
qreal | calcExpecPauliStrSum (Qureg qureg, PauliStrSum sum) |
Functions for calculating expected values of Hermitian observables.
qreal calcExpecFullStateDiagMatr | ( | Qureg | qureg, |
FullStateDiagMatr | matr ) |
Calculates the expectation value of the given Hermitian observable matr
- a diagonal, Hermitian matrix spanning the full Hilbert space - under the given state qureg
, without modifying it.
Let \( \hat{D} = \) matr
.
qureg
is a statevector \(\svpsi\), this function returns \[ \brapsi \hat{D} \svpsi \in \mathbb{R}. \]
qureg
is a density matrix \(\dmrho\), this function returns the real component of \[ \tr{ \hat{D} \dmrho } \]
which is the exact expectation value when \(\dmrho\) is physical (or at least, Hermitian).matr
requires that every element within is real. Validation will check matr
is approximately Hermitian, i.e. that \[ |\im{c}| \le \valeps \]
for all \(c \in \)matr.cpuElems
. Adjust \(\valeps\) using setValidationEpsilon().qureg
is correctly normalised, and matr
is Hermitian.matr
Hermiticity validation is relaxed and/or qureg
is an unnormalised density matrix. The full complex value can be obtained using calcExpecNonHermitianFullStateDiagMatr().[in] | qureg | the reference state. |
[in] | matr | the observable operator. |
error |
|
Definition at line 161 of file calculations.cpp.
Referenced by TEST_CASE().
qreal calcExpecFullStateDiagMatrPower | ( | Qureg | qureg, |
FullStateDiagMatr | matrix, | ||
qreal | exponent ) |
Calculates the expectation value of the given Hermitian observable matrix
- a diagonal, Hermitian matrix spanning the full Hilbert space - when raised to the given exponent
, under the given state qureg
, which is not modified.
Let \( \hat{D} = \) matrix
and \(x = \) exponent
.
qureg
is a statevector \(\svpsi\), this function returns \[ \brapsi \hat{D}^x \svpsi \in \mathbb{R}. \]
qureg
is a density matrix \(\dmrho\), this function returns the real component of \[ \tr{ \hat{D}^x \dmrho } \]
which is the exact expectation value when \(\dmrho\) is physical (or at least, Hermitian).matrix
itself requires that every element within is real. Validation will check matrix
is approximately Hermitian, i.e. that \[ |\im{c}| \le \valeps \]
for all \(c \in \)matr.cpuElems
. Adjust \(\valeps\) using setValidationEpsilon().matrix
, since a non-complex exponentiation function is used. That is, while validation permits the imaginary components to be small, they will be internally treated as precisely zero. This is true even when Hermiticity validation is disabled using setValidationOff(). To consult the imaginary components of matrix
, use calcExpecNonHermitianFullStateDiagMatrPower().matrix
when raised to exponent
further requires that, when exponent
is a non-integer, matrix
does not contain any negative elements which would otherwise produce complex elements in \(\hat{D}^x\). This validation is always strict (i.e. independent of \(\valeps\)), and demands that \[ \min(\hat{D}) \ge 0 \text{ when } x \notin \mathbb{R}. \]
exponent
is negative, matrix
does not contain any zero elements which would otherwise create divergences in \(\hat{D}^x\). Validation ergo checks that when exponent
is (strictly) negative, matrix
contains no elements within distance \(\valeps\) to zero (regardless of the magnitude of exponent
). Adjust \(\valeps\) using setValidationEpsilon().exponent
is always real, but can be relaxed to a general complex scalar via calcExpecNonHermitianFullStateDiagMatrPower().qureg
is an unnormalised density matrix. The full complex value can be obtained using calcExpecNonHermitianFullStateDiagMatrPower().[in] | qureg | the reference state. |
[in] | matrix | the observable operator. |
[in] | exponent | the exponent to which to raise matrix |
matrix
raised to exponent
. error |
|
Definition at line 185 of file calculations.cpp.
Referenced by TEST_CASE().
qcomp calcExpecNonHermitianFullStateDiagMatr | ( | Qureg | qureg, |
FullStateDiagMatr | matr ) |
Calculates the expectation value of the given permittedly non-Hermitian operator matr
, under the given state qureg
, without modifying it.
This function is mathematically equivalent to calcExpecFullStateDiagMatr(), except that here a complex scalar is returned. This permits obtaining the full scalar when sum
contains non-real elements, and/or when qureg
is unnormalised.
[in] | qureg | the permittedly unnormalised reference state. |
[in] | matr | the permittedly non-Hermitian operator. |
error |
|
Definition at line 85 of file calculations.cpp.
Referenced by TEST_CASE().
qcomp calcExpecNonHermitianFullStateDiagMatrPower | ( | Qureg | qureg, |
FullStateDiagMatr | matrix, | ||
qcomp | exponent ) |
Calculates the expectation value of the given permittedly non-Hermitian operator matrix
, raised to the arbitrary complex exponent
, under the given state qureg
, which is not modified.
This function is mathematically equivalent to calcExpecFullStateDiagMatrPower(), except that here a complex scalar is returned, in addition to exponent
being permittedly complex. This permits obtaining the full scalar when qureg
is unnormalised or matrix
(after being raised to exponent
) is non-Hermitian.
[in] | qureg | the permittedly unnormalised reference state. |
[in] | matrix | the permittedly non-Hermitian operator. |
[in] | exponent | the permittedly complex exponent. |
error |
|
Definition at line 98 of file calculations.cpp.
Referenced by calcExpecNonHermitianFullStateDiagMatr(), and TEST_CASE().
qcomp calcExpecNonHermitianPauliStrSum | ( | Qureg | qureg, |
PauliStrSum | sum ) |
Calculates the expectation value of the given permittedly non-Hermitian operator sum
qureg
, which is not modified.This function is mathematically equivalent to calcExpecPauliStrSum(), except that here a complex scalar is returned. This permits obtaining the full scalar when sum
contains non-real weights, and/or when qureg
is unnormalised.
[in] | qureg | the permittedly unnormalised reference state. |
[in] | sum | the permittedly non-Hermitian operator. |
error |
|
Definition at line 68 of file calculations.cpp.
Referenced by TEST_CASE().
Calculates the expectation value of the given Pauli string observable str
under the given state qureg
without modifying it.
Let \( \pstr = \) str
, which notates a tensor product of single-qubit Pauli operators.
qureg
is a statevector \(\svpsi\), this function returns \[ \brapsi \pstr \svpsi \in \mathbb{R}. \]
qureg
is a density matrix \(\dmrho\), this function returns the real component of \[ \tr{ \pstr \dmrho } \]
which is exact when \(\dmrho\) is physical (specifically Hermitian).qureg
is correctly normalised. This behaviour can be adjusted using setValidationEpsilon().str
is general, this function is equivalent to calling calcExpecPauliStrSum() with a PauliStrSum composed of only a single PauliStr term and a unity coefficient.str
\( = \id^\otimes \), the output is equivalent to that of calcTotalProb().[in] | qureg | the reference state. |
[in] | str | the observable operator. |
error |
|
Definition at line 133 of file calculations.cpp.
Referenced by TEST_CASE().
qreal calcExpecPauliStrSum | ( | Qureg | qureg, |
PauliStrSum | sum ) |
Calculates the expectation value of the given Hermitian observable sum
- a weighted sum of Pauli strings - under the given state qureg
, without modifying it.
Let \( \hat{H} = \) sum
.
qureg
is a statevector \(\svpsi\), this function returns \[ \brapsi \hat{H} \svpsi \in \mathbb{R}. \]
qureg
is a density matrix \(\dmrho\), this function returns the real component of \[ \tr{ \hat{H} \dmrho } \]
which is the exact expectation value when \(\dmrho\) is physical (or at least, Hermitian).sum
requires that every coefficient within is real. Validation will check sum
is approximately Hermitian, i.e. that \[ |\im{c}| \le \valeps \]
for all \(c \in \)sum.coeffs
. Adjust \(\valeps\) using setValidationEpsilon(). The sub-epsilon imaginary components of the coefficients are included in calculation.qureg
is correctly normalised, and sum
is Hermitian.qureg
is an unnormalised density matrix. The full complex value can be obtained using calcExpecNonHermitianPauliStrSum().PauliStr
within sum
, weighting each by its corresponding coefficient, and summing the outputs.sum
contains only \(\pauliz\) and \(\id\) operators, its corresponding operator matrix is diagonal, and could be instead effected with calcExpecFullStateDiagMatr(). This may be faster when sum
contains very-many terms and operates upon all qubits of the register.[in] | qureg | the reference state. |
[in] | sum | the observable operator. |
error |
|
Definition at line 146 of file calculations.cpp.
Referenced by TEST_CASE().