PyQrackIsing 9.2.4__py3-none-win_amd64.whl → 9.3.0__py3-none-win_amd64.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.
- pyqrackising/__init__.py +3 -1
- pyqrackising/generate_tfim_samples.py +7 -2
- pyqrackising/maxcut_tfim_util.py +6 -3
- pyqrackising/otoc.py +173 -0
- pyqrackising/tsp.py +3 -4
- {pyqrackising-9.2.4.dist-info → pyqrackising-9.3.0.dist-info}/METADATA +1 -1
- {pyqrackising-9.2.4.dist-info → pyqrackising-9.3.0.dist-info}/RECORD +10 -9
- {pyqrackising-9.2.4.dist-info → pyqrackising-9.3.0.dist-info}/WHEEL +0 -0
- {pyqrackising-9.2.4.dist-info → pyqrackising-9.3.0.dist-info}/licenses/LICENSE.md +0 -0
- {pyqrackising-9.2.4.dist-info → pyqrackising-9.3.0.dist-info}/top_level.txt +0 -0
pyqrackising/__init__.py
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
from .generate_tfim_samples import generate_tfim_samples
|
|
1
|
+
from .generate_tfim_samples import generate_tfim_samples, get_tfim_hamming_distribution
|
|
2
2
|
from .tfim_magnetization import tfim_magnetization
|
|
3
3
|
from .tfim_square_magnetization import tfim_square_magnetization
|
|
4
|
+
from .otoc import generate_otoc_samples, get_otoc_hamming_distribution
|
|
4
5
|
from .maxcut_tfim import maxcut_tfim
|
|
5
6
|
from .maxcut_tfim_sparse import maxcut_tfim_sparse
|
|
6
7
|
from .maxcut_tfim_streaming import maxcut_tfim_streaming
|
|
8
|
+
from .maxcut_tfim_util import probability_by_hamming_weight
|
|
7
9
|
from .spin_glass_solver import spin_glass_solver
|
|
8
10
|
from .spin_glass_solver_sparse import spin_glass_solver_sparse
|
|
9
11
|
from .spin_glass_solver_streaming import spin_glass_solver_streaming
|
|
@@ -91,7 +91,6 @@ def sample_hamming_weight(thresholds, shots):
|
|
|
91
91
|
|
|
92
92
|
@njit
|
|
93
93
|
def fix_cdf(hamming_prob):
|
|
94
|
-
hamming_prob /= hamming_prob.sum()
|
|
95
94
|
tot_prob = 0.0
|
|
96
95
|
n_bias = len(hamming_prob)
|
|
97
96
|
cum_prob = np.empty(n_bias, dtype=np.float64)
|
|
@@ -103,13 +102,19 @@ def fix_cdf(hamming_prob):
|
|
|
103
102
|
return cum_prob
|
|
104
103
|
|
|
105
104
|
|
|
105
|
+
@njit
|
|
106
|
+
def get_tfim_hamming_distribution(J=-1.0, h=2.0, z=4, theta=0.174532925199432957, t=5, n_qubits=56):
|
|
107
|
+
bias = probability_by_hamming_weight(J, h, z, theta, t, n_qubits + 1)
|
|
108
|
+
return bias / bias.sum()
|
|
109
|
+
|
|
110
|
+
|
|
106
111
|
def generate_tfim_samples(
|
|
107
112
|
J=-1.0, h=2.0, z=4, theta=0.174532925199432957, t=5, n_qubits=56, shots=100
|
|
108
113
|
):
|
|
109
114
|
n_rows, n_cols = factor_width(n_qubits)
|
|
110
115
|
|
|
111
116
|
# First dimension: Hamming weight
|
|
112
|
-
thresholds = fix_cdf(
|
|
117
|
+
thresholds = fix_cdf(get_tfim_hamming_distribution(J, h, z, theta, t, n_qubits + 1))
|
|
113
118
|
hamming_samples = sample_hamming_weight(thresholds, shots)
|
|
114
119
|
|
|
115
120
|
samples = []
|
pyqrackising/maxcut_tfim_util.py
CHANGED
|
@@ -411,7 +411,7 @@ def init_thresholds(n_qubits):
|
|
|
411
411
|
|
|
412
412
|
|
|
413
413
|
@njit
|
|
414
|
-
def probability_by_hamming_weight(J, h, z, theta, t, n_bias):
|
|
414
|
+
def probability_by_hamming_weight(J, h, z, theta, t, n_bias, normalized=True):
|
|
415
415
|
zJ = z * J
|
|
416
416
|
theta_c = ((np.pi if J > 0 else -np.pi) / 2) if abs(zJ) < epsilon else np.arcsin(max(-1.0, min(1.0, h / zJ)))
|
|
417
417
|
|
|
@@ -435,6 +435,9 @@ def probability_by_hamming_weight(J, h, z, theta, t, n_bias):
|
|
|
435
435
|
if J > 0.0:
|
|
436
436
|
return bias[::-1]
|
|
437
437
|
|
|
438
|
+
if normalized:
|
|
439
|
+
bias /= bias.sum()
|
|
440
|
+
|
|
438
441
|
return bias
|
|
439
442
|
|
|
440
443
|
|
|
@@ -459,8 +462,8 @@ def maxcut_hamming_cdf(n_qubits, J_func, degrees, quality, tot_t, h_mult):
|
|
|
459
462
|
t = step * delta_t
|
|
460
463
|
tm1 = (step - 1) * delta_t
|
|
461
464
|
h_t = h_mult * (tot_t - t)
|
|
462
|
-
bias = probability_by_hamming_weight(J_eff, h_t, z, theta_eff, t, n_bias)
|
|
463
|
-
last_bias = probability_by_hamming_weight(J_eff, h_t, z, theta_eff, tm1, n_bias)
|
|
465
|
+
bias = probability_by_hamming_weight(J_eff, h_t, z, theta_eff, t, n_bias, False)
|
|
466
|
+
last_bias = probability_by_hamming_weight(J_eff, h_t, z, theta_eff, tm1, n_bias, False)
|
|
464
467
|
for i in range(n_bias):
|
|
465
468
|
hamming_prob[i] += bias[i] - last_bias[i]
|
|
466
469
|
|
pyqrackising/otoc.py
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
from .maxcut_tfim_util import probability_by_hamming_weight, sample_mag
|
|
2
|
+
from numba import njit
|
|
3
|
+
import numpy as np
|
|
4
|
+
import random
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def get_otoc_hamming_distribution(J=-1.0, h=2.0, z=4, theta=0.174532925199432957, t=5, n_qubits=56, cycles=1, pauli_string = 'X' + 'I' * 55):
|
|
8
|
+
pauli_string = list(pauli_string)
|
|
9
|
+
if len(pauli_string) != n_qubits:
|
|
10
|
+
raise ValueError("OTOCS pauli_string must be same length as n_qubits! (Use 'I' for qubits that aren't changed.)")
|
|
11
|
+
|
|
12
|
+
fwd = probability_by_hamming_weight(J, h, z, theta, t, n_qubits + 1, False)
|
|
13
|
+
rev = probability_by_hamming_weight(-J, -h, z, -theta, t, n_qubits + 1, False)
|
|
14
|
+
diff_theta = rev - fwd
|
|
15
|
+
|
|
16
|
+
phi = theta - np.pi / 2
|
|
17
|
+
fwd = probability_by_hamming_weight(J, h, z, phi, t, n_qubits + 1, False)
|
|
18
|
+
rev = probability_by_hamming_weight(-J, -h, z, -phi, t, n_qubits + 1, False)
|
|
19
|
+
diff_phi = rev - fwd
|
|
20
|
+
|
|
21
|
+
diff_theta *= cycles
|
|
22
|
+
diff_phi *= cycles
|
|
23
|
+
diff_lam = 0.5 * (diff_theta + diff_phi)
|
|
24
|
+
|
|
25
|
+
n_bias = n_qubits + 1
|
|
26
|
+
diff_z = np.zeros(n_bias, dtype=np.float64)
|
|
27
|
+
diff_x = np.zeros(n_bias, dtype=np.float64)
|
|
28
|
+
diff_y = np.zeros(n_bias, dtype=np.float64)
|
|
29
|
+
for b in pauli_string:
|
|
30
|
+
match b:
|
|
31
|
+
case 'X':
|
|
32
|
+
diff_z += diff_theta
|
|
33
|
+
diff_x += diff_lam
|
|
34
|
+
diff_y += diff_phi
|
|
35
|
+
case 'Z':
|
|
36
|
+
diff_z += diff_phi
|
|
37
|
+
diff_x += diff_theta
|
|
38
|
+
diff_y += diff_lam
|
|
39
|
+
case 'Y':
|
|
40
|
+
diff_z += diff_lam
|
|
41
|
+
diff_x += diff_phi
|
|
42
|
+
diff_y += diff_theta
|
|
43
|
+
|
|
44
|
+
diff_z -= diff_z.min()
|
|
45
|
+
diff_x -= diff_x.min()
|
|
46
|
+
diff_y -= diff_y.min()
|
|
47
|
+
|
|
48
|
+
diff_z[0] += n_bias
|
|
49
|
+
diff_x[0] += n_bias
|
|
50
|
+
diff_y[0] += n_bias
|
|
51
|
+
|
|
52
|
+
diff_z /= diff_z.sum()
|
|
53
|
+
diff_x /= diff_x.sum()
|
|
54
|
+
diff_y /= diff_y.sum()
|
|
55
|
+
|
|
56
|
+
return { 'X': diff_x, 'Y': diff_y, 'Z': diff_z }
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
@njit
|
|
60
|
+
def fix_cdf(hamming_prob):
|
|
61
|
+
tot_prob = 0.0
|
|
62
|
+
n_bias = len(hamming_prob)
|
|
63
|
+
cum_prob = np.empty(n_bias, dtype=np.float64)
|
|
64
|
+
for i in range(n_bias):
|
|
65
|
+
tot_prob += hamming_prob[i]
|
|
66
|
+
cum_prob[i] = tot_prob
|
|
67
|
+
cum_prob[-1] = 2.0
|
|
68
|
+
|
|
69
|
+
return cum_prob
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
@njit
|
|
73
|
+
def take_all(b, basis, sample):
|
|
74
|
+
for i in range(len(basis)):
|
|
75
|
+
if basis[i] == b:
|
|
76
|
+
sample |= (1 << i)
|
|
77
|
+
|
|
78
|
+
return sample
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def take_sample(b, basis, sample, m):
|
|
82
|
+
indices = []
|
|
83
|
+
for i in range(len(basis)):
|
|
84
|
+
if basis[i] == b:
|
|
85
|
+
indices.append(i)
|
|
86
|
+
indices = random.sample(indices, m)
|
|
87
|
+
for i in indices:
|
|
88
|
+
sample |= 1 << i
|
|
89
|
+
|
|
90
|
+
return sample
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def generate_otoc_samples(J=-1.0, h=2.0, z=4, theta=0.174532925199432957, t=5, n_qubits=56, cycles=1, pauli_string = 'X' + 'I' * 55, shots=100, measurement_basis='Z' * 56):
|
|
94
|
+
pauli_string = list(pauli_string)
|
|
95
|
+
if len(pauli_string) != n_qubits:
|
|
96
|
+
raise ValueError("OTOC pauli_string must be same length as n_qubits! (Use 'I' for qubits that aren't changed.)")
|
|
97
|
+
|
|
98
|
+
measurement_basis = list(measurement_basis)
|
|
99
|
+
if len(measurement_basis) != n_qubits:
|
|
100
|
+
raise ValueError("OTOC measurement_basis must be same length as measurement_basis! (Use 'I' for excluded qubits.)")
|
|
101
|
+
|
|
102
|
+
basis_x, basis_y, basis_z = [], [], []
|
|
103
|
+
for b in pauli_string:
|
|
104
|
+
if b == 'Z':
|
|
105
|
+
basis_z.append('X')
|
|
106
|
+
basis_y.append('Z')
|
|
107
|
+
basis_x.append('I')
|
|
108
|
+
elif b == 'X':
|
|
109
|
+
basis_z.append('Z')
|
|
110
|
+
basis_y.append('I')
|
|
111
|
+
basis_x.append('X')
|
|
112
|
+
elif b == 'Y':
|
|
113
|
+
basis_z.append('I')
|
|
114
|
+
basis_y.append('I')
|
|
115
|
+
basis_x.append('X')
|
|
116
|
+
else:
|
|
117
|
+
basis_z.append('I')
|
|
118
|
+
basis_y.append('X')
|
|
119
|
+
basis_x.append('Z')
|
|
120
|
+
|
|
121
|
+
bases = { 'X': basis_x, 'Y': basis_y, 'Z': basis_z }
|
|
122
|
+
thresholds = { key: fix_cdf(value) for key, value in get_otoc_hamming_distribution(J, h, z, theta, t, n_qubits, cycles, pauli_string).items() }
|
|
123
|
+
|
|
124
|
+
samples_3_axis = {}
|
|
125
|
+
for key, value in thresholds.items():
|
|
126
|
+
basis = bases[key]
|
|
127
|
+
|
|
128
|
+
samples = []
|
|
129
|
+
for _ in range(shots):
|
|
130
|
+
sample_3_axis = { 'X': 0, 'Y': 0, 'Z': 0 }
|
|
131
|
+
for key, value in thresholds.items():
|
|
132
|
+
basis = bases[key]
|
|
133
|
+
|
|
134
|
+
# First dimension: Hamming weight
|
|
135
|
+
m = sample_mag(value)
|
|
136
|
+
if m >= n_qubits:
|
|
137
|
+
sample_3_axis[key] = (1 << n_qubits) - 1
|
|
138
|
+
continue
|
|
139
|
+
|
|
140
|
+
# Second dimension: permutation within Hamming weight
|
|
141
|
+
z_count = basis.count('Z')
|
|
142
|
+
if z_count > m:
|
|
143
|
+
sample_3_axis[key] = take_sample('Z', basis, sample_3_axis[key], m)
|
|
144
|
+
continue
|
|
145
|
+
m -= z_count
|
|
146
|
+
sample_3_axis[key] = take_all('Z', basis, sample_3_axis[key])
|
|
147
|
+
if m == 0:
|
|
148
|
+
continue
|
|
149
|
+
|
|
150
|
+
i_count = basis.count('I')
|
|
151
|
+
if i_count > m:
|
|
152
|
+
sample_3_axis[key] = take_sample('I', basis, sample_3_axis[key], m)
|
|
153
|
+
continue
|
|
154
|
+
m -= i_count
|
|
155
|
+
sample_3_axis[key] = take_all('I', basis, sample_3_axis[key])
|
|
156
|
+
if m == 0:
|
|
157
|
+
continue
|
|
158
|
+
|
|
159
|
+
sample_3_axis[key] = take_sample('X', basis, sample_3_axis[key], m)
|
|
160
|
+
|
|
161
|
+
sample = 0
|
|
162
|
+
j = 0
|
|
163
|
+
for i in range(n_qubits):
|
|
164
|
+
base = measurement_basis[i]
|
|
165
|
+
if base not in ['X', 'Y', 'Z']:
|
|
166
|
+
continue
|
|
167
|
+
if (sample_3_axis[base] >> i) & 1:
|
|
168
|
+
sample |= 1 << j
|
|
169
|
+
j += 1
|
|
170
|
+
|
|
171
|
+
samples.append(sample)
|
|
172
|
+
|
|
173
|
+
return samples
|
pyqrackising/tsp.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
from .maxcut_tfim_util import binary_search, opencl_context, to_scipy_sparse_upper_triangular
|
|
2
|
-
from .
|
|
2
|
+
from .spin_glass_solver import spin_glass_solver
|
|
3
3
|
from concurrent.futures import ProcessPoolExecutor
|
|
4
|
-
import time
|
|
5
4
|
import itertools
|
|
6
5
|
import networkx as nx
|
|
7
6
|
from numba import njit, prange
|
|
@@ -639,7 +638,7 @@ def tsp_symmetric_header(G_m, nodes, quality, shots, anneal_t, anneal_h, repulsi
|
|
|
639
638
|
for _ in range(multi_start):
|
|
640
639
|
bits = ([], [])
|
|
641
640
|
while (len(bits[0]) == 0) or (len(bits[1]) == 0):
|
|
642
|
-
_, cut_value, bits =
|
|
641
|
+
_, cut_value, bits, _ = spin_glass_solver(G_m, is_spin_glass=False, quality=quality, shots=shots, anneal_t=anneal_t, anneal_h=anneal_h, repulsion_base=repulsion_base)
|
|
643
642
|
if cut_value > best_cut:
|
|
644
643
|
best_cut = cut_value
|
|
645
644
|
a, b = bits
|
|
@@ -851,7 +850,7 @@ def tsp_asymmetric_header(G_m, nodes, quality, shots, anneal_t, anneal_h, repuls
|
|
|
851
850
|
for _ in range(multi_start):
|
|
852
851
|
bits = ([], [])
|
|
853
852
|
while (len(bits[0]) == 0) or (len(bits[1]) == 0):
|
|
854
|
-
_, cut_value, bits =
|
|
853
|
+
_, cut_value, bits, _ = spin_glass_solver((G_m + G_m.T) / 2, is_spin_glass=False, quality=quality, shots=shots, anneal_t=anneal_t, anneal_h=anneal_h, repulsion_base=repulsion_base)
|
|
855
854
|
if cut_value > best_cut:
|
|
856
855
|
best_cut = cut_value
|
|
857
856
|
a, b = bits
|
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
pyqrackising/__init__.py,sha256=
|
|
1
|
+
pyqrackising/__init__.py,sha256=MWxOmzFfQ2csz2A6o30Kf8zQvEtd996d3dz4kYaLtHM,898
|
|
2
2
|
pyqrackising/convert_tensor_network_to_tsp.py,sha256=55ajnvdBXFgf-Tx8Ck4i_tXOWULft3LZd_xz5Z6s4qw,3547
|
|
3
|
-
pyqrackising/generate_tfim_samples.py,sha256=
|
|
3
|
+
pyqrackising/generate_tfim_samples.py,sha256=NZh9dMW7RurMkfawFLdWI8WFZmXS5CTosTQDrwCBOSk,4503
|
|
4
4
|
pyqrackising/kernels.cl,sha256=YLWWyWxd38VzB_SbhSPaVtz0EHzLiat7oINtzR7moXQ,27861
|
|
5
5
|
pyqrackising/maxcut_tfim.py,sha256=U1nNjyfMS48TtTQk7TRf5_VF3pVPfAcZEa2awc2nR8k,10862
|
|
6
6
|
pyqrackising/maxcut_tfim_sparse.py,sha256=eenJNSEwRvgwACfKoH0tj6rpn7uqH6nNTBuxUPh_lDg,11941
|
|
7
7
|
pyqrackising/maxcut_tfim_streaming.py,sha256=FkBsRoXSRhv4gUeN9O7Ivx54oxq_SqiCDKnYsyxU4bs,6664
|
|
8
|
-
pyqrackising/maxcut_tfim_util.py,sha256=
|
|
8
|
+
pyqrackising/maxcut_tfim_util.py,sha256=D5tIbfKVLazR6f_INAoFypNJA0iuPin_bkiIM7-_pvg,16937
|
|
9
|
+
pyqrackising/otoc.py,sha256=IzARDeNvuGwL_RHBotQsth5d7iz5oGbsIharCrCLUyg,5620
|
|
9
10
|
pyqrackising/spin_glass_solver.py,sha256=tgmdJ6b1TetnFM--QEzOZFsNkquQYRVYiHVSzIGYvMI,14207
|
|
10
11
|
pyqrackising/spin_glass_solver_sparse.py,sha256=cmXfAR43n1beRk4LaQbwfrQWkkhMPzPXpdK2T1HhQrk,15159
|
|
11
12
|
pyqrackising/spin_glass_solver_streaming.py,sha256=joQLMKotgjQMwbG0msv_AookiWva_AiVBIR0Xr1Unho,10310
|
|
12
13
|
pyqrackising/tfim_magnetization.py,sha256=On1MhCNGGHRxJFRmCOpMcdqQJiy25gWkjz0Ka8i5f-Q,499
|
|
13
14
|
pyqrackising/tfim_square_magnetization.py,sha256=9uJCT8ytyufcGFrZiignjCkWJr9UcP44sAAy0BIBw34,531
|
|
14
|
-
pyqrackising/tsp.py,sha256=
|
|
15
|
+
pyqrackising/tsp.py,sha256=k8VK6fKw_niR-dVz8MyOT7LedABIwTzcSkhTOircYBg,64290
|
|
15
16
|
pyqrackising/tsp_maxcut.py,sha256=lEDruz5lhjVu0ufvH5VaMJW3_nohO-rEijJJabEtuSU,10084
|
|
16
|
-
pyqrackising-9.
|
|
17
|
-
pyqrackising-9.
|
|
18
|
-
pyqrackising-9.
|
|
19
|
-
pyqrackising-9.
|
|
20
|
-
pyqrackising-9.
|
|
17
|
+
pyqrackising-9.3.0.dist-info/licenses/LICENSE.md,sha256=fTqV5eBpeAZO0_jit8j4Ref9ikBSlHJ8xwj5TLg7gFk,7817
|
|
18
|
+
pyqrackising-9.3.0.dist-info/METADATA,sha256=wDNYY2jJvGgrFlue_d33vTrg26e1wZaQdSNigAlqqgA,1170
|
|
19
|
+
pyqrackising-9.3.0.dist-info/WHEEL,sha256=ZjXRCNaQ9YSypEK2TE0LRB0sy2OVXSszb4Sx1XjM99k,97
|
|
20
|
+
pyqrackising-9.3.0.dist-info/top_level.txt,sha256=bxlfGuLwzeVEI8Jm5D9HvC_WedgvvkSrpFwbGDjg-Ag,13
|
|
21
|
+
pyqrackising-9.3.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|