The Quantum Exact Simulation Toolkit v4.0.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 497 of file calculations.cpp.

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

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

◆ TEST_CASE() [3/18]

TEST_CASE ( "calcExpecFullStateDiagMatrPower" ,
TEST_CATEGORY LABEL_MIXED_DEPLOY_TAG )

Definition at line 603 of file calculations.cpp.

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

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

◆ TEST_CASE() [5/18]

TEST_CASE ( "calcExpecNonHermitianFullStateDiagMatrPower" ,
TEST_CATEGORY LABEL_MIXED_DEPLOY_TAG )

Definition at line 665 of file calculations.cpp.

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

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

◆ TEST_CASE() [7/18]

TEST_CASE ( "calcExpecPauliStr" ,
TEST_CATEGORY  )

TESTS

Definition at line 159 of file calculations.cpp.

159 {
160
161 SECTION( LABEL_CORRECTNESS ) {
162
163 int numQubits = getNumCachedQubits();
164 int numTargs = GENERATE_COPY( range(1,numQubits+1) );
165 auto targets = GENERATE_TARGS(numQubits, numTargs);
166
167 PauliStr str = getRandomPauliStr(targets);
168
169 TEST_ALL_QUREGS(
170 qureg, calcExpecPauliStr(qureg, str),
171 state, std::real(getReferenceExpectationValue(state, str))
172 );
173 }
174
175 /// @todo input validation
176}
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 180 of file calculations.cpp.

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

◆ TEST_CASE() [9/18]

TEST_CASE ( "calcFidelity" ,
TEST_CATEGORY LABEL_MIXED_DEPLOY_TAG )

Definition at line 455 of file calculations.cpp.

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

◆ TEST_CASE() [10/18]

TEST_CASE ( "calcInnerProduct" ,
TEST_CATEGORY LABEL_MIXED_DEPLOY_TAG )

Definition at line 406 of file calculations.cpp.

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

◆ TEST_CASE() [11/18]

TEST_CASE ( "calcPartialTrace" ,
TEST_CATEGORY  )

Definition at line 353 of file calculations.cpp.

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

◆ TEST_CASE() [12/18]

TEST_CASE ( "calcProbOfBasisState" ,
TEST_CATEGORY  )

Definition at line 226 of file calculations.cpp.

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

◆ TEST_CASE() [13/18]

TEST_CASE ( "calcProbOfMultiQubitOutcome" ,
TEST_CATEGORY  )

Definition at line 261 of file calculations.cpp.

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

◆ TEST_CASE() [14/18]

TEST_CASE ( "calcProbOfQubitOutcome" ,
TEST_CATEGORY  )

Definition at line 243 of file calculations.cpp.

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

◆ TEST_CASE() [15/18]

TEST_CASE ( "calcProbsOfAllMultiQubitOutcomes" ,
TEST_CATEGORY  )

Definition at line 281 of file calculations.cpp.

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

◆ TEST_CASE() [16/18]

TEST_CASE ( "calcPurity" ,
TEST_CATEGORY  )

Definition at line 323 of file calculations.cpp.

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

◆ TEST_CASE() [17/18]

TEST_CASE ( "calcReducedDensityMatrix" ,
TEST_CATEGORY  )

Definition at line 378 of file calculations.cpp.

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

◆ TEST_CASE() [18/18]

TEST_CASE ( "calcTotalProb" ,
TEST_CATEGORY  )

Definition at line 306 of file calculations.cpp.

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