MCPcopy Create free account
hub / github.com/QuEST-Kit/QuEST / calcExpecFullStateDiagMatrPower

Function calcExpecFullStateDiagMatrPower

quest/src/api/calculations.cpp:185–215  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

183
184
185qreal calcExpecFullStateDiagMatrPower(Qureg qureg, FullStateDiagMatr matrix, qreal exponent) {
186 validate_quregFields(qureg, __func__);
187 validate_matrixFields(matrix, __func__);
188 validate_matrixAndQuregAreCompatible(matrix, qureg, true, __func__);
189 validate_matrixExpIsHermitian(matrix, exponent, __func__);
190
191 // the backend can use either the pow(qcomp,qcomp) or pow(qreal,qreal) overload;
192 // the former is significantly less accurate when the base is real & negative and
193 // the exponent is real, because complex pow(a,b) = exp(i b Arg(a)) = exp(i b 2 pi),
194 // and the numerical error in pi is compounded by the exponent and the exp(). Because
195 // this function assumes approx/intended Hermiticity, it will always use the real-pow
196 // overload, discarding the imaginary components of 'matrix' during computation - this
197 // is a behaviour unique to this function (other functions collect the erroneous
198 // imaginary components before a final validation and discarding).
199 const bool useRealPow = true;
200
201 qcomp value = (qureg.isDensityMatrix)?
202 localiser_densmatr_calcExpecFullStateDiagMatr(qureg, matrix, exponent, useRealPow):
203 localiser_statevec_calcExpecFullStateDiagMatr(qureg, matrix, exponent, useRealPow);
204
205 // is it impossible for the statevector routine to produce non-zero
206 // imaginary components because of our use of real-pow, the result of
207 // which is multiplied by abs(amp). Alas, density matrices multiply the
208 // result with a complex scalar and can accrue erroneous imaginary
209 // components when the density matrix is non-Hermitian, or due to rounding
210 // errors. As such, we only post-validate density matrix values.
211 if (qureg.isDensityMatrix)
212 validate_densMatrExpecDiagMatrValueIsReal(value, exponent, __func__);
213
214 return std::real(value);
215}
216
217
218

Callers 1

SECTIONFunction · 0.85

Tested by

no test coverage detected