The Quantum Exact Simulation Toolkit v4.2.0
Loading...
Searching...
No Matches
 TEST_ALL_CTRL_OPERATIONS (PauliStr, any, paulistr, nullptr)
 
 TEST_ALL_CTRL_OPERATIONS (PauliGadget, any, pauligad, nullptr)
 
 TEST_ALL_CTRL_OPERATIONS (CompMatr1, one, compmatr, nullptr)
 
 TEST_ALL_CTRL_OPERATIONS (CompMatr2, two, compmatr, nullptr)
 
 TEST_ALL_CTRL_OPERATIONS (CompMatr, any, compmatr, nullptr)
 
 TEST_ALL_CTRL_OPERATIONS (DiagMatr1, one, diagmatr, nullptr)
 
 TEST_ALL_CTRL_OPERATIONS (DiagMatr2, two, diagmatr, nullptr)
 
 TEST_ALL_CTRL_OPERATIONS (DiagMatr, any, diagmatr, nullptr)
 
 TEST_ALL_CTRL_OPERATIONS (DiagMatrPower, any, diagpower, nullptr)
 
 TEST_ALL_CTRL_OPERATIONS (Hadamard, one, none, FixedMatrices::H)
 
 TEST_ALL_CTRL_OPERATIONS (PauliX, one, none, FixedMatrices::X)
 
 TEST_ALL_CTRL_OPERATIONS (PauliY, one, none, FixedMatrices::Y)
 
 TEST_ALL_CTRL_OPERATIONS (PauliZ, one, none, FixedMatrices::Z)
 
 TEST_ALL_CTRL_OPERATIONS (T, one, none, FixedMatrices::T)
 
 TEST_ALL_CTRL_OPERATIONS (S, one, none, FixedMatrices::S)
 
 TEST_ALL_CTRL_OPERATIONS (Swap, two, none, FixedMatrices::SWAP)
 
 TEST_ALL_CTRL_OPERATIONS (SqrtSwap, two, none, FixedMatrices::sqrtSWAP)
 
 TEST_ALL_CTRL_OPERATIONS (RotateX, one, scalar, ParameterisedMatrices::Rx)
 
 TEST_ALL_CTRL_OPERATIONS (RotateY, one, scalar, ParameterisedMatrices::Ry)
 
 TEST_ALL_CTRL_OPERATIONS (RotateZ, one, scalar, ParameterisedMatrices::Rz)
 
 TEST_ALL_CTRL_OPERATIONS (RotateAroundAxis, one, axisrots, nullptr)
 
 TEST_ALL_CTRL_OPERATIONS (MultiQubitNot, any, none, VariableSizeMatrices::X)
 
 TEST_ALL_CTRL_OPERATIONS (PhaseGadget, any, scalar, VariableSizeParameterisedMatrices::Z)
 
 TEST_CASE ("applyPhaseFlip", TEST_CATEGORY_OPS)
 
 TEST_CASE ("applyTwoQubitPhaseFlip", TEST_CATEGORY_OPS)
 
 TEST_CASE ("applyPhaseShift", TEST_CATEGORY_OPS)
 
 TEST_CASE ("applyTwoQubitPhaseShift", TEST_CATEGORY_OPS)
 
 TEST_CASE ("applyMultiQubitPhaseFlip", TEST_CATEGORY_OPS)
 
 TEST_CASE ("applyMultiQubitPhaseShift", TEST_CATEGORY_OPS)
 
 TEST_CASE ("applyQuantumFourierTransform", TEST_CATEGORY_OPS)
 
 TEST_CASE ("applyFullQuantumFourierTransform", TEST_CATEGORY_OPS)
 
 TEST_CASE ("applyQubitProjector", TEST_CATEGORY_OPS)
 
 TEST_CASE ("applyMultiQubitProjector", TEST_CATEGORY_OPS)
 
 TEST_CASE ("applyForcedQubitMeasurement", TEST_CATEGORY_OPS)
 
 TEST_CASE ("applyForcedMultiQubitMeasurement", TEST_CATEGORY_OPS)
 
 TEST_CASE ("applyMultiQubitMeasurement", TEST_CATEGORY_OPS)
 
 TEST_CASE ("applyMultiQubitMeasurementAndGetProb", TEST_CATEGORY_OPS)
 
 TEST_CASE ("applyQubitMeasurement", TEST_CATEGORY_OPS)
 
 TEST_CASE ("applyQubitMeasurementAndGetProb", TEST_CATEGORY_OPS)
 
 TEST_CASE ("applyFullStateDiagMatr", TEST_CATEGORY_OPS LABEL_MIXED_DEPLOY_TAG)
 
 TEST_CASE ("applyFullStateDiagMatrPower", TEST_CATEGORY_OPS LABEL_MIXED_DEPLOY_TAG)
 
 TEST_CASE ("applyNonUnitaryPauliGadget", TEST_CATEGORY_OPS)
 

Detailed Description

Function Documentation

◆ TEST_ALL_CTRL_OPERATIONS()

TEST_ALL_CTRL_OPERATIONS ( PauliStr ,
any ,
paulistr ,
nullptr  )

OPERATOR TESTS

◆ TEST_CASE() [1/19]

TEST_CASE ( "applyForcedMultiQubitMeasurement" ,
TEST_CATEGORY_OPS  )

Definition at line 1549 of file operations.cpp.

1549 {
1550
1551 PREPARE_TEST( numQubits, statevecQuregs, densmatrQuregs, statevecRef, densmatrRef );
1552
1553 SECTION( LABEL_CORRECTNESS ) {
1554
1555 int numTargs = GENERATE_COPY( range(1,numQubits+1) );
1556 auto targets = GENERATE_TARGS( numQubits, numTargs );
1557 auto outcomes = getRandomOutcomes(numTargs);
1558
1559 qmatrix projector = getProjector(targets, outcomes, numQubits);
1560
1561 // this test may randomly request a measurement outcome which
1562 // is illegally unlikely, triggering validation; we merely
1563 // disable such validation and hope divergences don't break the test!
1565
1566 auto testFunc = [&](Qureg qureg, auto& ref) {
1567
1568 // overwrite caller's setting of initDebugState, since
1569 // that precludes outcomes=|0><0| due to zero-probability
1570 setToRandomState(ref);
1571 setQuregToReference(qureg, ref);
1572
1573 // compare the probabilities...
1574 qreal apiProb = applyForcedMultiQubitMeasurement(qureg, targets.data(), outcomes.data(), numTargs);
1575 qreal refProb = getReferenceProbability(ref, targets, outcomes);
1576 REQUIRE_AGREE( apiProb, refProb );
1577
1578 // and the post-measurement states (caller calls subsequent REQUIRE_AGREE)
1579 applyReferenceOperator(ref, projector);
1580 ref /= (qureg.isDensityMatrix)?
1581 refProb : std::sqrt(refProb);
1582 };
1583
1584 CAPTURE( targets, outcomes );
1585 SECTION( LABEL_STATEVEC ) { TEST_ON_CACHED_QUREGS(statevecQuregs, statevecRef, testFunc); }
1586 SECTION( LABEL_DENSMATR ) { TEST_ON_CACHED_QUREGS(densmatrQuregs, densmatrRef, testFunc); }
1587
1589 }
1590
1591 /// @todo input validation
1592}
void setValidationEpsilonToDefault()
Definition debug.cpp:108
void setValidationEpsilon(qreal eps)
Definition debug.cpp:100
qreal applyForcedMultiQubitMeasurement(Qureg qureg, int *qubits, int *outcomes, int numQubits)
Definition qureg.h:49

◆ TEST_CASE() [2/19]

TEST_CASE ( "applyForcedQubitMeasurement" ,
TEST_CATEGORY_OPS  )

Definition at line 1510 of file operations.cpp.

1510 {
1511
1512 PREPARE_TEST( numQubits, statevecQuregs, densmatrQuregs, statevecRef, densmatrRef );
1513
1514 SECTION( LABEL_CORRECTNESS ) {
1515
1516 GENERATE( range(0,10) );
1517 int target = GENERATE_COPY( range(0,numQubits) );
1518 int outcome = GENERATE( 0, 1 );
1519
1520 qmatrix projector = getProjector(outcome);
1521
1522 auto testFunc = [&](Qureg qureg, auto& ref) {
1523
1524 // overwrite caller's setting of initDebugState, since
1525 // that precludes outcomes=|0><0| due to zero-probability
1526 setToRandomState(ref);
1527 setQuregToReference(qureg, ref);
1528
1529 // compare the probabilities...
1530 qreal apiProb = applyForcedQubitMeasurement(qureg, target, outcome);
1531 qreal refProb = getReferenceProbability(ref, {target}, {outcome});
1532 REQUIRE_AGREE( apiProb, refProb );
1533
1534 // and the post-projection states (caller calls subsequent REQUIRE_AGREE)
1535 applyReferenceOperator(ref, {target}, projector);
1536 ref /= (qureg.isDensityMatrix)?
1537 refProb : std::sqrt(refProb);
1538 };
1539
1540 CAPTURE( target, outcome );
1541 SECTION( LABEL_STATEVEC ) { TEST_ON_CACHED_QUREGS(statevecQuregs, statevecRef, testFunc); }
1542 SECTION( LABEL_DENSMATR ) { TEST_ON_CACHED_QUREGS(densmatrQuregs, densmatrRef, testFunc); }
1543 }
1544
1545 /// @todo input validation
1546}
qreal applyForcedQubitMeasurement(Qureg qureg, int target, int outcome)

◆ TEST_CASE() [3/19]

TEST_CASE ( "applyFullQuantumFourierTransform" ,
TEST_CATEGORY_OPS  )

Definition at line 1413 of file operations.cpp.

1413 {
1414
1415 PREPARE_TEST( numQubits, statevecQuregs, densmatrQuregs, statevecRef, densmatrRef );
1416
1417 SECTION( LABEL_CORRECTNESS ) {
1418
1419 GENERATE( range(0,10) );
1420
1421 SECTION( LABEL_STATEVEC ) {
1422
1423 auto testFunc = [&](Qureg qureg, qvector& ref) {
1425 ref = getDisceteFourierTransform(ref);
1426 };
1427
1428 TEST_ON_CACHED_QUREGS(statevecQuregs, statevecRef, testFunc);
1429 }
1430
1431 SECTION( LABEL_DENSMATR ) {
1432
1433 // prepare a random mixture
1434 auto states = getRandomOrthonormalStateVectors(numQubits, getRandomInt(1,10));
1435 auto probs = getRandomProbabilities(states.size());
1436
1437 auto testFunc = [&](Qureg qureg, qmatrix& ref) {
1438
1439 // overwrite the Qureg debug state set by caller to above mixture
1440 setQuregToReference(qureg, getMixture(states, probs));
1442
1443 ref = getZeroMatrix(ref.size());
1444 for (size_t i=0; i<states.size(); i++) {
1445 qvector vec = getDisceteFourierTransform(states[i]);
1446 ref += probs[i] * getOuterProduct(vec, vec);
1447 }
1448 };
1449
1450 TEST_ON_CACHED_QUREGS(densmatrQuregs, densmatrRef, testFunc);
1451 }
1452 }
1453
1454 /// @todo input validation
1455}
void applyFullQuantumFourierTransform(Qureg qureg)
qmatrix getZeroMatrix(size_t dim)
Definition qmatrix.cpp:18
vector< qreal > getRandomProbabilities(int numProbs)
Definition random.cpp:160
int getRandomInt(int min, int maxExcl)
Definition random.cpp:90

◆ TEST_CASE() [4/19]

TEST_CASE ( "applyFullStateDiagMatr" ,
TEST_CATEGORY_OPS LABEL_MIXED_DEPLOY_TAG )

Definition at line 1745 of file operations.cpp.

1745 {
1746
1747 PREPARE_TEST( numQubits, cachedSV, cachedDM, refSV, refDM );
1748
1749 auto cachedMatrs = getCachedFullStateDiagMatrs();
1750
1751 SECTION( LABEL_CORRECTNESS ) {
1752
1753 qmatrix refMatr = getRandomDiagonalUnitary(numQubits);
1754 auto apiFunc = applyFullStateDiagMatr;
1755
1756 GENERATE( range(0, getNumTestedMixedDeploymentRepetitions()) );
1757
1758 SECTION( LABEL_STATEVEC ) {
1759
1760 auto refFunc = [&] (qvector& state, qmatrix matr) { applyReferenceOperator(state, matr); };
1761
1762 TEST_ON_CACHED_QUREG_AND_MATRIX( cachedSV, cachedMatrs, apiFunc, refSV, refMatr, refFunc);
1763 }
1764
1765 SECTION( LABEL_DENSMATR ) {
1766
1767 auto refFunc = [&] (qmatrix& state, qmatrix matr) { applyReferenceOperator(state, matr); };
1768
1769 TEST_ON_CACHED_QUREG_AND_MATRIX( cachedDM, cachedMatrs, apiFunc, refDM, refMatr, refFunc);
1770 }
1771 }
1772
1773 /// @todo input validation
1774}
void applyFullStateDiagMatr(Qureg qureg, FullStateDiagMatr matrix)

◆ TEST_CASE() [5/19]

TEST_CASE ( "applyFullStateDiagMatrPower" ,
TEST_CATEGORY_OPS LABEL_MIXED_DEPLOY_TAG )

Definition at line 1777 of file operations.cpp.

1777 {
1778
1779 PREPARE_TEST( numQubits, cachedSV, cachedDM, refSV, refDM );
1780
1781 auto cachedMatrs = getCachedFullStateDiagMatrs();
1782
1783 SECTION( LABEL_CORRECTNESS ) {
1784
1785 qmatrix refMatr = getRandomDiagonalUnitary(numQubits);
1786
1787 // supplying a complex exponent requires disabling
1788 // numerical validation to relax unitarity
1789 bool testRealExp = GENERATE( true, false );
1790 qcomp exponent = (testRealExp)?
1791 qcomp(getRandomReal(-2, 2), 0):
1793
1794 auto apiFunc = [&](Qureg qureg, FullStateDiagMatr matr) {
1795 return applyFullStateDiagMatrPower(qureg, matr, exponent);
1796 };
1797
1798 CAPTURE( exponent );
1799
1800 GENERATE( range(0, getNumTestedMixedDeploymentRepetitions()) );
1801
1802 if (!testRealExp)
1804
1805 SECTION( LABEL_STATEVEC ) {
1806
1807 auto refFunc = [&] (qvector& state, qmatrix matr) {
1808 matr = getPowerOfDiagonalMatrix(matr, exponent);
1809 applyReferenceOperator(state, matr);
1810 };
1811
1812 TEST_ON_CACHED_QUREG_AND_MATRIX( cachedSV, cachedMatrs, apiFunc, refSV, refMatr, refFunc);
1813 }
1814
1815 SECTION( LABEL_DENSMATR ) {
1816
1817 auto refFunc = [&] (qmatrix& state, qmatrix matr) {
1818 matr = getPowerOfDiagonalMatrix(matr, exponent);
1819 applyReferenceOperator(state, matr);
1820 };
1821
1822 TEST_ON_CACHED_QUREG_AND_MATRIX( cachedDM, cachedMatrs, apiFunc, refDM, refMatr, refFunc);
1823 }
1824
1826 }
1827
1828 /// @todo input validation
1829}
void applyFullStateDiagMatrPower(Qureg qureg, FullStateDiagMatr matrix, qcomp exponent)
qcomp getRandomComplex()
Definition random.cpp:107
qreal getRandomReal(qreal min, qreal maxExcl)
Definition random.cpp:63

◆ TEST_CASE() [6/19]

TEST_CASE ( "applyMultiQubitMeasurement" ,
TEST_CATEGORY_OPS  )

Definition at line 1595 of file operations.cpp.

1595 {
1596
1597 PREPARE_TEST( numQubits, statevecQuregs, densmatrQuregs, statevecRef, densmatrRef );
1598
1599 SECTION( LABEL_CORRECTNESS ) {
1600
1601 int numTargs = GENERATE_COPY( range(1,numQubits+1) );
1602 auto targets = GENERATE_TARGS( numQubits, numTargs );
1603
1604 auto testFunc = [&](Qureg qureg, auto& ref) {
1605
1606 // overwrite caller's setting of initDebugState, since
1607 // sampling requires the outcome probs are normalised
1608 setToRandomState(ref);
1609 setQuregToReference(qureg, ref);
1610
1611 // the output API state...
1612 qindex apiOut = applyMultiQubitMeasurement(qureg, targets.data(), numTargs);
1613
1614 // informs the projector which determines the post-measurement reference
1615 auto apiOutBits = getBits(apiOut, numTargs);
1616 qmatrix projector = getProjector(targets, apiOutBits, numQubits);
1617 applyReferenceOperator(ref, projector);
1618 qreal refProb = getReferenceProbability(ref, targets, apiOutBits);
1619 ref /= (qureg.isDensityMatrix)?
1620 refProb : std::sqrt(refProb);
1621 };
1622
1623 CAPTURE( targets );
1624 SECTION( LABEL_STATEVEC ) { TEST_ON_CACHED_QUREGS(statevecQuregs, statevecRef, testFunc); }
1625 SECTION( LABEL_DENSMATR ) { TEST_ON_CACHED_QUREGS(densmatrQuregs, densmatrRef, testFunc); }
1626 }
1627
1628 /// @todo input validation
1629}
qindex applyMultiQubitMeasurement(Qureg qureg, int *qubits, int numQubits)

◆ TEST_CASE() [7/19]

TEST_CASE ( "applyMultiQubitMeasurementAndGetProb" ,
TEST_CATEGORY_OPS  )

Definition at line 1632 of file operations.cpp.

1632 {
1633
1634 PREPARE_TEST( numQubits, statevecQuregs, densmatrQuregs, statevecRef, densmatrRef );
1635
1636 SECTION( LABEL_CORRECTNESS ) {
1637
1638 int numTargs = GENERATE_COPY( range(1,numQubits+1) );
1639 auto targets = GENERATE_TARGS( numQubits, numTargs );
1640
1641 auto testFunc = [&](Qureg qureg, auto& ref) {
1642
1643 // overwrite caller's setting of initDebugState, since
1644 // sampling requires the outcome probs are normalised
1645 setToRandomState(ref);
1646 setQuregToReference(qureg, ref);
1647
1648 // compare the measurement probability...
1649 qreal apiProb = -1;
1650 qindex apiOut = applyMultiQubitMeasurementAndGetProb(qureg, targets.data(), numTargs, &apiProb);
1651 auto apiOutBits = getBits(apiOut, numTargs);
1652 qreal refProb = getReferenceProbability(ref, targets, apiOutBits);
1653 REQUIRE_AGREE( apiProb, refProb );
1654
1655 // and the post-measurement states (caller calls subsequent REQUIRE_AGREE)
1656 qmatrix projector = getProjector(targets, apiOutBits, numQubits);
1657 applyReferenceOperator(ref, projector);
1658 ref /= (qureg.isDensityMatrix)?
1659 refProb : std::sqrt(refProb);
1660 };
1661
1662 CAPTURE( targets );
1663 SECTION( LABEL_STATEVEC ) { TEST_ON_CACHED_QUREGS(statevecQuregs, statevecRef, testFunc); }
1664 SECTION( LABEL_DENSMATR ) { TEST_ON_CACHED_QUREGS(densmatrQuregs, densmatrRef, testFunc); }
1665 }
1666
1667 /// @todo input validation
1668}
qindex applyMultiQubitMeasurementAndGetProb(Qureg qureg, int *qubits, int numQubits, qreal *probability)

◆ TEST_CASE() [8/19]

TEST_CASE ( "applyMultiQubitPhaseFlip" ,
TEST_CATEGORY_OPS  )

Definition at line 1350 of file operations.cpp.

1350 {
1351 auto func = static_cast<void(*)(Qureg, int*, int)>(applyMultiQubitPhaseFlip);
1352 testOperation<zero,any,none,apply>(func, VariableSizeMatrices::PF);
1353}
void applyMultiQubitPhaseFlip(Qureg qureg, int *targets, int numTargets)

◆ TEST_CASE() [9/19]

TEST_CASE ( "applyMultiQubitPhaseShift" ,
TEST_CATEGORY_OPS  )

Definition at line 1355 of file operations.cpp.

1355 {
1356 auto func = static_cast<void(*)(Qureg, int*, int, qreal)>(applyMultiQubitPhaseShift);
1357 testOperation<zero,any,scalar,apply>(func, VariableSizeParameterisedMatrices::PS);
1358}
void applyMultiQubitPhaseShift(Qureg qureg, int *targets, int numTargets, qreal angle)

◆ TEST_CASE() [10/19]

TEST_CASE ( "applyMultiQubitProjector" ,
TEST_CATEGORY_OPS  )

Definition at line 1484 of file operations.cpp.

1484 {
1485
1486 PREPARE_TEST( numQubits, statevecQuregs, densmatrQuregs, statevecRef, densmatrRef );
1487
1488 SECTION( LABEL_CORRECTNESS ) {
1489
1490 int numTargs = GENERATE_COPY( range(1,numQubits+1) );
1491 auto targets = GENERATE_TARGS( numQubits, numTargs );
1492 auto outcomes = getRandomOutcomes(numTargs);
1493
1494 qmatrix projector = getProjector(targets, outcomes, numQubits);
1495
1496 auto testFunc = [&](Qureg qureg, auto& ref) {
1497 applyMultiQubitProjector(qureg, targets.data(), outcomes.data(), numTargs);
1498 applyReferenceOperator(ref, projector);
1499 };
1500
1501 CAPTURE( targets, outcomes );
1502 SECTION( LABEL_STATEVEC ) { TEST_ON_CACHED_QUREGS(statevecQuregs, statevecRef, testFunc); }
1503 SECTION( LABEL_DENSMATR ) { TEST_ON_CACHED_QUREGS(densmatrQuregs, densmatrRef, testFunc); }
1504 }
1505
1506 /// @todo input validation
1507}
void applyMultiQubitProjector(Qureg qureg, int *qubits, int *outcomes, int numQubits)

◆ TEST_CASE() [11/19]

TEST_CASE ( "applyNonUnitaryPauliGadget" ,
TEST_CATEGORY_OPS  )

Definition at line 1832 of file operations.cpp.

1832 {
1833
1834 PREPARE_TEST( numQubits, statevecQuregs, densmatrQuregs, statevecRef, densmatrRef );
1835
1836 SECTION( LABEL_CORRECTNESS ) {
1837
1838 // prepare a random Pauli string and angle
1839 int numTargs = GENERATE_COPY( range(1, numQubits+1) );
1840 auto targs = GENERATE_TARGS( numQubits, numTargs );
1841 PauliStr str = getRandomPauliStr(targs);
1842 qcomp angle = getRandomComplex();
1843
1844 // prepare the corresponding reference matrix exp(-i angle pauli)
1845 auto matrRef = getExponentialOfPauliMatrix(angle, getMatrix(str, numQubits));
1846
1847 auto testFunc = [&](Qureg qureg, auto& stateRef) {
1848 applyNonUnitaryPauliGadget(qureg, str, angle);
1849 applyReferenceOperator(stateRef, matrRef);
1850 };
1851
1852 CAPTURE( targs, angle );
1853 SECTION( LABEL_STATEVEC ) { TEST_ON_CACHED_QUREGS(statevecQuregs, statevecRef, testFunc); }
1854 SECTION( LABEL_DENSMATR ) { TEST_ON_CACHED_QUREGS(densmatrQuregs, densmatrRef, testFunc); }
1855 }
1856
1857 /// @todo input validation
1858}
void applyNonUnitaryPauliGadget(Qureg qureg, PauliStr str, qcomp angle)

◆ TEST_CASE() [12/19]

TEST_CASE ( "applyPhaseFlip" ,
TEST_CATEGORY_OPS  )

Definition at line 1337 of file operations.cpp.

1337{ testOperation<zero,one,none,apply> (applyPhaseFlip, VariableSizeMatrices::PF(1)); }
void applyPhaseFlip(Qureg qureg, int target)

◆ TEST_CASE() [13/19]

TEST_CASE ( "applyPhaseShift" ,
TEST_CATEGORY_OPS  )

Definition at line 1339 of file operations.cpp.

1339{ testOperation<zero,one,scalar,apply>(applyPhaseShift, ParameterisedMatrices::PS ); }
void applyPhaseShift(Qureg qureg, int target, qreal angle)

◆ TEST_CASE() [14/19]

TEST_CASE ( "applyQuantumFourierTransform" ,
TEST_CATEGORY_OPS  )

Definition at line 1365 of file operations.cpp.

1365 {
1366
1367 PREPARE_TEST( numQubits, statevecQuregs, densmatrQuregs, statevecRef, densmatrRef );
1368
1369 SECTION( LABEL_CORRECTNESS ) {
1370
1371 int numTargs = GENERATE_COPY( range(1,numQubits+1) );
1372 auto targs = GENERATE_TARGS( numQubits, numTargs );
1373
1374 CAPTURE( targs );
1375
1376 SECTION( LABEL_STATEVEC ) {
1377
1378 auto testFunc = [&](Qureg qureg, qvector& ref) {
1379 applyQuantumFourierTransform(qureg, targs.data(), targs.size());
1380 ref = getDisceteFourierTransform(ref, targs);
1381 };
1382
1383 TEST_ON_CACHED_QUREGS(statevecQuregs, statevecRef, testFunc);
1384 }
1385
1386 SECTION( LABEL_DENSMATR ) {
1387
1388 // prepare a random mixture
1389 auto states = getRandomOrthonormalStateVectors(numQubits, getRandomInt(1,10));
1390 auto probs = getRandomProbabilities(states.size());
1391
1392 auto testFunc = [&](Qureg qureg, qmatrix& ref) {
1393
1394 // overwrite the Qureg debug state set by caller to above mixture
1395 setQuregToReference(qureg, getMixture(states, probs));
1396 applyQuantumFourierTransform(qureg, targs.data(), targs.size());
1397
1398 ref = getZeroMatrix(ref.size());
1399 for (size_t i=0; i<states.size(); i++) {
1400 qvector vec = getDisceteFourierTransform(states[i], targs);
1401 ref += probs[i] * getOuterProduct(vec, vec);
1402 }
1403 };
1404
1405 TEST_ON_CACHED_QUREGS(densmatrQuregs, densmatrRef, testFunc);
1406 }
1407 }
1408
1409 /// @todo input validation
1410}
void applyQuantumFourierTransform(Qureg qureg, int *targets, int numTargets)

◆ TEST_CASE() [15/19]

TEST_CASE ( "applyQubitMeasurement" ,
TEST_CATEGORY_OPS  )

Definition at line 1671 of file operations.cpp.

1671 {
1672
1673 PREPARE_TEST( numQubits, statevecQuregs, densmatrQuregs, statevecRef, densmatrRef );
1674
1675 SECTION( LABEL_CORRECTNESS ) {
1676
1677 GENERATE( range(0,10) );
1678 int target = GENERATE_COPY( range(0,numQubits) );
1679
1680 auto testFunc = [&](Qureg qureg, auto& ref) {
1681
1682 // overwrite caller's setting of initDebugState, since
1683 // sampling requires the outcome probs are normalised
1684 setToRandomState(ref);
1685 setQuregToReference(qureg, ref);
1686
1687 // the output API state...
1688 int apiOut = applyQubitMeasurement(qureg, target);
1689
1690 // informs the projector which determines the post-measurement reference
1691 qmatrix projector = getProjector(apiOut);
1692 applyReferenceOperator(ref, {target}, projector);
1693 qreal refProb = getReferenceProbability(ref, {target}, {apiOut});
1694 ref /= (qureg.isDensityMatrix)?
1695 refProb : std::sqrt(refProb);
1696 };
1697
1698 CAPTURE( target );
1699 SECTION( LABEL_STATEVEC ) { TEST_ON_CACHED_QUREGS(statevecQuregs, statevecRef, testFunc); }
1700 SECTION( LABEL_DENSMATR ) { TEST_ON_CACHED_QUREGS(densmatrQuregs, densmatrRef, testFunc); }
1701 }
1702
1703 /// @todo input validation
1704}
int applyQubitMeasurement(Qureg qureg, int target)

◆ TEST_CASE() [16/19]

TEST_CASE ( "applyQubitMeasurementAndGetProb" ,
TEST_CATEGORY_OPS  )

Definition at line 1707 of file operations.cpp.

1707 {
1708
1709 PREPARE_TEST( numQubits, statevecQuregs, densmatrQuregs, statevecRef, densmatrRef );
1710
1711 SECTION( LABEL_CORRECTNESS ) {
1712
1713 GENERATE( range(0,10) );
1714 int target = GENERATE_COPY( range(0,numQubits) );
1715
1716 auto testFunc = [&](Qureg qureg, auto& ref) {
1717
1718 // overwrite caller's setting of initDebugState, since
1719 // sampling requires the outcome probs are normalised
1720 setToRandomState(ref);
1721 setQuregToReference(qureg, ref);
1722
1723 // compare the measurement probability...
1724 qreal apiProb = -1;
1725 int apiOut = applyQubitMeasurementAndGetProb(qureg, target, &apiProb);
1726 qreal refProb = getReferenceProbability(ref, {target}, {apiOut});
1727 REQUIRE_AGREE( apiProb, refProb );
1728
1729 // and the post-measurement states (caller calls subsequent REQUIRE_AGREE)
1730 qmatrix projector = getProjector(apiOut);
1731 applyReferenceOperator(ref, {target}, projector);
1732 ref /= (qureg.isDensityMatrix)?
1733 refProb : std::sqrt(refProb);
1734 };
1735
1736 CAPTURE( target );
1737 SECTION( LABEL_STATEVEC ) { TEST_ON_CACHED_QUREGS(statevecQuregs, statevecRef, testFunc); }
1738 SECTION( LABEL_DENSMATR ) { TEST_ON_CACHED_QUREGS(densmatrQuregs, densmatrRef, testFunc); }
1739 }
1740
1741 /// @todo input validation
1742}
int applyQubitMeasurementAndGetProb(Qureg qureg, int target, qreal *probability)

◆ TEST_CASE() [17/19]

TEST_CASE ( "applyQubitProjector" ,
TEST_CATEGORY_OPS  )

Definition at line 1458 of file operations.cpp.

1458 {
1459
1460 PREPARE_TEST( numQubits, statevecQuregs, densmatrQuregs, statevecRef, densmatrRef );
1461
1462 SECTION( LABEL_CORRECTNESS ) {
1463
1464 GENERATE( range(0,10) );
1465 int target = GENERATE_COPY( range(0,numQubits) );
1466 int outcome = GENERATE( 0, 1 );
1467
1468 qmatrix projector = getProjector(outcome);
1469
1470 auto testFunc = [&](Qureg qureg, auto& ref) {
1471 applyQubitProjector(qureg, target, outcome);
1472 applyReferenceOperator(ref, {target}, projector);
1473 };
1474
1475 CAPTURE( target, outcome );
1476 SECTION( LABEL_STATEVEC ) { TEST_ON_CACHED_QUREGS(statevecQuregs, statevecRef, testFunc); }
1477 SECTION( LABEL_DENSMATR ) { TEST_ON_CACHED_QUREGS(densmatrQuregs, densmatrRef, testFunc); }
1478 }
1479
1480 /// @todo input validation
1481}
void applyQubitProjector(Qureg qureg, int target, int outcome)

◆ TEST_CASE() [18/19]

TEST_CASE ( "applyTwoQubitPhaseFlip" ,
TEST_CATEGORY_OPS  )

Definition at line 1338 of file operations.cpp.

1338{ testOperation<zero,two,none,apply> (applyTwoQubitPhaseFlip, VariableSizeMatrices::PF(2)); }
void applyTwoQubitPhaseFlip(Qureg qureg, int target1, int target2)

◆ TEST_CASE() [19/19]

TEST_CASE ( "applyTwoQubitPhaseShift" ,
TEST_CATEGORY_OPS  )

Definition at line 1340 of file operations.cpp.

1340{ testOperation<zero,two,scalar,apply>(applyTwoQubitPhaseShift, ParameterisedMatrices::PS2 ); }
void applyTwoQubitPhaseShift(Qureg qureg, int target1, int target2, qreal angle)