-
Notifications
You must be signed in to change notification settings - Fork 0
/
script_analysis.py
96 lines (86 loc) · 3.59 KB
/
script_analysis.py
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
"""Script to analyse codes
"""
import sys
from itertools import combinations
import numpy as np
from QuantumCodeAnalysis.QuantumCodeAnalysis import low_weight_logical, logicals
from QuantumCodeConstruction.utils import readsparsematrix
np.set_printoptions(threshold=sys.maxsize)
goodones = []
for SEED in range(1, 2): # 2**9-1):
# if SEED == 1097:
# continue
# MX = readsparsematrix('PCMatrices/systematichp/systematic33_dim3_transpose_{}_X.sms'.format(SEED)).todense()
# MZ = readsparsematrix('PCMatrices/systematichp/systematic33_dim3_transpose_{}_Z.sms'.format(SEED)).todense()
# MX = readsparsematrix('PCMatrices/randomhp/randomhp_swap_{}_X.sms'.format(SEED)).todense()
# MZ = readsparsematrix('PCMatrices/randomhp/randomhp_swap_{}_Z.sms'.format(SEED)).todense()
# MZ = readsparsematrix('PCMatrices/color_code_535/6840_abcbadcbabadcbabadcbadcbabdcbabdX.sms').todense()
# MX = readsparsematrix('PCMatrices/color_code_535/6840_abcbadcbabadcbabadcbadcbabdcbabdZ.sms').todense()
MZ = readsparsematrix('PCMatrices/narrowCC/narrowCC_2224_(12)_dim3_X.sms').todense()
MX = readsparsematrix('PCMatrices/narrowCC/narrowCC_2224_(12)_dim3_Z.sms').todense()
# MZ = readsparsematrix('PCMatrices/535_6840_Z.sms').todense()
# MX = readsparsematrix('PCMatrices/535_6840_X.sms').todense()
print('Properties of the code narrowCC_2224_(12)_dim3:{}'.format(' '))
print('X-check matrix is {}x{}'.format(MX.shape[0], MX.shape[1]))
print(MX)
print('Z-check matrix is {}x{}'.format(MZ.shape[0], MZ.shape[1]))
print(MZ)
XW = {MX[j, :].sum() for j in range(MX.shape[0])}
ZW = {MZ[j, :].sum() for j in range(MZ.shape[0])}
print('X-checks have weights: {}'.format(XW))
print('Z-checks have weights: {}'.format(ZW))
LX, LZ = logicals(MX, MZ)
if LX:
LX = np.vstack(LX)
LZ = np.vstack(LZ)
GX = np.block([[LX], [MX]])
GZ = np.block([[LZ], [MZ]])
else:
print('Zero logical operator !')
continue
print('There are {} logical qubits'.format(LX.shape[0]))
print('logical X')
print(LX)
LOWX, PERMX = low_weight_logical(GX, LZ, 1)
print('logical Z')
print(LZ)
LOWZ, PERMZ = low_weight_logical(GZ, LX, 1)
print('There is a X-logical operator of weight {}'.format(LOWX.sum()))
print(LOWX)
print('There is a Z-logical operator of weight {}'.format(LOWZ.sum()))
print(LOWZ)
print('Check correct x log: {}'.format((np.dot(MZ[:, PERMX], LOWX) % 2).sum() == 0))
print('Check correct z log: {}'.format((np.dot(MX[:, PERMZ], LOWZ) % 2).sum() == 0))
print('Checking tri-orthogonal condition |L_j wedge L_k wedge S_l|')
K, N = LX.shape
NSX, _ = MX.shape
TRICOND = True
wrong = []
for ilog1, ilog2 in combinations(range(K), 2):
for istab in range(NSX):
TEST = np.multiply(LX[ilog1, :],
np.multiply(LX[ilog2, :],
MX[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 TRICOND:
goodones.append(SEED)
print(len(wrong))
# print(goodones)
# print(LX[wrong[0][0][0], :])
# print(LX[wrong[0][0][1], :])
# print(MX[wrong[0][1], :])
# a = wrong[0][0][0]
# b = wrong[0][0][1]
# c = wrong[0][1]
# count = 0
# for j in range(N):
# count += LX[a, j]*LX[b, j]*MX[c, j]
# print(LX[a, j], LX[b, j], MX[c, j])
# print(count)