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

Functions for comparing multiple quantum states. More...

Functions

qreal calcDistance (Qureg qureg1, Qureg qureg2)
 
qreal calcFidelity (Qureg qureg, Qureg other)
 
qcomp calcInnerProduct (Qureg qureg1, Qureg qureg2)
 

Detailed Description

Functions for comparing multiple quantum states.

Function Documentation

◆ calcDistance()

qreal calcDistance ( Qureg qureg1,
Qureg qureg2 )
Note
Documentation for this function or struct is under construction!
Attention
This function's input validation has not yet been tested, so erroneous usage may produce unexpected output. Please use with caution!

Definition at line 326 of file calculations.cpp.

326 {
327 validate_quregFields(quregA, __func__);
328 validate_quregFields(quregB, __func__);
329 validate_quregsCanBeProducted(quregA, quregB, __func__);
330
331 bool isDensA = quregA.isDensityMatrix;
332 bool isDensB = quregB.isDensityMatrix;
333
334 // Hilbert-Schmidt = sqrt( Tr((A-B)(A-B)^dagger) = sqrt(sum_ij |A_ij - B_ij|^2)
335 if (isDensA && isDensB) {
336 qreal dif = localiser_densmatr_calcHilbertSchmidtDistance(quregA, quregB);
337 return std::sqrt(dif);
338 }
339
340 // Bures = sqrt(2 - 2 |<A|B>|) (even when unnormalised)
341 if (!isDensA && !isDensB) {
342 qcomp prod = localiser_statevec_calcInnerProduct(quregA, quregB);
343 qreal mag = std::abs(prod);
344
345 validate_buresDistanceInnerProdIsNormalised(mag, __func__);
346 mag = (mag > 1)? 1 : mag; // forgive eps error to avoid complex
347 return std::sqrt(2 - 2 * mag);
348 }
349
350 // purified distance = sqrt(1 - <psi|rho|psi>)
351 qcomp fid = (quregA.isDensityMatrix)?
352 localiser_densmatr_calcFidelityWithPureState(quregA, quregB, false): // no conj
353 localiser_densmatr_calcFidelityWithPureState(quregB, quregA, false); // no conj
354
355 validate_purifiedDistanceIsNormalised(fid, __func__);
356 qreal re = std::real(fid);
357 re = (re > 1)? 1 : re; // forgive eps error to avoid complex
358 return std::sqrt(1 - re);
359}

Referenced by TEST_CASE().

◆ calcFidelity()

qreal calcFidelity ( Qureg qureg,
Qureg other )
Note
Documentation for this function or struct is under construction!
Attention
This function's input validation has not yet been tested, so erroneous usage may produce unexpected output. Please use with caution!

Definition at line 298 of file calculations.cpp.

298 {
299 validate_quregFields(quregA, __func__);
300 validate_quregFields(quregB, __func__);
301 validate_quregsCanBeProducted(quregA, quregB, __func__);
302
303 bool isDensA = quregA.isDensityMatrix;
304 bool isDensB = quregB.isDensityMatrix;
305
306 // F(rho,sigma) not yet supported
307 if (isDensA && isDensB)
308 validate_throwErrorBecauseCalcFidOfDensMatrNotYetImplemented(__func__);
309
310 // |<A|B>|^2
311 if (!isDensA && !isDensB) {
312 qcomp prod = localiser_statevec_calcInnerProduct(quregA, quregB);
313 return std::norm(prod);
314 }
315
316 // Re[<B|A|B>] or Re[<A|B|A>]
317 qcomp fid = (quregA.isDensityMatrix)?
318 localiser_densmatr_calcFidelityWithPureState(quregA, quregB, false): // no conj
319 localiser_densmatr_calcFidelityWithPureState(quregB, quregA, false); // no conj
320
321 validate_fidelityIsReal(fid, __func__);
322 return std::real(fid);
323}

Referenced by TEST_CASE(), and TEST_CASE().

◆ calcInnerProduct()

qcomp calcInnerProduct ( Qureg qureg1,
Qureg qureg2 )
Note
Documentation for this function or struct is under construction!
Attention
This function's input validation has not yet been tested, so erroneous usage may produce unexpected output. Please use with caution!

Definition at line 44 of file calculations.cpp.

44 {
45 validate_quregFields(quregA, __func__);
46 validate_quregFields(quregB, __func__);
47 validate_quregsCanBeProducted(quregA, quregB, __func__);
48
49 // <A|B> or Tr(A^dagger B) = <<A|B>>
50 if (quregA.isDensityMatrix == quregB.isDensityMatrix)
51 return localiser_statevec_calcInnerProduct(quregA, quregB);
52
53 return (quregA.isDensityMatrix)?
54 localiser_densmatr_calcFidelityWithPureState(quregA, quregB, true): // <B|A^dagger|B>
55 localiser_densmatr_calcFidelityWithPureState(quregB, quregA, false); // <A|B|A>
56}

Referenced by TEST_CASE(), and TEST_CASE().