PyQrackIsing 9.3.9__tar.gz → 9.3.11__tar.gz
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-9.3.9/pyqrackising.egg-info → pyqrackising-9.3.11}/PKG-INFO +1 -1
- {pyqrackising-9.3.9 → pyqrackising-9.3.11}/pyproject.toml +1 -1
- {pyqrackising-9.3.9 → pyqrackising-9.3.11}/pyqrackising/otoc.py +66 -54
- {pyqrackising-9.3.9 → pyqrackising-9.3.11/pyqrackising.egg-info}/PKG-INFO +1 -1
- {pyqrackising-9.3.9 → pyqrackising-9.3.11}/setup.py +1 -1
- {pyqrackising-9.3.9 → pyqrackising-9.3.11}/LICENSE.md +0 -0
- {pyqrackising-9.3.9 → pyqrackising-9.3.11}/MANIFEST.in +0 -0
- {pyqrackising-9.3.9 → pyqrackising-9.3.11}/README.md +0 -0
- {pyqrackising-9.3.9 → pyqrackising-9.3.11}/pyqrackising/__init__.py +0 -0
- {pyqrackising-9.3.9 → pyqrackising-9.3.11}/pyqrackising/convert_tensor_network_to_tsp.py +0 -0
- {pyqrackising-9.3.9 → pyqrackising-9.3.11}/pyqrackising/generate_tfim_samples.py +0 -0
- {pyqrackising-9.3.9 → pyqrackising-9.3.11}/pyqrackising/kernels.cl +0 -0
- {pyqrackising-9.3.9 → pyqrackising-9.3.11}/pyqrackising/maxcut_tfim.py +0 -0
- {pyqrackising-9.3.9 → pyqrackising-9.3.11}/pyqrackising/maxcut_tfim_sparse.py +0 -0
- {pyqrackising-9.3.9 → pyqrackising-9.3.11}/pyqrackising/maxcut_tfim_streaming.py +0 -0
- {pyqrackising-9.3.9 → pyqrackising-9.3.11}/pyqrackising/maxcut_tfim_util.py +0 -0
- {pyqrackising-9.3.9 → pyqrackising-9.3.11}/pyqrackising/spin_glass_solver.py +0 -0
- {pyqrackising-9.3.9 → pyqrackising-9.3.11}/pyqrackising/spin_glass_solver_sparse.py +0 -0
- {pyqrackising-9.3.9 → pyqrackising-9.3.11}/pyqrackising/spin_glass_solver_streaming.py +0 -0
- {pyqrackising-9.3.9 → pyqrackising-9.3.11}/pyqrackising/tfim_magnetization.py +0 -0
- {pyqrackising-9.3.9 → pyqrackising-9.3.11}/pyqrackising/tfim_square_magnetization.py +0 -0
- {pyqrackising-9.3.9 → pyqrackising-9.3.11}/pyqrackising/tsp.py +0 -0
- {pyqrackising-9.3.9 → pyqrackising-9.3.11}/pyqrackising/tsp_maxcut.py +0 -0
- {pyqrackising-9.3.9 → pyqrackising-9.3.11}/pyqrackising.egg-info/SOURCES.txt +0 -0
- {pyqrackising-9.3.9 → pyqrackising-9.3.11}/pyqrackising.egg-info/dependency_links.txt +0 -0
- {pyqrackising-9.3.9 → pyqrackising-9.3.11}/pyqrackising.egg-info/not-zip-safe +0 -0
- {pyqrackising-9.3.9 → pyqrackising-9.3.11}/pyqrackising.egg-info/top_level.txt +0 -0
- {pyqrackising-9.3.9 → pyqrackising-9.3.11}/setup.cfg +0 -0
|
@@ -10,7 +10,7 @@ build-backend = "setuptools.build_meta"
|
|
|
10
10
|
|
|
11
11
|
[project]
|
|
12
12
|
name = "pyqrackising"
|
|
13
|
-
version = "9.3.
|
|
13
|
+
version = "9.3.11"
|
|
14
14
|
requires-python = ">=3.8"
|
|
15
15
|
description = "Fast MAXCUT, TSP, and sampling heuristics from near-ideal transverse field Ising model (TFIM)"
|
|
16
16
|
readme = {file = "README.txt", content-type = "text/markdown"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
from .maxcut_tfim_util import probability_by_hamming_weight, sample_mag, opencl_context
|
|
2
2
|
from numba import njit
|
|
3
3
|
import numpy as np
|
|
4
|
-
import random
|
|
5
4
|
import sys
|
|
6
5
|
|
|
7
6
|
|
|
@@ -74,24 +73,65 @@ def fix_cdf(hamming_prob):
|
|
|
74
73
|
return cum_prob
|
|
75
74
|
|
|
76
75
|
|
|
77
|
-
def
|
|
78
|
-
for i in range(
|
|
79
|
-
|
|
80
|
-
|
|
76
|
+
def take_sample(n_qubits, sample, m, inv_dist):
|
|
77
|
+
indices = [i for i in range(n_qubits)]
|
|
78
|
+
tot_inv_dist = 0.0
|
|
79
|
+
for i in range(n_qubits):
|
|
80
|
+
tot_inv_dist += inv_dist[i]
|
|
81
|
+
selected = []
|
|
82
|
+
for i in range(m):
|
|
83
|
+
r = tot_inv_dist * np.random.random()
|
|
84
|
+
p = 0.0
|
|
85
|
+
idx = 0
|
|
86
|
+
while p < r:
|
|
87
|
+
p += inv_dist[indices[idx]]
|
|
88
|
+
idx += 1
|
|
89
|
+
i = indices[idx]
|
|
90
|
+
del indices[idx]
|
|
91
|
+
selected.append(i)
|
|
92
|
+
tot_inv_dist -= inv_dist[i]
|
|
93
|
+
for i in selected:
|
|
94
|
+
sample |= 1 << i
|
|
81
95
|
|
|
82
96
|
return sample
|
|
83
97
|
|
|
84
98
|
|
|
85
|
-
|
|
99
|
+
@njit
|
|
100
|
+
def factor_width(width):
|
|
101
|
+
col_len = np.floor(np.sqrt(width))
|
|
102
|
+
while ((width // col_len) * col_len) != width:
|
|
103
|
+
col_len -= 1
|
|
104
|
+
row_len = width // col_len
|
|
105
|
+
|
|
106
|
+
return row_len, col_len
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
# Provided by Google search AI
|
|
110
|
+
def find_all_str_occurrences(main_string, sub_string):
|
|
86
111
|
indices = []
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
112
|
+
start_index = 0
|
|
113
|
+
while True:
|
|
114
|
+
index = main_string.find(sub_string, start_index)
|
|
115
|
+
if index == -1:
|
|
116
|
+
break
|
|
117
|
+
indices.append(index)
|
|
118
|
+
start_index = index + 1 # Start searching after the found occurrence
|
|
93
119
|
|
|
94
|
-
return
|
|
120
|
+
return indices
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def get_inv_dist(butterfly_idx, n_qubits, row_len):
|
|
124
|
+
inv_dist = np.zeros(n_qubits, dtype=np.float64)
|
|
125
|
+
for idx in butterfly_idx:
|
|
126
|
+
for q in range(n_qubits):
|
|
127
|
+
b_row = idx // row_len
|
|
128
|
+
b_col = idx % row_len
|
|
129
|
+
q_row = q // row_len
|
|
130
|
+
q_col = q % row_len
|
|
131
|
+
dist = (q_row - b_row) ** 2 + (q_col - b_col) ** 2
|
|
132
|
+
inv_dist[q] += 1.0 / (1.0 + dist)
|
|
133
|
+
|
|
134
|
+
return inv_dist
|
|
95
135
|
|
|
96
136
|
|
|
97
137
|
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):
|
|
@@ -103,34 +143,24 @@ def generate_otoc_samples(J=-1.0, h=2.0, z=4, theta=0.174532925199432957, t=5, n
|
|
|
103
143
|
if len(measurement_basis) != n_qubits:
|
|
104
144
|
raise ValueError("OTOC measurement_basis must be same length as n_qubits! (Use 'I' for excluded qubits.)")
|
|
105
145
|
|
|
106
|
-
basis_x, basis_y, basis_z = [], [], []
|
|
107
|
-
for b in pauli_string:
|
|
108
|
-
if b == 'Z':
|
|
109
|
-
basis_z.append('X')
|
|
110
|
-
basis_y.append('I')
|
|
111
|
-
basis_x.append('Z')
|
|
112
|
-
elif b == 'X':
|
|
113
|
-
basis_z.append('Z')
|
|
114
|
-
basis_y.append('I')
|
|
115
|
-
basis_x.append('X')
|
|
116
|
-
elif b == 'Y':
|
|
117
|
-
basis_z.append('I')
|
|
118
|
-
basis_y.append('Z')
|
|
119
|
-
basis_x.append('I')
|
|
120
|
-
else:
|
|
121
|
-
basis_z.append('I')
|
|
122
|
-
basis_y.append('I')
|
|
123
|
-
basis_x.append('I')
|
|
124
|
-
|
|
125
|
-
bases = { 'X': basis_x, 'Y': basis_y, 'Z': basis_z }
|
|
126
146
|
thresholds = { key: fix_cdf(value) for key, value in get_otoc_hamming_distribution(J, h, z, theta, t, n_qubits, cycles, pauli_string).items() }
|
|
127
147
|
|
|
148
|
+
row_len, col_len = factor_width(n_qubits)
|
|
149
|
+
p_string = "".join(pauli_string)
|
|
150
|
+
butterfly_idx_x = find_all_str_occurrences(p_string, 'X')
|
|
151
|
+
butterfly_idx_y = find_all_str_occurrences(p_string, 'Y')
|
|
152
|
+
butterfly_idx_z = find_all_str_occurrences(p_string, 'Z')
|
|
153
|
+
|
|
154
|
+
inv_dist_x = get_inv_dist(butterfly_idx_x, n_qubits, row_len)
|
|
155
|
+
inv_dist_y = get_inv_dist(butterfly_idx_y, n_qubits, row_len)
|
|
156
|
+
inv_dist_z = get_inv_dist(butterfly_idx_z, n_qubits, row_len)
|
|
157
|
+
|
|
158
|
+
inv_dist = { 'X': inv_dist_x, 'Y': inv_dist_y, 'Z': inv_dist_z }
|
|
159
|
+
|
|
128
160
|
samples = []
|
|
129
161
|
for _ in range(shots):
|
|
130
162
|
sample_3_axis = { 'X': 0, 'Y': 0, 'Z': 0 }
|
|
131
163
|
for key, value in thresholds.items():
|
|
132
|
-
basis = bases[key]
|
|
133
|
-
|
|
134
164
|
# First dimension: Hamming weight
|
|
135
165
|
m = sample_mag(value)
|
|
136
166
|
if m == 0:
|
|
@@ -140,25 +170,7 @@ def generate_otoc_samples(J=-1.0, h=2.0, z=4, theta=0.174532925199432957, t=5, n
|
|
|
140
170
|
continue
|
|
141
171
|
|
|
142
172
|
# Second dimension: permutation within Hamming weight
|
|
143
|
-
|
|
144
|
-
if z_count > m:
|
|
145
|
-
sample_3_axis[key] = take_sample('Z', basis, sample_3_axis[key], m)
|
|
146
|
-
continue
|
|
147
|
-
m -= z_count
|
|
148
|
-
sample_3_axis[key] = take_all('Z', basis, sample_3_axis[key])
|
|
149
|
-
if m == 0:
|
|
150
|
-
continue
|
|
151
|
-
|
|
152
|
-
i_count = basis.count('I')
|
|
153
|
-
if i_count > m:
|
|
154
|
-
sample_3_axis[key] = take_sample('I', basis, sample_3_axis[key], m)
|
|
155
|
-
continue
|
|
156
|
-
m -= i_count
|
|
157
|
-
sample_3_axis[key] = take_all('I', basis, sample_3_axis[key])
|
|
158
|
-
if m == 0:
|
|
159
|
-
continue
|
|
160
|
-
|
|
161
|
-
sample_3_axis[key] = take_sample('X', basis, sample_3_axis[key], m)
|
|
173
|
+
sample_3_axis[key] = take_sample(n_qubits, sample_3_axis[key], m, inv_dist[key])
|
|
162
174
|
|
|
163
175
|
sample = 0
|
|
164
176
|
j = 0
|
|
@@ -7,7 +7,7 @@ with open(README_PATH) as readme_file:
|
|
|
7
7
|
|
|
8
8
|
setup(
|
|
9
9
|
name='pyqrackising',
|
|
10
|
-
version='9.3.
|
|
10
|
+
version='9.3.11',
|
|
11
11
|
author='Dan Strano',
|
|
12
12
|
author_email='stranoj@gmail.com',
|
|
13
13
|
description='Fast MAXCUT, TSP, and sampling heuristics from near-ideal transverse field Ising model (TFIM)',
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|