pyqrack-complex128 1.78.3__py3-none-macosx_14_0_arm64.whl → 1.82.0__py3-none-macosx_14_0_arm64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of pyqrack-complex128 might be problematic. Click here for more details.
- pyqrack/__init__.py +0 -1
- pyqrack/qrack_ace_backend.py +16 -46
- pyqrack/qrack_circuit.py +2 -6
- pyqrack/qrack_neuron.py +67 -36
- pyqrack/qrack_neuron_torch_layer.py +132 -235
- pyqrack/qrack_simulator.py +106 -189
- pyqrack/qrack_system/qrack_lib/{libqrack_pinvoke.9.34.5.dylib → libqrack_pinvoke.10.0.0.dylib} +0 -0
- pyqrack/qrack_system/qrack_lib/libqrack_pinvoke.dylib +0 -0
- pyqrack/qrack_system/qrack_system.py +68 -59
- pyqrack/stats/load_quantized_data.py +1 -3
- pyqrack/stats/quantize_by_range.py +2 -6
- {pyqrack_complex128-1.78.3.dist-info → pyqrack_complex128-1.82.0.dist-info}/METADATA +3 -1
- pyqrack_complex128-1.82.0.dist-info/RECORD +23 -0
- pyqrack_complex128-1.78.3.dist-info/RECORD +0 -23
- {pyqrack_complex128-1.78.3.dist-info → pyqrack_complex128-1.82.0.dist-info}/LICENSE +0 -0
- {pyqrack_complex128-1.78.3.dist-info → pyqrack_complex128-1.82.0.dist-info}/WHEEL +0 -0
- {pyqrack_complex128-1.78.3.dist-info → pyqrack_complex128-1.82.0.dist-info}/top_level.txt +0 -0
pyqrack/qrack_simulator.py
CHANGED
|
@@ -57,9 +57,7 @@ class QrackSimulator:
|
|
|
57
57
|
isPaged=True,
|
|
58
58
|
isCpuGpuHybrid=True,
|
|
59
59
|
isOpenCL=True,
|
|
60
|
-
isHostPointer=(
|
|
61
|
-
True if os.environ.get("PYQRACK_HOST_POINTER_DEFAULT_ON") else False
|
|
62
|
-
),
|
|
60
|
+
isHostPointer=(True if os.environ.get("PYQRACK_HOST_POINTER_DEFAULT_ON") else False),
|
|
63
61
|
isSparse=False,
|
|
64
62
|
noise=0,
|
|
65
63
|
pyzxCircuit=None,
|
|
@@ -79,7 +77,6 @@ class QrackSimulator:
|
|
|
79
77
|
"Cannot clone a QrackSimulator and specify its qubit length at the same time, in QrackSimulator constructor!"
|
|
80
78
|
)
|
|
81
79
|
|
|
82
|
-
self.is_tensor_network = isTensorNetwork
|
|
83
80
|
self.is_pure_stabilizer = False
|
|
84
81
|
|
|
85
82
|
if cloneSid > -1:
|
|
@@ -100,7 +97,7 @@ class QrackSimulator:
|
|
|
100
97
|
isCpuGpuHybrid,
|
|
101
98
|
isOpenCL,
|
|
102
99
|
isHostPointer,
|
|
103
|
-
isSparse
|
|
100
|
+
isSparse,
|
|
104
101
|
)
|
|
105
102
|
|
|
106
103
|
self._throw_if_error()
|
|
@@ -593,7 +590,11 @@ class QrackSimulator:
|
|
|
593
590
|
"2x2 matrix 'm' in QrackSimulator.mcmtrx() must contain at least 4 elements."
|
|
594
591
|
)
|
|
595
592
|
Qrack.qrack_lib.MCMtrx(
|
|
596
|
-
self.sid,
|
|
593
|
+
self.sid,
|
|
594
|
+
len(c),
|
|
595
|
+
QrackSimulator._ulonglong_byref(c),
|
|
596
|
+
QrackSimulator._complex_byref(m),
|
|
597
|
+
q,
|
|
597
598
|
)
|
|
598
599
|
self._throw_if_error()
|
|
599
600
|
|
|
@@ -771,7 +772,11 @@ class QrackSimulator:
|
|
|
771
772
|
"2x2 matrix 'm' in QrackSimulator.macmtrx() must contain at least 4 elements."
|
|
772
773
|
)
|
|
773
774
|
Qrack.qrack_lib.MACMtrx(
|
|
774
|
-
self.sid,
|
|
775
|
+
self.sid,
|
|
776
|
+
len(c),
|
|
777
|
+
QrackSimulator._ulonglong_byref(c),
|
|
778
|
+
QrackSimulator._complex_byref(m),
|
|
779
|
+
q,
|
|
775
780
|
)
|
|
776
781
|
self._throw_if_error()
|
|
777
782
|
|
|
@@ -796,7 +801,12 @@ class QrackSimulator:
|
|
|
796
801
|
"2x2 matrix 'm' in QrackSimulator.ucmtrx() must contain at least 4 elements."
|
|
797
802
|
)
|
|
798
803
|
Qrack.qrack_lib.UCMtrx(
|
|
799
|
-
self.sid,
|
|
804
|
+
self.sid,
|
|
805
|
+
len(c),
|
|
806
|
+
QrackSimulator._ulonglong_byref(c),
|
|
807
|
+
QrackSimulator._complex_byref(m),
|
|
808
|
+
q,
|
|
809
|
+
p,
|
|
800
810
|
)
|
|
801
811
|
self._throw_if_error()
|
|
802
812
|
|
|
@@ -820,7 +830,11 @@ class QrackSimulator:
|
|
|
820
830
|
"Multiplex matrix 'm' in QrackSimulator.multiplex1_mtrx() must contain at least (4 * 2 ** len(c)) elements."
|
|
821
831
|
)
|
|
822
832
|
Qrack.qrack_lib.Multiplex1Mtrx(
|
|
823
|
-
self.sid,
|
|
833
|
+
self.sid,
|
|
834
|
+
len(c),
|
|
835
|
+
QrackSimulator._ulonglong_byref(c),
|
|
836
|
+
q,
|
|
837
|
+
QrackSimulator._complex_byref(m),
|
|
824
838
|
)
|
|
825
839
|
self._throw_if_error()
|
|
826
840
|
|
|
@@ -978,9 +992,7 @@ class QrackSimulator:
|
|
|
978
992
|
Raises:
|
|
979
993
|
RuntimeError: QrackSimulator raised an exception.
|
|
980
994
|
"""
|
|
981
|
-
Qrack.qrack_lib.FSim(
|
|
982
|
-
self.sid, ctypes.c_double(th), ctypes.c_double(ph), qi1, qi2
|
|
983
|
-
)
|
|
995
|
+
Qrack.qrack_lib.FSim(self.sid, ctypes.c_double(th), ctypes.c_double(ph), qi1, qi2)
|
|
984
996
|
self._throw_if_error()
|
|
985
997
|
|
|
986
998
|
def cswap(self, c, qi1, qi2):
|
|
@@ -1294,15 +1306,11 @@ class QrackSimulator:
|
|
|
1294
1306
|
|
|
1295
1307
|
Raises:
|
|
1296
1308
|
RuntimeError: QrackSimulator raised an exception.
|
|
1297
|
-
RuntimeError:
|
|
1309
|
+
RuntimeError: QrackStabilizer cannot mul()! (Create a QrackSimulator instead.)
|
|
1298
1310
|
"""
|
|
1299
|
-
if self.is_tensor_network:
|
|
1300
|
-
raise RuntimeError(
|
|
1301
|
-
"QrackSimulator with isTensorNetwork=True option cannot mul()! (Turn off just this option, in the constructor.)"
|
|
1302
|
-
)
|
|
1303
1311
|
if self.is_pure_stabilizer:
|
|
1304
1312
|
raise RuntimeError(
|
|
1305
|
-
"QrackStabilizer cannot mul()! (Create a QrackSimulator instead
|
|
1313
|
+
"QrackStabilizer cannot mul()! (Create a QrackSimulator instead.)"
|
|
1306
1314
|
)
|
|
1307
1315
|
|
|
1308
1316
|
if len(q) != len(o):
|
|
@@ -1333,15 +1341,11 @@ class QrackSimulator:
|
|
|
1333
1341
|
|
|
1334
1342
|
Raises:
|
|
1335
1343
|
RuntimeError: QrackSimulator raised an exception.
|
|
1336
|
-
RuntimeError:
|
|
1344
|
+
RuntimeError: QrackStabilizer cannot div()! (Create a QrackSimulator instead.)
|
|
1337
1345
|
"""
|
|
1338
|
-
if self.is_tensor_network:
|
|
1339
|
-
raise RuntimeError(
|
|
1340
|
-
"QrackSimulator with isTensorNetwork=True option cannot div()! (Turn off just this option, in the constructor.)"
|
|
1341
|
-
)
|
|
1342
1346
|
if self.is_pure_stabilizer:
|
|
1343
1347
|
raise RuntimeError(
|
|
1344
|
-
"QrackStabilizer cannot div()! (Create a QrackSimulator instead
|
|
1348
|
+
"QrackStabilizer cannot div()! (Create a QrackSimulator instead.)"
|
|
1345
1349
|
)
|
|
1346
1350
|
|
|
1347
1351
|
if len(q) != len(o):
|
|
@@ -1430,15 +1434,11 @@ class QrackSimulator:
|
|
|
1430
1434
|
|
|
1431
1435
|
Raises:
|
|
1432
1436
|
RuntimeError: QrackSimulator raised an exception.
|
|
1433
|
-
RuntimeError:
|
|
1437
|
+
RuntimeError: QrackStabilizer cannot pown()! (Create a QrackSimulator instead.)
|
|
1434
1438
|
"""
|
|
1435
|
-
if self.is_tensor_network:
|
|
1436
|
-
raise RuntimeError(
|
|
1437
|
-
"QrackSimulator with isTensorNetwork=True option cannot pown()! (Turn off just this option, in the constructor.)"
|
|
1438
|
-
)
|
|
1439
1439
|
if self.is_pure_stabilizer:
|
|
1440
1440
|
raise RuntimeError(
|
|
1441
|
-
"QrackStabilizer cannot pown()! (Create a QrackSimulator instead
|
|
1441
|
+
"QrackStabilizer cannot pown()! (Create a QrackSimulator instead.)"
|
|
1442
1442
|
)
|
|
1443
1443
|
|
|
1444
1444
|
if len(q) != len(o):
|
|
@@ -1523,15 +1523,11 @@ class QrackSimulator:
|
|
|
1523
1523
|
|
|
1524
1524
|
Raises:
|
|
1525
1525
|
RuntimeError: QrackSimulator raised an exception.
|
|
1526
|
-
RuntimeError:
|
|
1526
|
+
RuntimeError: QrackStabilizer cannot mcmul()! (Create a QrackSimulator instead.)
|
|
1527
1527
|
"""
|
|
1528
|
-
if self.is_tensor_network:
|
|
1529
|
-
raise RuntimeError(
|
|
1530
|
-
"QrackSimulator with isTensorNetwork=True option cannot mcmul()! (Turn off just this option, in the constructor.)"
|
|
1531
|
-
)
|
|
1532
1528
|
if self.is_pure_stabilizer:
|
|
1533
1529
|
raise RuntimeError(
|
|
1534
|
-
"QrackStabilizer cannot mcmul()! (Create a QrackSimulator instead
|
|
1530
|
+
"QrackStabilizer cannot mcmul()! (Create a QrackSimulator instead.)"
|
|
1535
1531
|
)
|
|
1536
1532
|
|
|
1537
1533
|
if len(q) != len(o):
|
|
@@ -1565,15 +1561,11 @@ class QrackSimulator:
|
|
|
1565
1561
|
|
|
1566
1562
|
Raises:
|
|
1567
1563
|
RuntimeError: QrackSimulator raised an exception.
|
|
1568
|
-
RuntimeError:
|
|
1564
|
+
RuntimeError: QrackStabilizer cannot mcdiv()! (Create a QrackSimulator instead.)
|
|
1569
1565
|
"""
|
|
1570
|
-
if self.is_tensor_network:
|
|
1571
|
-
raise RuntimeError(
|
|
1572
|
-
"QrackSimulator with isTensorNetwork=True option cannot mcdiv()! (Turn off just this option, in the constructor.)"
|
|
1573
|
-
)
|
|
1574
1566
|
if self.is_pure_stabilizer:
|
|
1575
1567
|
raise RuntimeError(
|
|
1576
|
-
"QrackStabilizer cannot mcdiv()! (Create a QrackSimulator instead
|
|
1568
|
+
"QrackStabilizer cannot mcdiv()! (Create a QrackSimulator instead.)"
|
|
1577
1569
|
)
|
|
1578
1570
|
|
|
1579
1571
|
if len(q) != len(o):
|
|
@@ -1673,15 +1665,11 @@ class QrackSimulator:
|
|
|
1673
1665
|
|
|
1674
1666
|
Raises:
|
|
1675
1667
|
RuntimeError: QrackSimulator raised an exception.
|
|
1676
|
-
RuntimeError:
|
|
1668
|
+
RuntimeError: QrackStabilizer cannot mcpown()! (Create a QrackSimulator instead.)
|
|
1677
1669
|
"""
|
|
1678
|
-
if self.is_tensor_network:
|
|
1679
|
-
raise RuntimeError(
|
|
1680
|
-
"QrackSimulator with isTensorNetwork=True option cannot mcpown()! (Turn off just this option, in the constructor.)"
|
|
1681
|
-
)
|
|
1682
1670
|
if self.is_pure_stabilizer:
|
|
1683
1671
|
raise RuntimeError(
|
|
1684
|
-
"QrackStabilizer cannot mcpown()! (Create a QrackSimulator instead
|
|
1672
|
+
"QrackStabilizer cannot mcpown()! (Create a QrackSimulator instead.)"
|
|
1685
1673
|
)
|
|
1686
1674
|
|
|
1687
1675
|
if len(q) != len(o):
|
|
@@ -1714,15 +1702,11 @@ class QrackSimulator:
|
|
|
1714
1702
|
|
|
1715
1703
|
Raises:
|
|
1716
1704
|
RuntimeError: QrackSimulator raised an exception.
|
|
1717
|
-
RuntimeError:
|
|
1705
|
+
RuntimeError: QrackStabilizer cannot lda()! (Create a QrackSimulator instead.)
|
|
1718
1706
|
"""
|
|
1719
|
-
if self.is_tensor_network:
|
|
1720
|
-
raise RuntimeError(
|
|
1721
|
-
"QrackSimulator with isTensorNetwork=True option cannot lda()! (Turn off just this option, in the constructor.)"
|
|
1722
|
-
)
|
|
1723
1707
|
if self.is_pure_stabilizer:
|
|
1724
1708
|
raise RuntimeError(
|
|
1725
|
-
"QrackStabilizer cannot lda()! (Create a QrackSimulator instead
|
|
1709
|
+
"QrackStabilizer cannot lda()! (Create a QrackSimulator instead.)"
|
|
1726
1710
|
)
|
|
1727
1711
|
|
|
1728
1712
|
Qrack.qrack_lib.LDA(
|
|
@@ -1748,15 +1732,11 @@ class QrackSimulator:
|
|
|
1748
1732
|
|
|
1749
1733
|
Raises:
|
|
1750
1734
|
RuntimeError: QrackSimulator raised an exception.
|
|
1751
|
-
RuntimeError:
|
|
1735
|
+
RuntimeError: QrackStabilizer cannot adc()! (Create a QrackSimulator instead.)
|
|
1752
1736
|
"""
|
|
1753
|
-
if self.is_tensor_network:
|
|
1754
|
-
raise RuntimeError(
|
|
1755
|
-
"QrackSimulator with isTensorNetwork=True option cannot adc()! (Turn off just this option, in the constructor.)"
|
|
1756
|
-
)
|
|
1757
1737
|
if self.is_pure_stabilizer:
|
|
1758
1738
|
raise RuntimeError(
|
|
1759
|
-
"QrackStabilizer cannot adc()! (Create a QrackSimulator instead
|
|
1739
|
+
"QrackStabilizer cannot adc()! (Create a QrackSimulator instead.)"
|
|
1760
1740
|
)
|
|
1761
1741
|
|
|
1762
1742
|
Qrack.qrack_lib.ADC(
|
|
@@ -1783,15 +1763,11 @@ class QrackSimulator:
|
|
|
1783
1763
|
|
|
1784
1764
|
Raises:
|
|
1785
1765
|
RuntimeError: QrackSimulator raised an exception.
|
|
1786
|
-
RuntimeError:
|
|
1766
|
+
RuntimeError: QrackStabilizer cannot sbc()! (Create a QrackSimulator instead.)
|
|
1787
1767
|
"""
|
|
1788
|
-
if self.is_tensor_network:
|
|
1789
|
-
raise RuntimeError(
|
|
1790
|
-
"QrackSimulator with isTensorNetwork=True option cannot sbc()! (Turn off just this option, in the constructor.)"
|
|
1791
|
-
)
|
|
1792
1768
|
if self.is_pure_stabilizer:
|
|
1793
1769
|
raise RuntimeError(
|
|
1794
|
-
"QrackStabilizer cannot sbc()! (Create a QrackSimulator instead
|
|
1770
|
+
"QrackStabilizer cannot sbc()! (Create a QrackSimulator instead.)"
|
|
1795
1771
|
)
|
|
1796
1772
|
|
|
1797
1773
|
Qrack.qrack_lib.SBC(
|
|
@@ -1819,19 +1795,18 @@ class QrackSimulator:
|
|
|
1819
1795
|
|
|
1820
1796
|
Raises:
|
|
1821
1797
|
RuntimeError: QrackSimulator raised an exception.
|
|
1822
|
-
RuntimeError:
|
|
1798
|
+
RuntimeError: QrackStabilizer cannot hash()! (Create a QrackSimulator instead.)
|
|
1823
1799
|
"""
|
|
1824
|
-
if self.is_tensor_network:
|
|
1825
|
-
raise RuntimeError(
|
|
1826
|
-
"QrackSimulator with isTensorNetwork=True option cannot hash()! (Turn off just this option, in the constructor.)"
|
|
1827
|
-
)
|
|
1828
1800
|
if self.is_pure_stabilizer:
|
|
1829
1801
|
raise RuntimeError(
|
|
1830
|
-
"QrackStabilizer cannot hash()! (Create a QrackSimulator instead
|
|
1802
|
+
"QrackStabilizer cannot hash()! (Create a QrackSimulator instead.)"
|
|
1831
1803
|
)
|
|
1832
1804
|
|
|
1833
1805
|
Qrack.qrack_lib.Hash(
|
|
1834
|
-
self.sid,
|
|
1806
|
+
self.sid,
|
|
1807
|
+
len(q),
|
|
1808
|
+
QrackSimulator._ulonglong_byref(q),
|
|
1809
|
+
QrackSimulator._to_ubyte(len(q), t),
|
|
1835
1810
|
)
|
|
1836
1811
|
self._throw_if_error()
|
|
1837
1812
|
|
|
@@ -2134,13 +2109,7 @@ class QrackSimulator:
|
|
|
2134
2109
|
|
|
2135
2110
|
Raises:
|
|
2136
2111
|
RuntimeError: QrackSimulator raised an exception.
|
|
2137
|
-
RuntimeError: QrackSimulator with isTensorNetwork=True option cannot compose()! (Turn off just this option, in the constructor.)
|
|
2138
2112
|
"""
|
|
2139
|
-
if self.is_tensor_network:
|
|
2140
|
-
raise RuntimeError(
|
|
2141
|
-
"QrackSimulator with isTensorNetwork=True option cannot compose()! (Turn off just this option, in the constructor.)"
|
|
2142
|
-
)
|
|
2143
|
-
|
|
2144
2113
|
Qrack.qrack_lib.Compose(self.sid, other.sid, QrackSimulator._ulonglong_byref(q))
|
|
2145
2114
|
self._throw_if_error()
|
|
2146
2115
|
|
|
@@ -2154,16 +2123,10 @@ class QrackSimulator:
|
|
|
2154
2123
|
|
|
2155
2124
|
Raises:
|
|
2156
2125
|
RuntimeError: QrackSimulator raised an exception.
|
|
2157
|
-
RuntimeError: QrackSimulator with isTensorNetwork=True option cannot decompose()! (Turn off just this option, in the constructor.)
|
|
2158
2126
|
|
|
2159
2127
|
Returns:
|
|
2160
2128
|
Decomposed subsystem simulator.
|
|
2161
2129
|
"""
|
|
2162
|
-
if self.is_tensor_network:
|
|
2163
|
-
raise RuntimeError(
|
|
2164
|
-
"QrackSimulator with isTensorNetwork=True option cannot decompose()! (Turn off just this option, in the constructor.)"
|
|
2165
|
-
)
|
|
2166
|
-
|
|
2167
2130
|
other = QrackSimulator()
|
|
2168
2131
|
Qrack.qrack_lib.destroy(other.sid)
|
|
2169
2132
|
l = len(q)
|
|
@@ -2182,13 +2145,7 @@ class QrackSimulator:
|
|
|
2182
2145
|
|
|
2183
2146
|
Raises:
|
|
2184
2147
|
RuntimeError: QrackSimulator raised an exception.
|
|
2185
|
-
RuntimeError: QrackSimulator with isTensorNetwork=True option cannot dispose()! (Turn off just this option, in the constructor.)
|
|
2186
2148
|
"""
|
|
2187
|
-
if self.is_tensor_network:
|
|
2188
|
-
raise RuntimeError(
|
|
2189
|
-
"QrackSimulator with isTensorNetwork=True option cannot dispose()! (Turn off just this option, in the constructor.)"
|
|
2190
|
-
)
|
|
2191
|
-
|
|
2192
2149
|
l = len(q)
|
|
2193
2150
|
Qrack.qrack_lib.Dispose(self.sid, l, QrackSimulator._ulonglong_byref(q))
|
|
2194
2151
|
self._throw_if_error()
|
|
@@ -2316,7 +2273,9 @@ class QrackSimulator:
|
|
|
2316
2273
|
amp_count = 1 << len(q)
|
|
2317
2274
|
sqr_amp_count = amp_count * amp_count
|
|
2318
2275
|
flat_rdm = QrackSimulator._qrack_complex_byref([complex(0, 0)] * sqr_amp_count)
|
|
2319
|
-
Qrack.qrack_lib.OutReducedDensityMatrix(
|
|
2276
|
+
Qrack.qrack_lib.OutReducedDensityMatrix(
|
|
2277
|
+
self.sid, len(q), QrackSimulator._ulonglong_byref(q), flat_rdm
|
|
2278
|
+
)
|
|
2320
2279
|
self._throw_if_error()
|
|
2321
2280
|
return [complex(r, i) for r, i in QrackSimulator._pairwise(flat_rdm)]
|
|
2322
2281
|
|
|
@@ -2541,7 +2500,11 @@ class QrackSimulator:
|
|
|
2541
2500
|
raise RuntimeError("factorized_expectation argument lengths do not match.")
|
|
2542
2501
|
m = max([(x.bit_length() + 63) // 64 for x in c])
|
|
2543
2502
|
result = Qrack.qrack_lib.FactorizedExpectation(
|
|
2544
|
-
self.sid,
|
|
2503
|
+
self.sid,
|
|
2504
|
+
len(q),
|
|
2505
|
+
QrackSimulator._ulonglong_byref(q),
|
|
2506
|
+
m,
|
|
2507
|
+
QrackSimulator._to_ulonglong(m, c),
|
|
2545
2508
|
)
|
|
2546
2509
|
self._throw_if_error()
|
|
2547
2510
|
return result
|
|
@@ -2566,12 +2529,15 @@ class QrackSimulator:
|
|
|
2566
2529
|
Expectation value
|
|
2567
2530
|
"""
|
|
2568
2531
|
if (len(q) << 1) != len(c):
|
|
2569
|
-
raise RuntimeError(
|
|
2570
|
-
"factorized_expectation_rdm argument lengths do not match."
|
|
2571
|
-
)
|
|
2532
|
+
raise RuntimeError("factorized_expectation_rdm argument lengths do not match.")
|
|
2572
2533
|
m = max([(x.bit_length() + 63) // 64 for x in c])
|
|
2573
2534
|
result = Qrack.qrack_lib.FactorizedExpectationRdm(
|
|
2574
|
-
self.sid,
|
|
2535
|
+
self.sid,
|
|
2536
|
+
len(q),
|
|
2537
|
+
QrackSimulator._ulonglong_byref(q),
|
|
2538
|
+
m,
|
|
2539
|
+
QrackSimulator._to_ulonglong(m, c),
|
|
2540
|
+
r,
|
|
2575
2541
|
)
|
|
2576
2542
|
self._throw_if_error()
|
|
2577
2543
|
return result
|
|
@@ -2594,9 +2560,7 @@ class QrackSimulator:
|
|
|
2594
2560
|
Expectation value
|
|
2595
2561
|
"""
|
|
2596
2562
|
if (len(q) << 1) != len(c):
|
|
2597
|
-
raise RuntimeError(
|
|
2598
|
-
"factorized_expectation_rdm argument lengths do not match."
|
|
2599
|
-
)
|
|
2563
|
+
raise RuntimeError("factorized_expectation_rdm argument lengths do not match.")
|
|
2600
2564
|
result = Qrack.qrack_lib.FactorizedExpectationFp(
|
|
2601
2565
|
self.sid, len(q), QrackSimulator._ulonglong_byref(q), QrackSimulator._real1_byref(c)
|
|
2602
2566
|
)
|
|
@@ -2623,9 +2587,7 @@ class QrackSimulator:
|
|
|
2623
2587
|
Expectation value
|
|
2624
2588
|
"""
|
|
2625
2589
|
if (len(q) << 1) != len(c):
|
|
2626
|
-
raise RuntimeError(
|
|
2627
|
-
"factorized_expectation_fp_rdm argument lengths do not match."
|
|
2628
|
-
)
|
|
2590
|
+
raise RuntimeError("factorized_expectation_fp_rdm argument lengths do not match.")
|
|
2629
2591
|
result = Qrack.qrack_lib.FactorizedExpectationFpRdm(
|
|
2630
2592
|
self.sid, len(q), QrackSimulator._ulonglong_byref(q), QrackSimulator._real1_byref(c), r
|
|
2631
2593
|
)
|
|
@@ -2836,7 +2798,11 @@ class QrackSimulator:
|
|
|
2836
2798
|
raise RuntimeError("factorized_variance argument lengths do not match.")
|
|
2837
2799
|
m = max([(x.bit_length() + 63) // 64 for x in c])
|
|
2838
2800
|
result = Qrack.qrack_lib.FactorizedVariance(
|
|
2839
|
-
self.sid,
|
|
2801
|
+
self.sid,
|
|
2802
|
+
len(q),
|
|
2803
|
+
QrackSimulator._ulonglong_byref(q),
|
|
2804
|
+
m,
|
|
2805
|
+
QrackSimulator._to_ulonglong(m, c),
|
|
2840
2806
|
)
|
|
2841
2807
|
self._throw_if_error()
|
|
2842
2808
|
return result
|
|
@@ -2864,7 +2830,12 @@ class QrackSimulator:
|
|
|
2864
2830
|
raise RuntimeError("factorized_variance_rdm argument lengths do not match.")
|
|
2865
2831
|
m = max([(x.bit_length() + 63) // 64 for x in c])
|
|
2866
2832
|
result = Qrack.qrack_lib.FactorizedVarianceRdm(
|
|
2867
|
-
self.sid,
|
|
2833
|
+
self.sid,
|
|
2834
|
+
len(q),
|
|
2835
|
+
QrackSimulator._ulonglong_byref(q),
|
|
2836
|
+
m,
|
|
2837
|
+
QrackSimulator._to_ulonglong(m, c),
|
|
2838
|
+
r,
|
|
2868
2839
|
)
|
|
2869
2840
|
self._throw_if_error()
|
|
2870
2841
|
return result
|
|
@@ -2914,9 +2885,7 @@ class QrackSimulator:
|
|
|
2914
2885
|
variance
|
|
2915
2886
|
"""
|
|
2916
2887
|
if (len(q) << 1) != len(c):
|
|
2917
|
-
raise RuntimeError(
|
|
2918
|
-
"factorized_variance_fp_rdm argument lengths do not match."
|
|
2919
|
-
)
|
|
2888
|
+
raise RuntimeError("factorized_variance_fp_rdm argument lengths do not match.")
|
|
2920
2889
|
result = Qrack.qrack_lib.FactorizedVarianceFpRdm(
|
|
2921
2890
|
self.sid, len(q), QrackSimulator._ulonglong_byref(q), QrackSimulator._real1_byref(c), r
|
|
2922
2891
|
)
|
|
@@ -3100,15 +3069,11 @@ class QrackSimulator:
|
|
|
3100
3069
|
|
|
3101
3070
|
Raises:
|
|
3102
3071
|
RuntimeError: QrackSimulator raised an exception.
|
|
3103
|
-
RuntimeError:
|
|
3072
|
+
RuntimeError: QrackStabilizer cannot phase_parity()! (Create a QrackSimulator instead.)
|
|
3104
3073
|
"""
|
|
3105
|
-
if self.is_tensor_network:
|
|
3106
|
-
raise RuntimeError(
|
|
3107
|
-
"QrackSimulator with isTensorNetwork=True option cannot phase_parity()! (Turn off just this option, in the constructor.)"
|
|
3108
|
-
)
|
|
3109
3074
|
if self.is_pure_stabilizer:
|
|
3110
3075
|
raise RuntimeError(
|
|
3111
|
-
"QrackStabilizer cannot phase_parity()! (Create a QrackSimulator instead
|
|
3076
|
+
"QrackStabilizer cannot phase_parity()! (Create a QrackSimulator instead.)"
|
|
3112
3077
|
)
|
|
3113
3078
|
|
|
3114
3079
|
Qrack.qrack_lib.PhaseParity(
|
|
@@ -3127,15 +3092,11 @@ class QrackSimulator:
|
|
|
3127
3092
|
|
|
3128
3093
|
Raises:
|
|
3129
3094
|
RuntimeError: QrackSimulator raised an exception.
|
|
3130
|
-
RuntimeError:
|
|
3095
|
+
RuntimeError: QrackStabilizer cannot phase_root_n()! (Create a QrackSimulator instead.)
|
|
3131
3096
|
"""
|
|
3132
|
-
if self.is_tensor_network:
|
|
3133
|
-
raise RuntimeError(
|
|
3134
|
-
"QrackSimulator with isTensorNetwork=True option cannot phase_root_n()! (Turn off just this option, in the constructor.)"
|
|
3135
|
-
)
|
|
3136
3097
|
if self.is_pure_stabilizer:
|
|
3137
3098
|
raise RuntimeError(
|
|
3138
|
-
"QrackStabilizer cannot phase_root_n()! (Create a QrackSimulator instead
|
|
3099
|
+
"QrackStabilizer cannot phase_root_n()! (Create a QrackSimulator instead.)"
|
|
3139
3100
|
)
|
|
3140
3101
|
|
|
3141
3102
|
Qrack.qrack_lib.PhaseRootN(self.sid, n, len(q), QrackSimulator._ulonglong_byref(q))
|
|
@@ -3551,9 +3512,7 @@ class QrackSimulator:
|
|
|
3551
3512
|
"swap",
|
|
3552
3513
|
]
|
|
3553
3514
|
try:
|
|
3554
|
-
circ = transpile(
|
|
3555
|
-
clifford_circ, basis_gates=basis_gates, optimization_level=2
|
|
3556
|
-
)
|
|
3515
|
+
circ = transpile(clifford_circ, basis_gates=basis_gates, optimization_level=2)
|
|
3557
3516
|
except:
|
|
3558
3517
|
circ = clifford_circ
|
|
3559
3518
|
|
|
@@ -3649,9 +3608,7 @@ class QrackSimulator:
|
|
|
3649
3608
|
)
|
|
3650
3609
|
elif op.name == "h":
|
|
3651
3610
|
non_clifford = np.matmul(
|
|
3652
|
-
np.array(
|
|
3653
|
-
[[sqrt1_2, sqrt1_2], [sqrt1_2, -sqrt1_2]], np.complex128
|
|
3654
|
-
),
|
|
3611
|
+
np.array([[sqrt1_2, sqrt1_2], [sqrt1_2, -sqrt1_2]], np.complex128),
|
|
3655
3612
|
non_clifford,
|
|
3656
3613
|
)
|
|
3657
3614
|
elif op.name == "x":
|
|
@@ -3759,9 +3716,7 @@ class QrackSimulator:
|
|
|
3759
3716
|
j += 1
|
|
3760
3717
|
continue
|
|
3761
3718
|
|
|
3762
|
-
if (q1 == i) and (
|
|
3763
|
-
(op.name == "cx") or (op.name == "cy") or (op.name == "cz")
|
|
3764
|
-
):
|
|
3719
|
+
if (q1 == i) and ((op.name == "cx") or (op.name == "cy") or (op.name == "cz")):
|
|
3765
3720
|
if np.isclose(np.abs(non_clifford[0][1]), 0) and np.isclose(
|
|
3766
3721
|
np.abs(non_clifford[1][0]), 0
|
|
3767
3722
|
):
|
|
@@ -3827,9 +3782,7 @@ class QrackSimulator:
|
|
|
3827
3782
|
elif op.name == "h":
|
|
3828
3783
|
non_clifford = np.matmul(
|
|
3829
3784
|
non_clifford,
|
|
3830
|
-
np.array(
|
|
3831
|
-
[[sqrt1_2, sqrt1_2], [sqrt1_2, -sqrt1_2]], np.complex128
|
|
3832
|
-
),
|
|
3785
|
+
np.array([[sqrt1_2, sqrt1_2], [sqrt1_2, -sqrt1_2]], np.complex128),
|
|
3833
3786
|
)
|
|
3834
3787
|
elif op.name == "x":
|
|
3835
3788
|
non_clifford = np.matmul(
|
|
@@ -4019,12 +3972,8 @@ class QrackSimulator:
|
|
|
4019
3972
|
qasm = qasm3.dumps(circ)
|
|
4020
3973
|
except:
|
|
4021
3974
|
qasm = circ.qasm()
|
|
4022
|
-
qasm = qasm.replace(
|
|
4023
|
-
|
|
4024
|
-
)
|
|
4025
|
-
highest_index = max(
|
|
4026
|
-
[int(x) for x in re.findall(r"\[(.*?)\]", qasm) if x.isdigit()]
|
|
4027
|
-
)
|
|
3975
|
+
qasm = qasm.replace("qreg q[" + str(circ.width()) + "];", "qreg q[" + str(width) + "];")
|
|
3976
|
+
highest_index = max([int(x) for x in re.findall(r"\[(.*?)\]", qasm) if x.isdigit()])
|
|
4028
3977
|
if highest_index != width:
|
|
4029
3978
|
qasm = qasm.replace(
|
|
4030
3979
|
"qreg q[" + str(width) + "];", "qreg q[" + str(highest_index) + "];"
|
|
@@ -4139,17 +4088,11 @@ class QrackSimulator:
|
|
|
4139
4088
|
(-1 * float(operation.params[1])) + math.pi / 2,
|
|
4140
4089
|
)
|
|
4141
4090
|
elif name == "rx":
|
|
4142
|
-
self._sim.r(
|
|
4143
|
-
Pauli.PauliX, float(operation.params[0]), operation.qubits[0]._index
|
|
4144
|
-
)
|
|
4091
|
+
self._sim.r(Pauli.PauliX, float(operation.params[0]), operation.qubits[0]._index)
|
|
4145
4092
|
elif name == "ry":
|
|
4146
|
-
self._sim.r(
|
|
4147
|
-
Pauli.PauliY, float(operation.params[0]), operation.qubits[0]._index
|
|
4148
|
-
)
|
|
4093
|
+
self._sim.r(Pauli.PauliY, float(operation.params[0]), operation.qubits[0]._index)
|
|
4149
4094
|
elif name == "rz":
|
|
4150
|
-
self._sim.r(
|
|
4151
|
-
Pauli.PauliZ, float(operation.params[0]), operation.qubits[0]._index
|
|
4152
|
-
)
|
|
4095
|
+
self._sim.r(Pauli.PauliZ, float(operation.params[0]), operation.qubits[0]._index)
|
|
4153
4096
|
elif name == "h":
|
|
4154
4097
|
self._sim.h(operation.qubits[0]._index)
|
|
4155
4098
|
elif name == "x":
|
|
@@ -4201,21 +4144,13 @@ class QrackSimulator:
|
|
|
4201
4144
|
float(operation.params[2]),
|
|
4202
4145
|
)
|
|
4203
4146
|
elif name == "cx":
|
|
4204
|
-
self._sim.mcx(
|
|
4205
|
-
[q._index for q in operation.qubits[0:1]], operation.qubits[1]._index
|
|
4206
|
-
)
|
|
4147
|
+
self._sim.mcx([q._index for q in operation.qubits[0:1]], operation.qubits[1]._index)
|
|
4207
4148
|
elif name == "cy":
|
|
4208
|
-
self._sim.mcy(
|
|
4209
|
-
[q._index for q in operation.qubits[0:1]], operation.qubits[1]._index
|
|
4210
|
-
)
|
|
4149
|
+
self._sim.mcy([q._index for q in operation.qubits[0:1]], operation.qubits[1]._index)
|
|
4211
4150
|
elif name == "cz":
|
|
4212
|
-
self._sim.mcz(
|
|
4213
|
-
[q._index for q in operation.qubits[0:1]], operation.qubits[1]._index
|
|
4214
|
-
)
|
|
4151
|
+
self._sim.mcz([q._index for q in operation.qubits[0:1]], operation.qubits[1]._index)
|
|
4215
4152
|
elif name == "ch":
|
|
4216
|
-
self._sim.mch(
|
|
4217
|
-
[q._index for q in operation.qubits[0:1]], operation.qubits[1]._index
|
|
4218
|
-
)
|
|
4153
|
+
self._sim.mch([q._index for q in operation.qubits[0:1]], operation.qubits[1]._index)
|
|
4219
4154
|
elif name == "cp":
|
|
4220
4155
|
self._sim.mcmtrx(
|
|
4221
4156
|
[q._index for q in operation.qubits[0:1]],
|
|
@@ -4241,34 +4176,20 @@ class QrackSimulator:
|
|
|
4241
4176
|
operation.qubits[1]._index,
|
|
4242
4177
|
)
|
|
4243
4178
|
elif name == "dcx":
|
|
4244
|
-
self._sim.mcx(
|
|
4245
|
-
[q._index for q in operation.qubits[0:1]], operation.qubits[1]._index
|
|
4246
|
-
)
|
|
4179
|
+
self._sim.mcx([q._index for q in operation.qubits[0:1]], operation.qubits[1]._index)
|
|
4247
4180
|
self._sim.mcx(operation.qubits[1:2]._index, operation.qubits[0]._index)
|
|
4248
4181
|
elif name == "ccx":
|
|
4249
|
-
self._sim.mcx(
|
|
4250
|
-
[q._index for q in operation.qubits[0:2]], operation.qubits[2]._index
|
|
4251
|
-
)
|
|
4182
|
+
self._sim.mcx([q._index for q in operation.qubits[0:2]], operation.qubits[2]._index)
|
|
4252
4183
|
elif name == "ccy":
|
|
4253
|
-
self._sim.mcy(
|
|
4254
|
-
[q._index for q in operation.qubits[0:2]], operation.qubits[2]._index
|
|
4255
|
-
)
|
|
4184
|
+
self._sim.mcy([q._index for q in operation.qubits[0:2]], operation.qubits[2]._index)
|
|
4256
4185
|
elif name == "ccz":
|
|
4257
|
-
self._sim.mcz(
|
|
4258
|
-
[q._index for q in operation.qubits[0:2]], operation.qubits[2]._index
|
|
4259
|
-
)
|
|
4186
|
+
self._sim.mcz([q._index for q in operation.qubits[0:2]], operation.qubits[2]._index)
|
|
4260
4187
|
elif name == "mcx":
|
|
4261
|
-
self._sim.mcx(
|
|
4262
|
-
[q._index for q in operation.qubits[0:-1]], operation.qubits[-1]._index
|
|
4263
|
-
)
|
|
4188
|
+
self._sim.mcx([q._index for q in operation.qubits[0:-1]], operation.qubits[-1]._index)
|
|
4264
4189
|
elif name == "mcy":
|
|
4265
|
-
self._sim.mcy(
|
|
4266
|
-
[q._index for q in operation.qubits[0:-1]], operation.qubits[-1]._index
|
|
4267
|
-
)
|
|
4190
|
+
self._sim.mcy([q._index for q in operation.qubits[0:-1]], operation.qubits[-1]._index)
|
|
4268
4191
|
elif name == "mcz":
|
|
4269
|
-
self._sim.mcz(
|
|
4270
|
-
[q._index for q in operation.qubits[0:-1]], operation.qubits[-1]._index
|
|
4271
|
-
)
|
|
4192
|
+
self._sim.mcz([q._index for q in operation.qubits[0:-1]], operation.qubits[-1]._index)
|
|
4272
4193
|
elif name == "swap":
|
|
4273
4194
|
self._sim.swap(operation.qubits[0]._index, operation.qubits[1]._index)
|
|
4274
4195
|
elif name == "iswap":
|
|
@@ -4320,9 +4241,9 @@ class QrackSimulator:
|
|
|
4320
4241
|
cregbit = clbit
|
|
4321
4242
|
|
|
4322
4243
|
regbit = 1 << cregbit
|
|
4323
|
-
self._classical_register = (
|
|
4324
|
-
|
|
4325
|
-
)
|
|
4244
|
+
self._classical_register = (self._classical_register & (~regbit)) | (
|
|
4245
|
+
qubit_outcome << cregbit
|
|
4246
|
+
)
|
|
4326
4247
|
|
|
4327
4248
|
elif name == "bfunc":
|
|
4328
4249
|
mask = int(operation.mask, 16)
|
|
@@ -4437,9 +4358,7 @@ class QrackSimulator:
|
|
|
4437
4358
|
if operation.name == "id" or operation.name == "barrier":
|
|
4438
4359
|
continue
|
|
4439
4360
|
|
|
4440
|
-
if is_initializing and (
|
|
4441
|
-
(operation.name == "measure") or (operation.name == "reset")
|
|
4442
|
-
):
|
|
4361
|
+
if is_initializing and ((operation.name == "measure") or (operation.name == "reset")):
|
|
4443
4362
|
continue
|
|
4444
4363
|
|
|
4445
4364
|
is_initializing = False
|
|
@@ -4497,9 +4416,7 @@ class QrackSimulator:
|
|
|
4497
4416
|
self._sample_cregbits = []
|
|
4498
4417
|
|
|
4499
4418
|
if self._sample_measure and (len(self._sample_qubits) > 0):
|
|
4500
|
-
_data = self._add_sample_measure(
|
|
4501
|
-
self._sample_qubits, self._sample_clbits, self._shots
|
|
4502
|
-
)
|
|
4419
|
+
_data = self._add_sample_measure(self._sample_qubits, self._sample_clbits, self._shots)
|
|
4503
4420
|
|
|
4504
4421
|
del self._sim
|
|
4505
4422
|
|
pyqrack/qrack_system/qrack_lib/{libqrack_pinvoke.9.34.5.dylib → libqrack_pinvoke.10.0.0.dylib}
RENAMED
|
Binary file
|
|
Binary file
|