-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript_reduced_chain_complex.py
More file actions
127 lines (114 loc) · 5.42 KB
/
script_reduced_chain_complex.py
File metadata and controls
127 lines (114 loc) · 5.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
"""script to test reduced chain complexes of pin codes
"""
from itertools import combinations
import numpy as np
from QuantumCodeConstruction.pincode import GrPoset, reduced_chain_complex, pincode, reduced_vec_to_flag_vec
from QuantumCodeConstruction.utils import readsparsematrix
from QuantumCodeAnalysis.QuantumCodeAnalysis import logicals # , low_weight_logical
TRANSITIONS = [readsparsematrix('BoundaryMaps/systematichp/systematic33_dim3_transpose_39_{}.sms'.format(j)).todense() for j in range(3)]
# TRANSITIONS = [readsparsematrix('BoundaryMaps/535_3420_{}.sms'.format(j)).todense().transpose() for j in range(1, 4)]
POSET = GrPoset(TRANSITIONS, iscomplete=False)
print('correct boundary map: {}'.format(POSET.check_boundary_map()))
PCX, PCZ = pincode(POSET, 1, 2)
RX, NQ = PCX.shape
print('correct boundary map: {}'.format(POSET.check_boundary_map()))
LX, LZ = logicals(PCX.todense(), PCZ.todense())
print(len(LX))
# print(PCX.todense())
# print(PCZ.todense())
print('Constructing reduced Z logicals')
XMAT0, ZMAT0, REDQ0 = reduced_chain_complex(POSET, (0,))
LX0, LZ0 = logicals(XMAT0, ZMAT0)
print(len(LZ0))
FLAGVECS0 = np.zeros((len(LZ0), NQ), dtype='uint8')
for j in range(len(LZ0)):
FLAGVECS0[j] = reduced_vec_to_flag_vec(POSET, LZ0[j], REDQ0)
print('are actual logicals if 0: {}'.format((np.dot(PCX.todense(), FLAGVECS0.transpose()) % 2).sum()))
XMAT1, ZMAT1, REDQ1 = reduced_chain_complex(POSET, (1,))
LX1, LZ1 = logicals(XMAT1, ZMAT1)
print(len(LZ1))
FLAGVECS1 = np.zeros((len(LZ1), NQ), dtype='uint8')
for j in range(len(LZ1)):
FLAGVECS1[j] = reduced_vec_to_flag_vec(POSET, LZ1[j], REDQ1)
print('are actual logicals if 0: {}'.format((np.dot(PCX.todense(), FLAGVECS1.transpose()) % 2).sum()))
XMAT2, ZMAT2, REDQ2 = reduced_chain_complex(POSET, (2,))
LX2, LZ2 = logicals(XMAT2, ZMAT2)
print(len(LZ2))
FLAGVECS2 = np.zeros((len(LZ2), NQ), dtype='uint8')
for j in range(len(LZ2)):
FLAGVECS2[j] = reduced_vec_to_flag_vec(POSET, LZ2[j], REDQ2)
print('are actual logicals if 0: {}'.format((np.dot(PCX.todense(), FLAGVECS2.transpose()) % 2).sum()))
XMAT3, ZMAT3, REDQ3 = reduced_chain_complex(POSET, (3,))
LX3, LZ3 = logicals(XMAT3, ZMAT3)
print(len(LZ3))
FLAGVECS3 = np.zeros((len(LZ3), NQ), dtype='uint8')
for j in range(len(LZ3)):
FLAGVECS3[j] = reduced_vec_to_flag_vec(POSET, LZ3[j], REDQ3)
print('are actual logicals if 0: {}'.format((np.dot(PCX.todense(), FLAGVECS3.transpose()) % 2).sum()))
print('Constructing reduced X logicals')
XMAT01, ZMAT01, REDQ01 = reduced_chain_complex(POSET, (0, 1))
LZ01, LX01 = logicals(XMAT01, ZMAT01)
print(len(LZ01))
FLAGVECS01 = np.zeros((len(LX01), NQ), dtype='uint8')
for j in range(len(LX01)):
FLAGVECS01[j] = reduced_vec_to_flag_vec(POSET, LX01[j], REDQ01)
print('are actual logicals if 0: {}'.format((np.dot(PCZ.todense(), FLAGVECS01.transpose()) % 2).sum()))
XMAT02, ZMAT02, REDQ02 = reduced_chain_complex(POSET, (0, 2))
LZ02, LX02 = logicals(XMAT02, ZMAT02)
print(len(LZ02))
FLAGVECS02 = np.zeros((len(LX02), NQ), dtype='uint8')
for j in range(len(LX02)):
FLAGVECS02[j] = reduced_vec_to_flag_vec(POSET, LX02[j], REDQ02)
print('are actual logicals if 0: {}'.format((np.dot(PCZ.todense(), FLAGVECS02.transpose()) % 2).sum()))
XMAT03, ZMAT03, REDQ03 = reduced_chain_complex(POSET, (0, 3))
LZ03, LX03 = logicals(XMAT03, ZMAT03)
print(len(LZ03))
FLAGVECS03 = np.zeros((len(LX03), NQ), dtype='uint8')
for j in range(len(LX03)):
FLAGVECS03[j] = reduced_vec_to_flag_vec(POSET, LX03[j], REDQ03)
print('are actual logicals if 0: {}'.format((np.dot(PCZ.todense(), FLAGVECS03.transpose()) % 2).sum()))
XMAT12, ZMAT12, REDQ12 = reduced_chain_complex(POSET, (1, 2))
LZ12, LX12 = logicals(XMAT12, ZMAT12)
print(len(LZ12))
FLAGVECS12 = np.zeros((len(LX12), NQ), dtype='uint8')
for j in range(len(LX12)):
FLAGVECS12[j] = reduced_vec_to_flag_vec(POSET, LX12[j], REDQ12)
print('are actual logicals if 0: {}'.format((np.dot(PCZ.todense(), FLAGVECS12.transpose()) % 2).sum()))
XMAT13, ZMAT13, REDQ13 = reduced_chain_complex(POSET, (1, 3))
LZ13, LX13 = logicals(XMAT13, ZMAT13)
print(len(LZ13))
FLAGVECS13 = np.zeros((len(LX13), NQ), dtype='uint8')
for j in range(len(LX13)):
FLAGVECS13[j] = reduced_vec_to_flag_vec(POSET, LX13[j], REDQ13)
print('are actual logicals if 0: {}'.format((np.dot(PCZ.todense(), FLAGVECS13.transpose()) % 2).sum()))
XMAT23, ZMAT23, REDQ23 = reduced_chain_complex(POSET, (2, 3))
LZ23, LX23 = logicals(XMAT23, ZMAT23)
print(len(LZ23))
FLAGVECS23 = np.zeros((len(LX23), NQ), dtype='uint8')
for j in range(len(LX23)):
FLAGVECS23[j] = reduced_vec_to_flag_vec(POSET, LX23[j], REDQ23)
print('are actual logicals if 0: {}'.format((np.dot(PCZ.todense(), FLAGVECS23.transpose()) % 2).sum()))
print('Checking tri-orthogonal condition for surface like X logicals: |L_j wedge L_k wedge S_l|')
REDLX = np.block([[FLAGVECS01], [FLAGVECS02], [FLAGVECS03], [FLAGVECS12], [FLAGVECS13], [FLAGVECS23]])
PCX = PCX.todense()
K, N = REDLX.shape
NSX, _ = PCX.shape
TRICOND = True
wrong = []
for ilog1, ilog2 in combinations(range(K), 2):
for istab in range(NSX):
TEST = np.multiply(REDLX[ilog1, :],
np.multiply(REDLX[ilog2, :],
PCX[istab, :])).sum() % 2 == 0
TRICOND = TRICOND and TEST
if not TEST:
wrong.append(((ilog1, ilog2), istab))
if wrong:
break
if wrong:
break
print('Triorthogonal: {}'.format(TRICOND))
if not TRICOND:
print(REDLX[wrong[0][0][0]])
print(REDLX[wrong[0][0][1]])
print(PCX[wrong[0][1]])