The Quantum Exact Simulation Toolkit v4.0.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 ("multiplyPauliStr", TEST_CATEGORY)
 
 TEST_CASE ("multiplyPauliGadget", TEST_CATEGORY)
 
 TEST_CASE ("multiplyCompMatr1", TEST_CATEGORY)
 
 TEST_CASE ("multiplyCompMatr2", TEST_CATEGORY)
 
 TEST_CASE ("multiplyDiagMatr1", TEST_CATEGORY)
 
 TEST_CASE ("multiplyDiagMatr2", TEST_CATEGORY)
 
 TEST_CASE ("applyPhaseFlip", TEST_CATEGORY)
 
 TEST_CASE ("applyTwoQubitPhaseFlip", TEST_CATEGORY)
 
 TEST_CASE ("applyPhaseShift", TEST_CATEGORY)
 
 TEST_CASE ("applyTwoQubitPhaseShift", TEST_CATEGORY)
 
 TEST_CASE ("multiplyCompMatr", TEST_CATEGORY)
 
 TEST_CASE ("multiplyDiagMatr", TEST_CATEGORY)
 
 TEST_CASE ("multiplyDiagMatrPower", TEST_CATEGORY)
 
 TEST_CASE ("multiplyMultiQubitNot", TEST_CATEGORY)
 
 TEST_CASE ("multiplyPhaseGadget", TEST_CATEGORY)
 
 TEST_CASE ("applyMultiQubitPhaseFlip", TEST_CATEGORY)
 
 TEST_CASE ("applyMultiQubitPhaseShift", TEST_CATEGORY)
 
 TEST_CASE ("applyQuantumFourierTransform", TEST_CATEGORY)
 
 TEST_CASE ("applyFullQuantumFourierTransform", TEST_CATEGORY)
 
 TEST_CASE ("applyQubitProjector", TEST_CATEGORY)
 
 TEST_CASE ("applyMultiQubitProjector", TEST_CATEGORY)
 
 TEST_CASE ("applyForcedQubitMeasurement", TEST_CATEGORY)
 
 TEST_CASE ("applyForcedMultiQubitMeasurement", TEST_CATEGORY)
 
 TEST_CASE ("applyMultiQubitMeasurement", TEST_CATEGORY)
 
 TEST_CASE ("applyMultiQubitMeasurementAndGetProb", TEST_CATEGORY)
 
 TEST_CASE ("applyQubitMeasurement", TEST_CATEGORY)
 
 TEST_CASE ("applyQubitMeasurementAndGetProb", TEST_CATEGORY)
 
 TEST_CASE ("multiplyFullStateDiagMatr", TEST_CATEGORY LABEL_MIXED_DEPLOY_TAG)
 
 TEST_CASE ("multiplyFullStateDiagMatrPower", TEST_CATEGORY LABEL_MIXED_DEPLOY_TAG)
 
 TEST_CASE ("applyFullStateDiagMatr", TEST_CATEGORY LABEL_MIXED_DEPLOY_TAG)
 
 TEST_CASE ("applyFullStateDiagMatrPower", TEST_CATEGORY LABEL_MIXED_DEPLOY_TAG)
 
 TEST_CASE ("multiplyPauliStrSum", TEST_CATEGORY LABEL_MIXED_DEPLOY_TAG)
 

Detailed Description

Function Documentation

◆ TEST_ALL_CTRL_OPERATIONS()

TEST_ALL_CTRL_OPERATIONS ( PauliStr ,
any ,
paulistr ,
nullptr  )

TESTS

◆ TEST_CASE() [1/32]

TEST_CASE ( "applyForcedMultiQubitMeasurement" ,
TEST_CATEGORY  )

Definition at line 1534 of file operations.cpp.

1534 {
1535
1536 PREPARE_TEST( numQubits, statevecQuregs, densmatrQuregs, statevecRef, densmatrRef );
1537
1538 SECTION( LABEL_CORRECTNESS ) {
1539
1540 int numTargs = GENERATE_COPY( range(1,numQubits+1) );
1541 auto targets = GENERATE_TARGS( numQubits, numTargs );
1542 auto outcomes = getRandomOutcomes(numTargs);
1543
1544 qmatrix projector = getProjector(targets, outcomes, numQubits);
1545
1546 // this test may randomly request a measurement outcome which
1547 // is illegally unlikely, triggering validation; we merely
1548 // disable such validation and hope divergences don't break the test!
1550
1551 auto testFunc = [&](Qureg qureg, auto& ref) {
1552
1553 // overwrite caller's setting of initDebugState, since
1554 // that precludes outcomes=|0><0| due to zero-probability
1555 setToRandomState(ref);
1556 setQuregToReference(qureg, ref);
1557
1558 // compare the probabilities...
1559 qreal apiProb = applyForcedMultiQubitMeasurement(qureg, targets.data(), outcomes.data(), numTargs);
1560 qreal refProb = getReferenceProbability(ref, targets, outcomes);
1561 REQUIRE_AGREE( apiProb, refProb );
1562
1563 // and the post-measurement states (caller calls subsequent REQUIRE_AGREE)
1564 applyReferenceOperator(ref, projector);
1565 ref /= (qureg.isDensityMatrix)?
1566 refProb : std::sqrt(refProb);
1567 };
1568
1569 CAPTURE( targets, outcomes );
1570 SECTION( LABEL_STATEVEC ) { TEST_ON_CACHED_QUREGS(statevecQuregs, statevecRef, testFunc); }
1571 SECTION( LABEL_DENSMATR ) { TEST_ON_CACHED_QUREGS(densmatrQuregs, densmatrRef, testFunc); }
1572
1574 }
1575
1576 /// @todo input validation
1577}
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/32]

TEST_CASE ( "applyForcedQubitMeasurement" ,
TEST_CATEGORY  )

Definition at line 1495 of file operations.cpp.

1495 {
1496
1497 PREPARE_TEST( numQubits, statevecQuregs, densmatrQuregs, statevecRef, densmatrRef );
1498
1499 SECTION( LABEL_CORRECTNESS ) {
1500
1501 GENERATE( range(0,10) );
1502 int target = GENERATE_COPY( range(0,numQubits) );
1503 int outcome = GENERATE( 0, 1 );
1504
1505 qmatrix projector = getProjector(outcome);
1506
1507 auto testFunc = [&](Qureg qureg, auto& ref) {
1508
1509 // overwrite caller's setting of initDebugState, since
1510 // that precludes outcomes=|0><0| due to zero-probability
1511 setToRandomState(ref);
1512 setQuregToReference(qureg, ref);
1513
1514 // compare the probabilities...
1515 qreal apiProb = applyForcedQubitMeasurement(qureg, target, outcome);
1516 qreal refProb = getReferenceProbability(ref, {target}, {outcome});
1517 REQUIRE_AGREE( apiProb, refProb );
1518
1519 // and the post-projection states (caller calls subsequent REQUIRE_AGREE)
1520 applyReferenceOperator(ref, {target}, projector);
1521 ref /= (qureg.isDensityMatrix)?
1522 refProb : std::sqrt(refProb);
1523 };
1524
1525 CAPTURE( target, outcome );
1526 SECTION( LABEL_STATEVEC ) { TEST_ON_CACHED_QUREGS(statevecQuregs, statevecRef, testFunc); }
1527 SECTION( LABEL_DENSMATR ) { TEST_ON_CACHED_QUREGS(densmatrQuregs, densmatrRef, testFunc); }
1528 }
1529
1530 /// @todo input validation
1531}
qreal applyForcedQubitMeasurement(Qureg qureg, int target, int outcome)

◆ TEST_CASE() [3/32]

TEST_CASE ( "applyFullQuantumFourierTransform" ,
TEST_CATEGORY  )

Definition at line 1398 of file operations.cpp.

1398 {
1399
1400 PREPARE_TEST( numQubits, statevecQuregs, densmatrQuregs, statevecRef, densmatrRef );
1401
1402 SECTION( LABEL_CORRECTNESS ) {
1403
1404 GENERATE( range(0,10) );
1405
1406 SECTION( LABEL_STATEVEC ) {
1407
1408 auto testFunc = [&](Qureg qureg, qvector& ref) {
1410 ref = getDisceteFourierTransform(ref);
1411 };
1412
1413 TEST_ON_CACHED_QUREGS(statevecQuregs, statevecRef, testFunc);
1414 }
1415
1416 SECTION( LABEL_DENSMATR ) {
1417
1418 // prepare a random mixture
1419 auto states = getRandomOrthonormalStateVectors(numQubits, getRandomInt(1,10));
1420 auto probs = getRandomProbabilities(states.size());
1421
1422 auto testFunc = [&](Qureg qureg, qmatrix& ref) {
1423
1424 // overwrite the Qureg debug state set by caller to above mixture
1425 setQuregToReference(qureg, getMixture(states, probs));
1427
1428 ref = getZeroMatrix(ref.size());
1429 for (size_t i=0; i<states.size(); i++) {
1430 qvector vec = getDisceteFourierTransform(states[i]);
1431 ref += probs[i] * getOuterProduct(vec, vec);
1432 }
1433 };
1434
1435 TEST_ON_CACHED_QUREGS(densmatrQuregs, densmatrRef, testFunc);
1436 }
1437 }
1438
1439 /// @todo input validation
1440}
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/32]

TEST_CASE ( "applyFullStateDiagMatr" ,
TEST_CATEGORY LABEL_MIXED_DEPLOY_TAG )

Definition at line 1806 of file operations.cpp.

1806 {
1807
1808 PREPARE_TEST( numQubits, cachedSV, cachedDM, refSV, refDM );
1809
1810 auto cachedMatrs = getCachedFullStateDiagMatrs();
1811
1812 SECTION( LABEL_CORRECTNESS ) {
1813
1814 qmatrix refMatr = getRandomDiagonalUnitary(numQubits);
1815 auto apiFunc = applyFullStateDiagMatr;
1816
1817 GENERATE( range(0, TEST_NUM_MIXED_DEPLOYMENT_REPETITIONS) );
1818
1819 SECTION( LABEL_STATEVEC ) {
1820
1821 auto refFunc = [&] (qvector& state, qmatrix matr) { applyReferenceOperator(state, matr); };
1822
1823 TEST_ON_CACHED_QUREG_AND_MATRIX( cachedSV, cachedMatrs, apiFunc, refSV, refMatr, refFunc);
1824 }
1825
1826 SECTION( LABEL_DENSMATR ) {
1827
1828 auto refFunc = [&] (qmatrix& state, qmatrix matr) { applyReferenceOperator(state, matr); };
1829
1830 TEST_ON_CACHED_QUREG_AND_MATRIX( cachedDM, cachedMatrs, apiFunc, refDM, refMatr, refFunc);
1831 }
1832 }
1833
1834 /// @todo input validation
1835}
void applyFullStateDiagMatr(Qureg qureg, FullStateDiagMatr matrix)
const int TEST_NUM_MIXED_DEPLOYMENT_REPETITIONS
Definition macros.hpp:63

◆ TEST_CASE() [5/32]

TEST_CASE ( "applyFullStateDiagMatrPower" ,
TEST_CATEGORY LABEL_MIXED_DEPLOY_TAG )

Definition at line 1838 of file operations.cpp.

1838 {
1839
1840 PREPARE_TEST( numQubits, cachedSV, cachedDM, refSV, refDM );
1841
1842 auto cachedMatrs = getCachedFullStateDiagMatrs();
1843
1844 SECTION( LABEL_CORRECTNESS ) {
1845
1846 qmatrix refMatr = getRandomDiagonalUnitary(numQubits);
1847
1848 // supplying a complex exponent requires disabling
1849 // numerical validation to relax unitarity
1850 bool testRealExp = GENERATE( true, false );
1851 qcomp exponent = (testRealExp)?
1852 qcomp(getRandomReal(-2, 2), 0):
1854
1855 auto apiFunc = [&](Qureg qureg, FullStateDiagMatr matr) {
1856 return applyFullStateDiagMatrPower(qureg, matr, exponent);
1857 };
1858
1859 CAPTURE( exponent );
1860
1861 GENERATE( range(0, TEST_NUM_MIXED_DEPLOYMENT_REPETITIONS) );
1862
1863 if (!testRealExp)
1865
1866 SECTION( LABEL_STATEVEC ) {
1867
1868 auto refFunc = [&] (qvector& state, qmatrix matr) {
1869 matr = getPowerOfDiagonalMatrix(matr, exponent);
1870 applyReferenceOperator(state, matr);
1871 };
1872
1873 TEST_ON_CACHED_QUREG_AND_MATRIX( cachedSV, cachedMatrs, apiFunc, refSV, refMatr, refFunc);
1874 }
1875
1876 SECTION( LABEL_DENSMATR ) {
1877
1878 auto refFunc = [&] (qmatrix& state, qmatrix matr) {
1879 matr = getPowerOfDiagonalMatrix(matr, exponent);
1880 applyReferenceOperator(state, matr);
1881 };
1882
1883 TEST_ON_CACHED_QUREG_AND_MATRIX( cachedDM, cachedMatrs, apiFunc, refDM, refMatr, refFunc);
1884 }
1885
1887 }
1888
1889 /// @todo input validation
1890}
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/32]

TEST_CASE ( "applyMultiQubitMeasurement" ,
TEST_CATEGORY  )

Definition at line 1580 of file operations.cpp.

1580 {
1581
1582 PREPARE_TEST( numQubits, statevecQuregs, densmatrQuregs, statevecRef, densmatrRef );
1583
1584 SECTION( LABEL_CORRECTNESS ) {
1585
1586 int numTargs = GENERATE_COPY( range(1,numQubits+1) );
1587 auto targets = GENERATE_TARGS( numQubits, numTargs );
1588
1589 auto testFunc = [&](Qureg qureg, auto& ref) {
1590
1591 // overwrite caller's setting of initDebugState, since
1592 // sampling requires the outcome probs are normalised
1593 setToRandomState(ref);
1594 setQuregToReference(qureg, ref);
1595
1596 // the output API state...
1597 qindex apiOut = applyMultiQubitMeasurement(qureg, targets.data(), numTargs);
1598
1599 // informs the projector which determines the post-measurement reference
1600 auto apiOutBits = getBits(apiOut, numTargs);
1601 qmatrix projector = getProjector(targets, apiOutBits, numQubits);
1602 applyReferenceOperator(ref, projector);
1603 qreal refProb = getReferenceProbability(ref, targets, apiOutBits);
1604 ref /= (qureg.isDensityMatrix)?
1605 refProb : std::sqrt(refProb);
1606 };
1607
1608 CAPTURE( targets );
1609 SECTION( LABEL_STATEVEC ) { TEST_ON_CACHED_QUREGS(statevecQuregs, statevecRef, testFunc); }
1610 SECTION( LABEL_DENSMATR ) { TEST_ON_CACHED_QUREGS(densmatrQuregs, densmatrRef, testFunc); }
1611 }
1612
1613 /// @todo input validation
1614}
qindex applyMultiQubitMeasurement(Qureg qureg, int *qubits, int numQubits)

◆ TEST_CASE() [7/32]

TEST_CASE ( "applyMultiQubitMeasurementAndGetProb" ,
TEST_CATEGORY  )

Definition at line 1617 of file operations.cpp.

1617 {
1618
1619 PREPARE_TEST( numQubits, statevecQuregs, densmatrQuregs, statevecRef, densmatrRef );
1620
1621 SECTION( LABEL_CORRECTNESS ) {
1622
1623 int numTargs = GENERATE_COPY( range(1,numQubits+1) );
1624 auto targets = GENERATE_TARGS( numQubits, numTargs );
1625
1626 auto testFunc = [&](Qureg qureg, auto& ref) {
1627
1628 // overwrite caller's setting of initDebugState, since
1629 // sampling requires the outcome probs are normalised
1630 setToRandomState(ref);
1631 setQuregToReference(qureg, ref);
1632
1633 // compare the measurement probability...
1634 qreal apiProb = -1;
1635 qindex apiOut = applyMultiQubitMeasurementAndGetProb(qureg, targets.data(), numTargs, &apiProb);
1636 auto apiOutBits = getBits(apiOut, numTargs);
1637 qreal refProb = getReferenceProbability(ref, targets, apiOutBits);
1638 REQUIRE_AGREE( apiProb, refProb );
1639
1640 // and the post-measurement states (caller calls subsequent REQUIRE_AGREE)
1641 qmatrix projector = getProjector(targets, apiOutBits, numQubits);
1642 applyReferenceOperator(ref, projector);
1643 ref /= (qureg.isDensityMatrix)?
1644 refProb : std::sqrt(refProb);
1645 };
1646
1647 CAPTURE( targets );
1648 SECTION( LABEL_STATEVEC ) { TEST_ON_CACHED_QUREGS(statevecQuregs, statevecRef, testFunc); }
1649 SECTION( LABEL_DENSMATR ) { TEST_ON_CACHED_QUREGS(densmatrQuregs, densmatrRef, testFunc); }
1650 }
1651
1652 /// @todo input validation
1653}
qindex applyMultiQubitMeasurementAndGetProb(Qureg qureg, int *qubits, int numQubits, qreal *probability)

◆ TEST_CASE() [8/32]

TEST_CASE ( "applyMultiQubitPhaseFlip" ,
TEST_CATEGORY  )

Definition at line 1335 of file operations.cpp.

1335 {
1336 auto func = static_cast<void(*)(Qureg, int*, int)>(applyMultiQubitPhaseFlip);
1337 testOperation<zero,any,none>(func, VariableSizeMatrices::PF);
1338}
void applyMultiQubitPhaseFlip(Qureg qureg, int *targets, int numTargets)

◆ TEST_CASE() [9/32]

TEST_CASE ( "applyMultiQubitPhaseShift" ,
TEST_CATEGORY  )

Definition at line 1340 of file operations.cpp.

1340 {
1341 auto func = static_cast<void(*)(Qureg, int*, int, qreal)>(applyMultiQubitPhaseShift);
1342 testOperation<zero,any,scalar>(func, VariableSizeParameterisedMatrices::PS);
1343}
void applyMultiQubitPhaseShift(Qureg qureg, int *targets, int numTargets, qreal angle)

◆ TEST_CASE() [10/32]

TEST_CASE ( "applyMultiQubitProjector" ,
TEST_CATEGORY  )

Definition at line 1469 of file operations.cpp.

1469 {
1470
1471 PREPARE_TEST( numQubits, statevecQuregs, densmatrQuregs, statevecRef, densmatrRef );
1472
1473 SECTION( LABEL_CORRECTNESS ) {
1474
1475 int numTargs = GENERATE_COPY( range(1,numQubits+1) );
1476 auto targets = GENERATE_TARGS( numQubits, numTargs );
1477 auto outcomes = getRandomOutcomes(numTargs);
1478
1479 qmatrix projector = getProjector(targets, outcomes, numQubits);
1480
1481 auto testFunc = [&](Qureg qureg, auto& ref) {
1482 applyMultiQubitProjector(qureg, targets.data(), outcomes.data(), numTargs);
1483 applyReferenceOperator(ref, projector);
1484 };
1485
1486 CAPTURE( targets, outcomes );
1487 SECTION( LABEL_STATEVEC ) { TEST_ON_CACHED_QUREGS(statevecQuregs, statevecRef, testFunc); }
1488 SECTION( LABEL_DENSMATR ) { TEST_ON_CACHED_QUREGS(densmatrQuregs, densmatrRef, testFunc); }
1489 }
1490
1491 /// @todo input validation
1492}
void applyMultiQubitProjector(Qureg qureg, int *qubits, int *outcomes, int numQubits)

◆ TEST_CASE() [11/32]

TEST_CASE ( "applyPhaseFlip" ,
TEST_CATEGORY  )

Definition at line 1297 of file operations.cpp.

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

◆ TEST_CASE() [12/32]

TEST_CASE ( "applyPhaseShift" ,
TEST_CATEGORY  )

Definition at line 1299 of file operations.cpp.

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

◆ TEST_CASE() [13/32]

TEST_CASE ( "applyQuantumFourierTransform" ,
TEST_CATEGORY  )

Definition at line 1350 of file operations.cpp.

1350 {
1351
1352 PREPARE_TEST( numQubits, statevecQuregs, densmatrQuregs, statevecRef, densmatrRef );
1353
1354 SECTION( LABEL_CORRECTNESS ) {
1355
1356 int numTargs = GENERATE_COPY( range(1,numQubits+1) );
1357 auto targs = GENERATE_TARGS( numQubits, numTargs );
1358
1359 CAPTURE( targs );
1360
1361 SECTION( LABEL_STATEVEC ) {
1362
1363 auto testFunc = [&](Qureg qureg, qvector& ref) {
1364 applyQuantumFourierTransform(qureg, targs.data(), targs.size());
1365 ref = getDisceteFourierTransform(ref, targs);
1366 };
1367
1368 TEST_ON_CACHED_QUREGS(statevecQuregs, statevecRef, testFunc);
1369 }
1370
1371 SECTION( LABEL_DENSMATR ) {
1372
1373 // prepare a random mixture
1374 auto states = getRandomOrthonormalStateVectors(numQubits, getRandomInt(1,10));
1375 auto probs = getRandomProbabilities(states.size());
1376
1377 auto testFunc = [&](Qureg qureg, qmatrix& ref) {
1378
1379 // overwrite the Qureg debug state set by caller to above mixture
1380 setQuregToReference(qureg, getMixture(states, probs));
1381 applyQuantumFourierTransform(qureg, targs.data(), targs.size());
1382
1383 ref = getZeroMatrix(ref.size());
1384 for (size_t i=0; i<states.size(); i++) {
1385 qvector vec = getDisceteFourierTransform(states[i], targs);
1386 ref += probs[i] * getOuterProduct(vec, vec);
1387 }
1388 };
1389
1390 TEST_ON_CACHED_QUREGS(densmatrQuregs, densmatrRef, testFunc);
1391 }
1392 }
1393
1394 /// @todo input validation
1395}
void applyQuantumFourierTransform(Qureg qureg, int *targets, int numTargets)

◆ TEST_CASE() [14/32]

TEST_CASE ( "applyQubitMeasurement" ,
TEST_CATEGORY  )

Definition at line 1656 of file operations.cpp.

1656 {
1657
1658 PREPARE_TEST( numQubits, statevecQuregs, densmatrQuregs, statevecRef, densmatrRef );
1659
1660 SECTION( LABEL_CORRECTNESS ) {
1661
1662 GENERATE( range(0,10) );
1663 int target = GENERATE_COPY( range(0,numQubits) );
1664
1665 auto testFunc = [&](Qureg qureg, auto& ref) {
1666
1667 // overwrite caller's setting of initDebugState, since
1668 // sampling requires the outcome probs are normalised
1669 setToRandomState(ref);
1670 setQuregToReference(qureg, ref);
1671
1672 // the output API state...
1673 int apiOut = applyQubitMeasurement(qureg, target);
1674
1675 // informs the projector which determines the post-measurement reference
1676 qmatrix projector = getProjector(apiOut);
1677 applyReferenceOperator(ref, {target}, projector);
1678 qreal refProb = getReferenceProbability(ref, {target}, {apiOut});
1679 ref /= (qureg.isDensityMatrix)?
1680 refProb : std::sqrt(refProb);
1681 };
1682
1683 CAPTURE( target );
1684 SECTION( LABEL_STATEVEC ) { TEST_ON_CACHED_QUREGS(statevecQuregs, statevecRef, testFunc); }
1685 SECTION( LABEL_DENSMATR ) { TEST_ON_CACHED_QUREGS(densmatrQuregs, densmatrRef, testFunc); }
1686 }
1687
1688 /// @todo input validation
1689}
int applyQubitMeasurement(Qureg qureg, int target)

◆ TEST_CASE() [15/32]

TEST_CASE ( "applyQubitMeasurementAndGetProb" ,
TEST_CATEGORY  )

Definition at line 1692 of file operations.cpp.

1692 {
1693
1694 PREPARE_TEST( numQubits, statevecQuregs, densmatrQuregs, statevecRef, densmatrRef );
1695
1696 SECTION( LABEL_CORRECTNESS ) {
1697
1698 GENERATE( range(0,10) );
1699 int target = GENERATE_COPY( range(0,numQubits) );
1700
1701 auto testFunc = [&](Qureg qureg, auto& ref) {
1702
1703 // overwrite caller's setting of initDebugState, since
1704 // sampling requires the outcome probs are normalised
1705 setToRandomState(ref);
1706 setQuregToReference(qureg, ref);
1707
1708 // compare the measurement probability...
1709 qreal apiProb = -1;
1710 int apiOut = applyQubitMeasurementAndGetProb(qureg, target, &apiProb);
1711 qreal refProb = getReferenceProbability(ref, {target}, {apiOut});
1712 REQUIRE_AGREE( apiProb, refProb );
1713
1714 // and the post-measurement states (caller calls subsequent REQUIRE_AGREE)
1715 qmatrix projector = getProjector(apiOut);
1716 applyReferenceOperator(ref, {target}, projector);
1717 ref /= (qureg.isDensityMatrix)?
1718 refProb : std::sqrt(refProb);
1719 };
1720
1721 CAPTURE( target );
1722 SECTION( LABEL_STATEVEC ) { TEST_ON_CACHED_QUREGS(statevecQuregs, statevecRef, testFunc); }
1723 SECTION( LABEL_DENSMATR ) { TEST_ON_CACHED_QUREGS(densmatrQuregs, densmatrRef, testFunc); }
1724 }
1725
1726 /// @todo input validation
1727}
int applyQubitMeasurementAndGetProb(Qureg qureg, int target, qreal *probability)

◆ TEST_CASE() [16/32]

TEST_CASE ( "applyQubitProjector" ,
TEST_CATEGORY  )

Definition at line 1443 of file operations.cpp.

1443 {
1444
1445 PREPARE_TEST( numQubits, statevecQuregs, densmatrQuregs, statevecRef, densmatrRef );
1446
1447 SECTION( LABEL_CORRECTNESS ) {
1448
1449 GENERATE( range(0,10) );
1450 int target = GENERATE_COPY( range(0,numQubits) );
1451 int outcome = GENERATE( 0, 1 );
1452
1453 qmatrix projector = getProjector(outcome);
1454
1455 auto testFunc = [&](Qureg qureg, auto& ref) {
1456 applyQubitProjector(qureg, target, outcome);
1457 applyReferenceOperator(ref, {target}, projector);
1458 };
1459
1460 CAPTURE( target, outcome );
1461 SECTION( LABEL_STATEVEC ) { TEST_ON_CACHED_QUREGS(statevecQuregs, statevecRef, testFunc); }
1462 SECTION( LABEL_DENSMATR ) { TEST_ON_CACHED_QUREGS(densmatrQuregs, densmatrRef, testFunc); }
1463 }
1464
1465 /// @todo input validation
1466}
void applyQubitProjector(Qureg qureg, int target, int outcome)

◆ TEST_CASE() [17/32]

TEST_CASE ( "applyTwoQubitPhaseFlip" ,
TEST_CATEGORY  )

Definition at line 1298 of file operations.cpp.

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

◆ TEST_CASE() [18/32]

TEST_CASE ( "applyTwoQubitPhaseShift" ,
TEST_CATEGORY  )

Definition at line 1300 of file operations.cpp.

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

◆ TEST_CASE() [19/32]

TEST_CASE ( "multiplyCompMatr" ,
TEST_CATEGORY  )

Definition at line 1310 of file operations.cpp.

1310 {
1311 auto func = static_cast<void(*)(Qureg, int*, int, CompMatr)>(multiplyCompMatr);
1312 testOperation<zero,any,compmatr>(func, nullptr, true);
1313}
void multiplyCompMatr(Qureg qureg, int *targets, int numTargets, CompMatr matr)

◆ TEST_CASE() [20/32]

TEST_CASE ( "multiplyCompMatr1" ,
TEST_CATEGORY  )

Definition at line 1293 of file operations.cpp.

1293{ testOperation<zero,one,compmatr>(multiplyCompMatr1, nullptr, true); }
void multiplyCompMatr1(Qureg qureg, int target, CompMatr1 matrix)

◆ TEST_CASE() [21/32]

TEST_CASE ( "multiplyCompMatr2" ,
TEST_CATEGORY  )

Definition at line 1294 of file operations.cpp.

1294{ testOperation<zero,two,compmatr>(multiplyCompMatr2, nullptr, true); }
void multiplyCompMatr2(Qureg qureg, int target1, int target2, CompMatr2 matr)

◆ TEST_CASE() [22/32]

TEST_CASE ( "multiplyDiagMatr" ,
TEST_CATEGORY  )

Definition at line 1315 of file operations.cpp.

1315 {
1316 auto func = static_cast<void(*)(Qureg, int*, int, DiagMatr)>(multiplyDiagMatr);
1317 testOperation<zero,any,diagmatr>(func, nullptr, true);
1318}
void multiplyDiagMatr(Qureg qureg, int *targets, int numTargets, DiagMatr matrix)

◆ TEST_CASE() [23/32]

TEST_CASE ( "multiplyDiagMatr1" ,
TEST_CATEGORY  )

Definition at line 1295 of file operations.cpp.

1295{ testOperation<zero,one,diagmatr>(multiplyDiagMatr1, nullptr, true); }
void multiplyDiagMatr1(Qureg qureg, int target, DiagMatr1 matr)

◆ TEST_CASE() [24/32]

TEST_CASE ( "multiplyDiagMatr2" ,
TEST_CATEGORY  )

Definition at line 1296 of file operations.cpp.

1296{ testOperation<zero,two,diagmatr>(multiplyDiagMatr2, nullptr, true); }
void multiplyDiagMatr2(Qureg qureg, int target1, int target2, DiagMatr2 matr)

◆ TEST_CASE() [25/32]

TEST_CASE ( "multiplyDiagMatrPower" ,
TEST_CATEGORY  )

Definition at line 1320 of file operations.cpp.

1320 {
1321 auto func = static_cast<void(*)(Qureg, int*, int, DiagMatr, qcomp)>(multiplyDiagMatrPower);
1322 testOperation<zero,any,diagpower>(func, nullptr, true);
1323}
void multiplyDiagMatrPower(Qureg qureg, int *targets, int numTargets, DiagMatr matrix, qcomp exponent)

◆ TEST_CASE() [26/32]

TEST_CASE ( "multiplyFullStateDiagMatr" ,
TEST_CATEGORY LABEL_MIXED_DEPLOY_TAG )

Definition at line 1730 of file operations.cpp.

1730 {
1731
1732 PREPARE_TEST( numQubits, cachedSV, cachedDM, refSV, refDM );
1733
1734 auto cachedMatrs = getCachedFullStateDiagMatrs();
1735
1736 SECTION( LABEL_CORRECTNESS ) {
1737
1738 qmatrix refMatr = getRandomDiagonalMatrix(getPow2(numQubits));
1739 auto apiFunc = multiplyFullStateDiagMatr;
1740
1741 GENERATE( range(0, TEST_NUM_MIXED_DEPLOYMENT_REPETITIONS) );
1742
1743 SECTION( LABEL_STATEVEC ) {
1744
1745 auto refFunc = [&] (qvector& state, qmatrix matr) { multiplyReferenceOperator(state, matr); };
1746
1747 TEST_ON_CACHED_QUREG_AND_MATRIX( cachedSV, cachedMatrs, apiFunc, refSV, refMatr, refFunc);
1748 }
1749
1750 SECTION( LABEL_DENSMATR ) {
1751
1752 auto refFunc = [&] (qmatrix& state, qmatrix matr) { multiplyReferenceOperator(state, matr); };
1753
1754 TEST_ON_CACHED_QUREG_AND_MATRIX( cachedDM, cachedMatrs, apiFunc, refDM, refMatr, refFunc);
1755 }
1756 }
1757
1758 /// @todo input validation
1759}
void multiplyFullStateDiagMatr(Qureg qureg, FullStateDiagMatr matrix)

◆ TEST_CASE() [27/32]

TEST_CASE ( "multiplyFullStateDiagMatrPower" ,
TEST_CATEGORY LABEL_MIXED_DEPLOY_TAG )

Definition at line 1762 of file operations.cpp.

1762 {
1763
1764 PREPARE_TEST( numQubits, cachedSV, cachedDM, refSV, refDM );
1765
1766 auto cachedMatrs = getCachedFullStateDiagMatrs();
1767
1768 SECTION( LABEL_CORRECTNESS ) {
1769
1770 qmatrix refMatr = getRandomDiagonalMatrix(getPow2(numQubits));
1771 qcomp exponent = getRandomComplex();
1772
1773 auto apiFunc = [&](Qureg qureg, FullStateDiagMatr matr) {
1774 return multiplyFullStateDiagMatrPower(qureg, matr, exponent);
1775 };
1776
1777 CAPTURE( exponent );
1778
1779 GENERATE( range(0, TEST_NUM_MIXED_DEPLOYMENT_REPETITIONS) );
1780
1781 SECTION( LABEL_STATEVEC ) {
1782
1783 auto refFunc = [&] (qvector& state, qmatrix matr) {
1784 matr = getPowerOfDiagonalMatrix(matr, exponent);
1785 multiplyReferenceOperator(state, matr);
1786 };
1787
1788 TEST_ON_CACHED_QUREG_AND_MATRIX( cachedSV, cachedMatrs, apiFunc, refSV, refMatr, refFunc);
1789 }
1790
1791 SECTION( LABEL_DENSMATR ) {
1792
1793 auto refFunc = [&] (qmatrix& state, qmatrix matr) {
1794 matr = getPowerOfDiagonalMatrix(matr, exponent);
1795 multiplyReferenceOperator(state, matr);
1796 };
1797
1798 TEST_ON_CACHED_QUREG_AND_MATRIX( cachedDM, cachedMatrs, apiFunc, refDM, refMatr, refFunc);
1799 }
1800 }
1801
1802 /// @todo input validation
1803}
void multiplyFullStateDiagMatrPower(Qureg qureg, FullStateDiagMatr matrix, qcomp exponent)

◆ TEST_CASE() [28/32]

TEST_CASE ( "multiplyMultiQubitNot" ,
TEST_CATEGORY  )

Definition at line 1325 of file operations.cpp.

1325 {
1326 auto func = static_cast<void(*)(Qureg, int*, int)>(multiplyMultiQubitNot);
1327 testOperation<zero,any,none>(func, VariableSizeMatrices::X, true);
1328}
void multiplyMultiQubitNot(Qureg qureg, int *targets, int numTargets)

◆ TEST_CASE() [29/32]

TEST_CASE ( "multiplyPauliGadget" ,
TEST_CATEGORY  )

Definition at line 1292 of file operations.cpp.

1292{ testOperation<zero,any,pauligad>(multiplyPauliGadget, nullptr, true); }
void multiplyPauliGadget(Qureg qureg, PauliStr str, qreal angle)

◆ TEST_CASE() [30/32]

TEST_CASE ( "multiplyPauliStr" ,
TEST_CATEGORY  )

Definition at line 1291 of file operations.cpp.

1291{ testOperation<zero,any,paulistr>(multiplyPauliStr, nullptr, true); }
void multiplyPauliStr(Qureg qureg, PauliStr str)

◆ TEST_CASE() [31/32]

TEST_CASE ( "multiplyPauliStrSum" ,
TEST_CATEGORY LABEL_MIXED_DEPLOY_TAG )

Definition at line 1893 of file operations.cpp.

1893 {
1894
1895 PREPARE_TEST( numQubits, statevecQuregs, densmatrQuregs, statevecRef, densmatrRef );
1896
1897 SECTION( LABEL_CORRECTNESS ) {
1898
1899 int numQubits = getNumCachedQubits();
1900 int numTerms = GENERATE_COPY( 1, 2, 10 );
1901
1902 PauliStrSum sum = createRandomPauliStrSum(numQubits, numTerms);
1903
1904 auto testFunc = [&](Qureg qureg, auto& ref) {
1905
1906 // must use (and ergo make) an identically-deployed workspace
1907 Qureg workspace = createCloneQureg(qureg);
1908 multiplyPauliStrSum(qureg, sum, workspace);
1909 destroyQureg(workspace);
1910
1911 ref = getMatrix(sum, numQubits) * ref;
1912 };
1913
1914 CAPTURE( numTerms );
1915 SECTION( LABEL_STATEVEC ) { TEST_ON_CACHED_QUREGS(statevecQuregs, statevecRef, testFunc); }
1916 SECTION( LABEL_DENSMATR ) { TEST_ON_CACHED_QUREGS(densmatrQuregs, densmatrRef, testFunc); }
1917 }
1918
1919 /// @todo input validation
1920}
void multiplyPauliStrSum(Qureg qureg, PauliStrSum sum, Qureg workspace)
Qureg createCloneQureg(Qureg qureg)
Definition qureg.cpp:315
void destroyQureg(Qureg qureg)
Definition qureg.cpp:330

◆ TEST_CASE() [32/32]

TEST_CASE ( "multiplyPhaseGadget" ,
TEST_CATEGORY  )

Definition at line 1330 of file operations.cpp.

1330 {
1331 auto func = static_cast<void(*)(Qureg, int*, int, qreal)>(multiplyPhaseGadget);
1332 testOperation<zero,any,scalar>(func, VariableSizeParameterisedMatrices::Z, true);
1333}
void multiplyPhaseGadget(Qureg qureg, int *targets, int numTargets, qreal angle)