Skip to content

Commit c83a606

Browse files
committed
Updating newtools
1 parent 15574bf commit c83a606

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

pygsti/extras/ml/newtools.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,26 @@
1414
from tensorflow import unique
1515
import tensorflow as _tf
1616

17+
def grid_adj_matrix(grid_width: int):
18+
num_qubits = grid_width**2
19+
adj_matrix = _np.zeros((num_qubits, num_qubits))
20+
for i in range(num_qubits):
21+
if i % grid_width == grid_width - 1 and i != grid_width*grid_width - 1:
22+
# far right column, not the bottom left corner
23+
# print(i)
24+
# print('first')
25+
adj_matrix[i, i+grid_width] = 1
26+
elif i // grid_width == grid_width - 1 and i != grid_width*grid_width - 1:
27+
# bottom row, not the bottom left corner
28+
adj_matrix[i, i+1] = 1
29+
elif i != num_qubits - 1:
30+
# print(i)
31+
# print('third')
32+
# not the bottom right corner
33+
adj_matrix[i, i+grid_width] = 1
34+
adj_matrix[i, i+1] = 1
35+
adj_matrix = adj_matrix + adj_matrix.T
36+
return adj_matrix
1737

1838
def ring_adj_matrix(num_qubits: int):
1939
adj_matrix = _np.zeros((num_qubits, num_qubits))

0 commit comments

Comments
 (0)