File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change 14
14
from tensorflow import unique
15
15
import tensorflow as _tf
16
16
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
17
37
18
38
def ring_adj_matrix (num_qubits : int ):
19
39
adj_matrix = _np .zeros ((num_qubits , num_qubits ))
You can’t perform that action at this time.
0 commit comments