|
1598 | 1598 | )] |
1599 | 1599 |
|
1600 | 1600 |
|
| 1601 | +(*Unit tests for (sparse and dense) Housholder decomposition*) |
| 1602 | + |
| 1603 | + |
| 1604 | +(*Check Methods based on Householder decomposition*) |
| 1605 | + |
| 1606 | + |
| 1607 | +checkDenseHouseholder[v_]:=Module[{st,iso},( |
| 1608 | +st=DenseHouseholderDec[v]; |
| 1609 | +iso=NCreateOperationFromGateList[st]; |
| 1610 | +isIdentityUpToPhase[N[ConjugateTranspose[v].iso]] |
| 1611 | +) |
| 1612 | +] |
| 1613 | +checkSparseHouseholder[v_]:=Module[{st,iso},( |
| 1614 | +st=SparseHouseholderDec[v]; |
| 1615 | +iso=NCreateOperationFromGateList[st]; |
| 1616 | +isIdentityUpToPhase[N[ConjugateTranspose[v].iso]] |
| 1617 | +) |
| 1618 | +] |
| 1619 | + |
| 1620 | + |
| 1621 | +(*Tests for (sparse and dense) Householder decomposition*) |
| 1622 | + |
| 1623 | + |
| 1624 | +TestDenseHouseholder:=Module[{error},( |
| 1625 | +error=0; |
| 1626 | +If[Quiet[Check[checkDenseHouseholder[PickRandomIsometry[2,2^4]],error=1;False]]&& |
| 1627 | +Quiet[Check[checkDenseHouseholder[PickRandomIsometry[1,2^3]],error=2;False]]&& |
| 1628 | +Quiet[Check[checkDenseHouseholder[randPermutMat[2^1,2^2]],error=3;False]]&& |
| 1629 | +Quiet[Check[checkDenseHouseholder[N[randPermutMat[2^2,2^4]]],error=4;False]]&& |
| 1630 | +Quiet[Check[checkDenseHouseholder[PickRandomIsometry[1,2^2]],error=5;False]]&& |
| 1631 | +Quiet[Check[checkDenseHouseholder[PickRandomIsometry[2^3,2^3]],error=6;False]], |
| 1632 | +True, |
| 1633 | +Print["Error in DenseHouseholderDec with error message code ",error];False |
| 1634 | +] |
| 1635 | +)] |
| 1636 | + |
| 1637 | + |
| 1638 | +TestSparseHouseholder:=Module[{error},( |
| 1639 | +error=0; |
| 1640 | +If[Quiet[Check[checkSparseHouseholder[PickRandomIsometry[2,2^4]],error=1;False]]&& |
| 1641 | +Quiet[Check[checkSparseHouseholder[PickRandomIsometry[1,2^3]],error=2;False]]&& |
| 1642 | +Quiet[Check[checkSparseHouseholder[randPermutMat[2^1,2^2]],error=3;False]]&& |
| 1643 | +Quiet[Check[checkSparseHouseholder[N[randPermutMat[2^2,2^4]]],error=4;False]]&& |
| 1644 | +Quiet[Check[checkSparseHouseholder[PickRandomSparseIsometry[1,2^2]],error=5;False]]&& |
| 1645 | +Quiet[Check[checkSparseHouseholder[PickRandomSparseIsometry[2^3,2^3]],error=6;False]], |
| 1646 | +True, |
| 1647 | +Print["Error in SparseHouseholderDec with error message code ",error];False |
| 1648 | +] |
| 1649 | +)] |
| 1650 | + |
| 1651 | + |
| 1652 | +(*All tests for Housholder decomposition*) |
| 1653 | + |
| 1654 | + |
| 1655 | +testHouseholderAll := Module[{},( |
| 1656 | +If[TestDenseHouseholder&&TestSparseHouseholder, |
| 1657 | +Print["All tests for (dense and sparse) Householder decomposition pass."],, |
| 1658 | + Print["testHouseholderAll neither returned True nor False"] |
| 1659 | +] |
| 1660 | +)] |
| 1661 | + |
| 1662 | + |
1601 | 1663 | (*Unit tests for state preparaion (Plesch-Brukner decomposition)*) |
1602 | 1664 |
|
1603 | 1665 |
|
|
1634 | 1696 |
|
1635 | 1697 | testStatePreparationAll := Module[{},( |
1636 | 1698 | If[TestStatePreparation, |
1637 | | -Print["All tests for State preparation pass."],, |
| 1699 | +Print["All tests for state preparation pass."],, |
1638 | 1700 | Print["testStatePreparationAll neither returned True nor False"] |
1639 | 1701 | ] |
1640 | 1702 | )] |
1641 | 1703 |
|
1642 | 1704 |
|
| 1705 | +(*Unit tests for sparse state preparaion*) |
| 1706 | + |
| 1707 | + |
| 1708 | +(*Checks for sparse state preparation*) |
| 1709 | + |
| 1710 | + |
| 1711 | +checkSparseStatePreparation[psi_]:=Module[{st,iso},( |
| 1712 | +st=SparseStatePreparation[psi]; |
| 1713 | +iso=NCreateOperationFromGateList[st]; |
| 1714 | +isIdentityUpToPhase[N[ConjugateTranspose[psi].iso]] |
| 1715 | +) |
| 1716 | +] |
| 1717 | + |
| 1718 | + |
| 1719 | +(*Tests for sparse state preparation*) |
| 1720 | + |
| 1721 | + |
| 1722 | +TestSparseStatePreparation:=Module[{error},( |
| 1723 | +error=0; |
| 1724 | +If[Quiet[Check[checkSparseStatePreparation[PickRandomPsi[2^4]],error=1;False]]&& |
| 1725 | +Quiet[Check[checkSparseStatePreparation[PickRandomSparsePsi[2^4,2^3]],error=2;False]]&& |
| 1726 | +Quiet[Check[checkSparseStatePreparation[PickRandomPsi[2^4]],error=3;False]]&& |
| 1727 | +Quiet[Check[checkSparseStatePreparation[N[randPermutMat[1,8]]],error=1;False]]&& |
| 1728 | +Quiet[Check[checkSparseStatePreparation[N[randPermutMat[1,8]]],error=2;False]]&& |
| 1729 | +Quiet[Check[checkSparseStatePreparation[N[randPermutMat[1,8]]],error=3;False]] |
| 1730 | +, |
| 1731 | +True, |
| 1732 | +Print["Error in SparseStatePreparation with error message code ",error];False |
| 1733 | +] |
| 1734 | +)] |
| 1735 | + |
| 1736 | + |
| 1737 | +(*All tests for sparse state preparation*) |
| 1738 | + |
| 1739 | + |
| 1740 | +testSparseStatePreparationAll := Module[{},( |
| 1741 | +If[TestSparseStatePreparation, |
| 1742 | +Print["All tests for sparse state preparation pass."],, |
| 1743 | + Print["testSparseStatePreparationAll neither returned True nor False"] |
| 1744 | +] |
| 1745 | +)] |
| 1746 | + |
| 1747 | + |
| 1748 | +(*Unit tests for CNOT \[TwoWayRule] XX transformation*) |
| 1749 | + |
| 1750 | + |
| 1751 | +(*Checks for CNOT \[TwoWayRule] XX transformation*) |
| 1752 | + |
| 1753 | + |
1643 | 1754 | CheckCNOTtoXX[v_]:=Module[{st,st2,iso,ch}, |
1644 | 1755 | st=DecIsometryGeneric[v];st2=CNOTRotationsToXXRGates[st]; |
1645 | 1756 | iso=CreateOperationFromGateList[st2,Log[2,Dimensions[v][[1]]]];ch=CT[v].iso; |
|
1651 | 1762 | iso=CreateOperationFromGateList[st3,Log[2,Dimensions[v][[1]]]];ch=CT[v].iso; |
1652 | 1763 | Chop[ch/ch[[1,1]]-IdentityMatrix[Dimensions[iso][[2]]],10^-6]==0*IdentityMatrix[Dimensions[iso][[2]]]] |
1653 | 1764 |
|
| 1765 | + |
| 1766 | +(*Tests for CNOT \[TwoWayRule] XX transformation*) |
| 1767 | + |
| 1768 | + |
1654 | 1769 | TestCNOTtoXX:=Module[{error=0},If[Quiet[Check[CheckCNOTtoXX[PickRandomIsometry[2^2,2^2]],error=1;False]]&& |
1655 | 1770 | Quiet[Check[CheckCNOTtoXX[PickRandomIsometry[2^2,2^3]],error=2;False]]&& |
1656 | 1771 | Quiet[Check[CheckCNOTtoXX[PickRandomIsometry[2^2,2^4]],error=3;False]]&& |
|
1675 | 1790 | Print["Error in CheckXXtoCNOT with error message code ",error];False |
1676 | 1791 | ]] |
1677 | 1792 |
|
| 1793 | + |
| 1794 | +(*All tests for CNOT \[TwoWayRule] XX transformation*) |
| 1795 | + |
| 1796 | + |
1678 | 1797 | testXXCNOTAll := Module[{},( |
1679 | 1798 | If[TestCNOTtoXX&&TestXXtoCNOT, |
1680 | 1799 | Print["All tests for converting to and from XX gates pass."],, |
|
1752 | 1871 |
|
1753 | 1872 |
|
1754 | 1873 | (*Run all tests*) |
1755 | | -runAllTests:=Module[{},(testAllBasicMethods;testUCGs;testAllDiagGateMethods;testIsoSmall;testCCDec;testDec2Qubit;testDecSingleQubit;testQSDAll;testQSD;testStatePreparationAll;testAllMCGMethods;testKnill;testIsometryDecompositions;testStinespring;testPOVM;testXXCNOTAll;testChannelDecompositions;testInstrumentDecompositions)] |
| 1874 | +runAllTests:=Module[{},(testAllBasicMethods;testUCGs;testAllDiagGateMethods;testIsoSmall;testCCDec;testDec2Qubit;testDecSingleQubit;testQSDAll;testQSD;testStatePreparationAll;testSparseStatePreparationAll;testAllMCGMethods;testKnill;testHouseholderAll;testIsometryDecompositions;testStinespring;testPOVM;testXXCNOTAll;testChannelDecompositions;testInstrumentDecompositions)] |
1756 | 1875 |
|
1757 | 1876 |
|
1758 | 1877 | Timing[runAllTests] |
|
0 commit comments