The Quantum Exact Simulation Toolkit v4.1.0
Loading...
Searching...
No Matches
Calculations
 TEST_CASE ("calcExpecPauliStr", TEST_CATEGORY)
 
 TEST_CASE ("calcExpecPauliStrSum", TEST_CATEGORY)
 
 TEST_CASE ("calcExpecNonHermitianPauliStrSum", TEST_CATEGORY)
 
 TEST_CASE ("calcProbOfBasisState", TEST_CATEGORY)
 
 TEST_CASE ("calcProbOfQubitOutcome", TEST_CATEGORY)
 
 TEST_CASE ("calcProbOfMultiQubitOutcome", TEST_CATEGORY)
 
 TEST_CASE ("calcProbsOfAllMultiQubitOutcomes", TEST_CATEGORY)
 
 TEST_CASE ("calcTotalProb", TEST_CATEGORY)
 
 TEST_CASE ("calcPurity", TEST_CATEGORY)
 
 TEST_CASE ("calcPartialTrace", TEST_CATEGORY)
 
 TEST_CASE ("calcReducedDensityMatrix", TEST_CATEGORY)
 
 TEST_CASE ("calcInnerProduct", TEST_CATEGORY LABEL_MIXED_DEPLOY_TAG)
 
 TEST_CASE ("calcFidelity", TEST_CATEGORY LABEL_MIXED_DEPLOY_TAG)
 
 TEST_CASE ("calcDistance", TEST_CATEGORY LABEL_MIXED_DEPLOY_TAG)
 
 TEST_CASE ("calcExpecFullStateDiagMatr", TEST_CATEGORY LABEL_MIXED_DEPLOY_TAG)
 
 TEST_CASE ("calcExpecNonHermitianFullStateDiagMatr", TEST_CATEGORY LABEL_MIXED_DEPLOY_TAG)
 
 TEST_CASE ("calcExpecFullStateDiagMatrPower", TEST_CATEGORY LABEL_MIXED_DEPLOY_TAG)
 
 TEST_CASE ("calcExpecNonHermitianFullStateDiagMatrPower", TEST_CATEGORY LABEL_MIXED_DEPLOY_TAG)
 

Detailed Description

Function Documentation

◆ TEST_CASE() [1/18]

TEST_CASE ( "calcDistance" ,
TEST_CATEGORY LABEL_MIXED_DEPLOY_TAG )

Definition at line 498 of file calculations.cpp.

498 {
499
500 SECTION( LABEL_CORRECTNESS ) {
501
502 qvector refSV = getRefStatevec();
503 qmatrix refDM = getRefDensmatr();
504 auto apiFunc = calcDistance;
505
506 GENERATE( range(0, TEST_NUM_MIXED_DEPLOYMENT_REPETITIONS) );
507
508 SECTION( LABEL_STATEVEC LABEL_DELIMITER LABEL_STATEVEC ) {
509
510 // sqrt(2 - 2 |<A|B>|)
511 auto refFunc = [&](qvector a, qvector b) { return std::sqrt(2 - 2 * std::abs(getInnerProduct(a,b))); };
512
513 TEST_ON_MIXED_CACHED_QUREGS( getCachedStatevecs(), getAltCachedStatevecs(), refSV, refSV, apiFunc, refFunc);
514 }
515
516 SECTION( LABEL_STATEVEC LABEL_DELIMITER LABEL_DENSMATR ) {
517
518 // sqrt(1 - <psi|rho|psi>)
519 auto refFunc = [&](qvector a, qmatrix b) { return std::sqrt(1 - std::real(getInnerProduct(a, b * a))); };
520
521 TEST_ON_MIXED_CACHED_QUREGS( getCachedStatevecs(), getAltCachedDensmatrs(), refSV, refDM, apiFunc, refFunc );
522 }
523
524 SECTION( LABEL_DENSMATR LABEL_DELIMITER LABEL_STATEVEC ) {
525
526 // sqrt(1 - <psi|rho|psi>)
527 auto refFunc = [&](qmatrix a, qvector b) { return std::sqrt(1 - std::real(getInnerProduct(b, a * b))); };
528
529 TEST_ON_MIXED_CACHED_QUREGS( getCachedDensmatrs(), getAltCachedStatevecs(), refDM, refSV, apiFunc, refFunc );
530 }
531
532 SECTION( LABEL_DENSMATR LABEL_DELIMITER LABEL_DENSMATR ) {
533
534 // sqrt(Tr((A-B)(A-B)^dagger)
535 auto refFunc = [&](qmatrix a, qmatrix b) { return std::sqrt(std::real(getTrace((a-b)*getConjugateTranspose(a-b)))); };
536
537 TEST_ON_MIXED_CACHED_QUREGS( getCachedDensmatrs(), getAltCachedDensmatrs(), refDM, refDM, apiFunc, refFunc );
538 }
539 }
540
541 /// @todo input validation
542}
qreal calcDistance(Qureg qureg1, Qureg qureg2)
qmatrix getConjugateTranspose(qmatrix m)
Definition linalg.cpp:291
const int TEST_NUM_MIXED_DEPLOYMENT_REPETITIONS
Definition macros.hpp:63

◆ TEST_CASE() [2/18]

TEST_CASE ( "calcExpecFullStateDiagMatr" ,
TEST_CATEGORY LABEL_MIXED_DEPLOY_TAG )

Definition at line 546 of file calculations.cpp.

546 {
547
548 SECTION( LABEL_CORRECTNESS ) {
549
550 qmatrix refMatr = getRandomDiagonalHermitian(getNumCachedQubits());
551 auto apiFunc = calcExpecFullStateDiagMatr;
552
553 GENERATE( range(0, TEST_NUM_MIXED_DEPLOYMENT_REPETITIONS) );
554
555 SECTION( LABEL_STATEVEC ) {
556
557 auto refFunc = [&] (qvector state, qmatrix matr) { return getReferenceExpectationValue(state, matr); };
558
559 TEST_ON_CACHED_QUREG_AND_MATRIX( getCachedStatevecs(), getCachedFullStateDiagMatrs(), apiFunc, getRefStatevec(), refMatr, refFunc);
560 }
561
562 SECTION( LABEL_DENSMATR ) {
563
564 auto refFunc = [&] (qmatrix state, qmatrix matr) { return getReferenceExpectationValue(state, matr); };
565
566 TEST_ON_CACHED_QUREG_AND_MATRIX( getCachedDensmatrs(), getCachedFullStateDiagMatrs(), apiFunc, getRefDensmatr(), refMatr, refFunc);
567 }
568 }
569
570 /// @todo input validation
571}
qreal calcExpecFullStateDiagMatr(Qureg qureg, FullStateDiagMatr matr)

◆ TEST_CASE() [3/18]

TEST_CASE ( "calcExpecFullStateDiagMatrPower" ,
TEST_CATEGORY LABEL_MIXED_DEPLOY_TAG )

Definition at line 604 of file calculations.cpp.

604 {
605
606 SECTION( LABEL_CORRECTNESS ) {
607
608 qmatrix refMatr = getRandomDiagonalHermitian(getNumCachedQubits());
609
610 // integer and non-integer exponents have different requirements
611 bool isIntegerExp = GENERATE( true, false );
612 qreal exponent = (isIntegerExp)?
613 getRandomInt(-3, 3):
614 getRandomReal(-3, 3);
615
616 // when exponent is non-integer, the matrix cannot contain negative
617 // numbers which otherwise become complex, making the matrix non-
618 // Hermitian and triggering validation
619 if (!isIntegerExp)
620 for (size_t i=0; i<refMatr.size(); i++)
621 refMatr[i][i] = std::abs(std::real(refMatr[i][i]));
622
623 // when exponent is negative, the matrix cannot contain near-zero
624 // magnitude numbers which create divergences and trigger validation.
625 // Negative exponents are particularly unstable (they can produce
626 // very large matrix elements which ergo have less post-decimal
627 // precision and sum catastrophically), so we scale up matrix.
628 if (exponent < 0)
629 for (size_t i=0; i<refMatr.size(); i++)
630 refMatr[i][i] *= 100;
631
632 auto apiFunc = [&](Qureg qureg, FullStateDiagMatr matr) {
633 return calcExpecFullStateDiagMatrPower(qureg, matr, exponent);
634 };
635
636 CAPTURE( exponent );
637
638 GENERATE( range(0, TEST_NUM_MIXED_DEPLOYMENT_REPETITIONS) );
639
640 SECTION( LABEL_STATEVEC ) {
641
642 auto refFunc = [&] (qvector state, qmatrix matr) {
643 matr = getPowerOfDiagonalMatrix(matr, qcomp(exponent,0));
644 return getReferenceExpectationValue(state, matr);
645 };
646
647 TEST_ON_CACHED_QUREG_AND_MATRIX( getCachedStatevecs(), getCachedFullStateDiagMatrs(), apiFunc, getRefStatevec(), refMatr, refFunc);
648 }
649
650 SECTION( LABEL_DENSMATR ) {
651
652 auto refFunc = [&] (qmatrix state, qmatrix matr) {
653 matr = getPowerOfDiagonalMatrix(matr, qcomp(exponent,0));
654 return getReferenceExpectationValue(state, matr);
655 };
656
657 TEST_ON_CACHED_QUREG_AND_MATRIX( getCachedDensmatrs(), getCachedFullStateDiagMatrs(), apiFunc, getRefDensmatr(), refMatr, refFunc);
658 }
659 }
660
661 /// @todo input validation
662}
qreal calcExpecFullStateDiagMatrPower(Qureg qureg, FullStateDiagMatr matr, qreal exponent)
qreal getRandomReal(qreal min, qreal maxExcl)
Definition random.cpp:63
int getRandomInt(int min, int maxExcl)
Definition random.cpp:90
Definition qureg.h:49

◆ TEST_CASE() [4/18]

TEST_CASE ( "calcExpecNonHermitianFullStateDiagMatr" ,
TEST_CATEGORY LABEL_MIXED_DEPLOY_TAG )

Definition at line 575 of file calculations.cpp.

575 {
576
577 SECTION( LABEL_CORRECTNESS ) {
578
579 qmatrix refMatr = getRandomDiagonalMatrix(getPow2(getNumCachedQubits()));
581
582 GENERATE( range(0, TEST_NUM_MIXED_DEPLOYMENT_REPETITIONS) );
583
584 SECTION( LABEL_STATEVEC ) {
585
586 auto refFunc = [&] (qvector state, qmatrix matr) { return getReferenceExpectationValue(state, matr); };
587
588 TEST_ON_CACHED_QUREG_AND_MATRIX( getCachedStatevecs(), getCachedFullStateDiagMatrs(), apiFunc, getRefStatevec(), refMatr, refFunc);
589 }
590
591 SECTION( LABEL_DENSMATR ) {
592
593 auto refFunc = [&] (qmatrix state, qmatrix matr) { return getReferenceExpectationValue(state, matr); };
594
595 TEST_ON_CACHED_QUREG_AND_MATRIX( getCachedDensmatrs(), getCachedFullStateDiagMatrs(), apiFunc, getRefDensmatr(), refMatr, refFunc);
596 }
597 }
598
599 /// @todo input validation
600}
qcomp calcExpecNonHermitianFullStateDiagMatr(Qureg qureg, FullStateDiagMatr matr)

◆ TEST_CASE() [5/18]

TEST_CASE ( "calcExpecNonHermitianFullStateDiagMatrPower" ,
TEST_CATEGORY LABEL_MIXED_DEPLOY_TAG )

Definition at line 666 of file calculations.cpp.

666 {
667
668 SECTION( LABEL_CORRECTNESS ) {
669
670 qmatrix refMatr = getRandomDiagonalMatrix(getPow2(getNumCachedQubits()));
671 qcomp exponent = getRandomComplex();
672
673 auto apiFunc = [&](Qureg qureg, FullStateDiagMatr matr) {
674 return calcExpecNonHermitianFullStateDiagMatrPower(qureg, matr, exponent);
675 };
676
677 CAPTURE( exponent );
678
679 GENERATE( range(0, TEST_NUM_MIXED_DEPLOYMENT_REPETITIONS) );
680
681 SECTION( LABEL_STATEVEC ) {
682
683 auto refFunc = [&] (qvector state, qmatrix matr) {
684 matr = getPowerOfDiagonalMatrix(matr, exponent);
685 return getReferenceExpectationValue(state, matr);
686 };
687
688 TEST_ON_CACHED_QUREG_AND_MATRIX( getCachedStatevecs(), getCachedFullStateDiagMatrs(), apiFunc, getRefStatevec(), refMatr, refFunc);
689 }
690
691 SECTION( LABEL_DENSMATR ) {
692
693 auto refFunc = [&] (qmatrix state, qmatrix matr) {
694 matr = getPowerOfDiagonalMatrix(matr, exponent);
695 return getReferenceExpectationValue(state, matr);
696 };
697
698 TEST_ON_CACHED_QUREG_AND_MATRIX( getCachedDensmatrs(), getCachedFullStateDiagMatrs(), apiFunc, getRefDensmatr(), refMatr, refFunc);
699 }
700 }
701
702 /// @todo input validation
703}
qcomp calcExpecNonHermitianFullStateDiagMatrPower(Qureg qureg, FullStateDiagMatr matrix, qcomp exponent)
qcomp getRandomComplex()
Definition random.cpp:107

◆ TEST_CASE() [6/18]

TEST_CASE ( "calcExpecNonHermitianPauliStrSum" ,
TEST_CATEGORY  )

Definition at line 204 of file calculations.cpp.

204 {
205
206 SECTION( LABEL_CORRECTNESS ) {
207
208 GENERATE( range(0,10) );
209 int numQubits = getNumCachedQubits();
210 int numTerms = GENERATE_COPY( 1, numQubits, getPow2(2*numQubits) );
211
212 PauliStrSum sum = createRandomNonHermitianPauliStrSum(numQubits, numTerms);
213
214 TEST_ALL_QUREGS(
215 qureg, calcExpecNonHermitianPauliStrSum(qureg, sum),
216 state, getReferenceExpectationValue(state, sum)
217 );
218
220 }
221
222 /// @todo input validation
223}
qcomp calcExpecNonHermitianPauliStrSum(Qureg qureg, PauliStrSum sum)
void destroyPauliStrSum(PauliStrSum sum)
Definition paulis.cpp:481

◆ TEST_CASE() [7/18]

TEST_CASE ( "calcExpecPauliStr" ,
TEST_CATEGORY  )

TESTS

Definition at line 160 of file calculations.cpp.

160 {
161
162 SECTION( LABEL_CORRECTNESS ) {
163
164 int numQubits = getNumCachedQubits();
165 int numTargs = GENERATE_COPY( range(1,numQubits+1) );
166 auto targets = GENERATE_TARGS(numQubits, numTargs);
167
168 PauliStr str = getRandomPauliStr(targets);
169
170 TEST_ALL_QUREGS(
171 qureg, calcExpecPauliStr(qureg, str),
172 state, std::real(getReferenceExpectationValue(state, str))
173 );
174 }
175
176 /// @todo input validation
177}
qreal calcExpecPauliStr(Qureg qureg, PauliStr str)

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

◆ TEST_CASE() [8/18]

TEST_CASE ( "calcExpecPauliStrSum" ,
TEST_CATEGORY  )

Definition at line 181 of file calculations.cpp.

181 {
182
183 SECTION( LABEL_CORRECTNESS ) {
184
185 int numQubits = getNumCachedQubits();
186 int numTerms = GENERATE_COPY( 1, numQubits, getPow2(2*numQubits) );
187
188 GENERATE( range(0,10) );
189 PauliStrSum sum = createRandomPauliStrSum(numQubits, numTerms);
190
191 TEST_ALL_QUREGS(
192 qureg, calcExpecPauliStrSum(qureg, sum),
193 state, std::real(getReferenceExpectationValue(state, sum))
194 );
195
197 }
198
199 /// @todo input validation
200}
qreal calcExpecPauliStrSum(Qureg qureg, PauliStrSum sum)

◆ TEST_CASE() [9/18]

TEST_CASE ( "calcFidelity" ,
TEST_CATEGORY LABEL_MIXED_DEPLOY_TAG )

Definition at line 456 of file calculations.cpp.

456 {
457
458 SECTION( LABEL_CORRECTNESS ) {
459
460 qvector refSV = getRefStatevec();
461 qmatrix refDM = getRefDensmatr();
462 auto apiFunc = calcFidelity;
463
464 GENERATE( range(0, TEST_NUM_MIXED_DEPLOYMENT_REPETITIONS) );
465
466 SECTION( LABEL_STATEVEC LABEL_DELIMITER LABEL_STATEVEC ) {
467
468 // |<a|b>|^2
469 auto refFunc = [&](qvector a, qvector b) { return std::norm(getInnerProduct(a,b)); };
470
471 TEST_ON_MIXED_CACHED_QUREGS( getCachedStatevecs(), getAltCachedStatevecs(), refSV, refSV, apiFunc, refFunc );
472 }
473
474 SECTION( LABEL_STATEVEC LABEL_DELIMITER LABEL_DENSMATR ) {
475
476 // Re[<A|B|A>]
477 auto refFunc = [&](qvector a, qmatrix b) { return std::real(getInnerProduct(a, b * a)); };
478
479 TEST_ON_MIXED_CACHED_QUREGS( getCachedStatevecs(), getAltCachedDensmatrs(), refSV, refDM, apiFunc, refFunc );
480 }
481
482 SECTION( LABEL_DENSMATR LABEL_DELIMITER LABEL_STATEVEC ) {
483
484 // Re[<B|A|B>]
485 auto refFunc = [&](qmatrix a, qvector b) { return std::real(getInnerProduct(b, a * b)); };
486
487 TEST_ON_MIXED_CACHED_QUREGS( getCachedDensmatrs(), getAltCachedStatevecs(), refDM, refSV, apiFunc, refFunc );
488 }
489
490 // (densitymatrix, densitymatrix) not supported
491 }
492
493 /// @todo input validation
494}
qreal calcFidelity(Qureg qureg, Qureg other)

◆ TEST_CASE() [10/18]

TEST_CASE ( "calcInnerProduct" ,
TEST_CATEGORY LABEL_MIXED_DEPLOY_TAG )

Definition at line 407 of file calculations.cpp.

407 {
408
409 SECTION( LABEL_CORRECTNESS ) {
410
411 qvector refSV = getRefStatevec();
412 qmatrix refDM = getRefDensmatr();
413 auto apiFunc = calcInnerProduct;
414
415 GENERATE( range(0, TEST_NUM_MIXED_DEPLOYMENT_REPETITIONS) );
416
417 SECTION( LABEL_STATEVEC LABEL_DELIMITER LABEL_STATEVEC ) {
418
419 // <a|b>
420 auto refFunc = [&](qvector a, qvector b) { return getInnerProduct (a,b); };
421
422 TEST_ON_MIXED_CACHED_QUREGS( getCachedStatevecs(), getAltCachedStatevecs(), refSV, refSV, apiFunc, refFunc );
423 }
424
425 SECTION( LABEL_STATEVEC LABEL_DELIMITER LABEL_DENSMATR ) {
426
427 // <A|B|A>
428 auto refFunc = [&](qvector a, qmatrix b) { return getInnerProduct(a, b * a); };
429
430 TEST_ON_MIXED_CACHED_QUREGS( getCachedStatevecs(), getAltCachedDensmatrs(), refSV, refDM, apiFunc, refFunc );
431 }
432
433 SECTION( LABEL_DENSMATR LABEL_DELIMITER LABEL_STATEVEC ) {
434
435 // <B|A^dagger|B>
436
437 auto refFunc = [&](qmatrix a, qvector b) { return getInnerProduct(b, getConjugateTranspose(a) * b); };
438
439 TEST_ON_MIXED_CACHED_QUREGS( getCachedDensmatrs(), getAltCachedStatevecs(), refDM, refSV, apiFunc, refFunc );
440 }
441
442 SECTION( LABEL_DENSMATR LABEL_DELIMITER LABEL_DENSMATR ) {
443
444 // Tr(a^dagger b)
445 auto refFunc = [&](qmatrix a, qmatrix b) { return getTrace(getConjugateTranspose(a) * b); };
446
447 TEST_ON_MIXED_CACHED_QUREGS( getCachedDensmatrs(), getAltCachedDensmatrs(), refDM, refDM, apiFunc, refFunc );
448 }
449 }
450
451 /// @todo input validation
452}
qcomp calcInnerProduct(Qureg qureg1, Qureg qureg2)

◆ TEST_CASE() [11/18]

TEST_CASE ( "calcPartialTrace" ,
TEST_CATEGORY  )

Definition at line 354 of file calculations.cpp.

354 {
355
356 // no statevector equivalent
357
358 SECTION( LABEL_CORRECTNESS ) {
359
360 SECTION( LABEL_DENSMATR ) {
361
362 int numQubits = getNumCachedQubits();
363 int maxNumTargs = getMaxNumTracedQubits(numQubits);
364 int numTargs = GENERATE_COPY( range(1,maxNumTargs+1) );
365 auto targets = GENERATE_TARGS(numQubits, numTargs);
366
367 auto apiFunc = [&](Qureg qureg) { return calcPartialTrace(qureg, targets.data(), numTargs); };
368 auto refFunc = [&](qmatrix ref) { return getPartialTrace(ref, targets); };
369
370 TEST_ON_CACHED_QUREGS(getCachedDensmatrs(), getRefDensmatr(), apiFunc, refFunc);
371 }
372 }
373
374 /// @todo input validation
375}
Qureg calcPartialTrace(Qureg qureg, int *traceOutQubits, int numTraceQubits)

◆ TEST_CASE() [12/18]

TEST_CASE ( "calcProbOfBasisState" ,
TEST_CATEGORY  )

Definition at line 227 of file calculations.cpp.

227 {
228
229 SECTION( LABEL_CORRECTNESS ) {
230
231 qindex index = GENERATE( range(0, 1 << getNumCachedQubits()) );
232
233 TEST_ALL_QUREGS(
234 qureg, calcProbOfBasisState(qureg, index),
235 state, getReferenceProbability(state, index)
236 );
237 }
238
239 /// @todo input validation
240}
qreal calcProbOfBasisState(Qureg qureg, qindex index)

◆ TEST_CASE() [13/18]

TEST_CASE ( "calcProbOfMultiQubitOutcome" ,
TEST_CATEGORY  )

Definition at line 262 of file calculations.cpp.

262 {
263
264 SECTION( LABEL_CORRECTNESS ) {
265
266 int numQubits = getNumCachedQubits();
267 int numTargs = GENERATE_COPY( range(1, numQubits+1) );
268 auto targets = GENERATE_TARGS(numQubits, numTargs);
269 auto outcomes = getRandomOutcomes(numTargs);
270
271 TEST_ALL_QUREGS(
272 qureg, calcProbOfMultiQubitOutcome(qureg, targets.data(), outcomes.data(), numTargs),
273 state, getReferenceProbability(state, targets, outcomes)
274 );
275 }
276
277 /// @todo input validation
278}
qreal calcProbOfMultiQubitOutcome(Qureg qureg, int *qubits, int *outcomes, int numQubits)

◆ TEST_CASE() [14/18]

TEST_CASE ( "calcProbOfQubitOutcome" ,
TEST_CATEGORY  )

Definition at line 244 of file calculations.cpp.

244 {
245
246 SECTION( LABEL_CORRECTNESS ) {
247
248 int target = GENERATE( range(0, getNumCachedQubits()) );
249 int outcome = GENERATE( 0, 1 );
250
251 TEST_ALL_QUREGS(
252 qureg, calcProbOfQubitOutcome(qureg, target, outcome),
253 state, getReferenceProbability(state, {target}, {outcome})
254 );
255 }
256
257 /// @todo input validation
258}
qreal calcProbOfQubitOutcome(Qureg qureg, int qubit, int outcome)

◆ TEST_CASE() [15/18]

TEST_CASE ( "calcProbsOfAllMultiQubitOutcomes" ,
TEST_CATEGORY  )

Definition at line 282 of file calculations.cpp.

282 {
283
284 SECTION( LABEL_CORRECTNESS ) {
285
286 int numQubits = getNumCachedQubits();
287 int numTargs = GENERATE_COPY( range(1,numQubits+1) );
288 auto targets = GENERATE_TARGS(numQubits, numTargs);
289
290 auto apiFunc = [&](Qureg qureg) {
291 vector<qreal> out(getPow2(numTargs));
292 calcProbsOfAllMultiQubitOutcomes(out.data(), qureg, targets.data(), numTargs);
293 return out;
294 };
295 auto refFunc = [&](auto& state) {
296 return getAllReferenceProbabilities(state, targets);
297 };
298
299 TEST_ON_CACHED_STATEVECS_AND_DENSMATRS( apiFunc, refFunc );
300 }
301
302 /// @todo input validation
303}
void calcProbsOfAllMultiQubitOutcomes(qreal *outcomeProbs, Qureg qureg, int *qubits, int numQubits)

◆ TEST_CASE() [16/18]

TEST_CASE ( "calcPurity" ,
TEST_CATEGORY  )

Definition at line 324 of file calculations.cpp.

324 {
325
326 SECTION( LABEL_CORRECTNESS ) {
327
328 GENERATE( range(0,100) );
329
330 TEST_ALL_QUREGS(
331 qureg, calcPurity(qureg),
332 state, getReferencePurity(state)
333 );
334 }
335
336 /// @todo input validation
337}
qreal calcPurity(Qureg qureg)

◆ TEST_CASE() [17/18]

TEST_CASE ( "calcReducedDensityMatrix" ,
TEST_CATEGORY  )

Definition at line 379 of file calculations.cpp.

379 {
380
381 // no statevector equivalent
382
383 SECTION( LABEL_CORRECTNESS ) {
384
385 SECTION( LABEL_DENSMATR ) {
386
387 int numQubits = getNumCachedQubits();
388 int maxNumTraced = getMaxNumTracedQubits(numQubits);
389 int minNumRetained = numQubits - maxNumTraced;
390 int maxNumRetained = numQubits - 1;
391 int numRetained = GENERATE_COPY( range(minNumRetained, maxNumRetained+1) );
392 auto retains = GENERATE_TARGS(numQubits, numRetained);
393 auto targets = getComplement(getRange(numQubits), retains);
394
395 auto apiFunc = [&](Qureg qureg) { return calcReducedDensityMatrix(qureg, retains.data(), numRetained); };
396 auto refFunc = [&](qmatrix ref) { return getPartialTrace(ref, targets); };
397
398 TEST_ON_CACHED_QUREGS(getCachedDensmatrs(), getRefDensmatr(), apiFunc, refFunc);
399 }
400 }
401
402 /// @todo input validation
403}
Qureg calcReducedDensityMatrix(Qureg qureg, int *retainQubits, int numRetainQubits)

◆ TEST_CASE() [18/18]

TEST_CASE ( "calcTotalProb" ,
TEST_CATEGORY  )

Definition at line 307 of file calculations.cpp.

307 {
308
309 SECTION( LABEL_CORRECTNESS ) {
310
311 GENERATE( range(0,100) );
312
313 TEST_ALL_QUREGS(
314 qureg, calcTotalProb(qureg),
315 state, getReferenceProbability(state)
316 );
317 }
318
319 /// @todo input validation
320}
qreal calcTotalProb(Qureg qureg)