-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript_analyse_all.py
More file actions
120 lines (97 loc) · 3.97 KB
/
script_analyse_all.py
File metadata and controls
120 lines (97 loc) · 3.97 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
"""Script to analyse all codes
"""
from itertools import combinations
import os
import re
import json
import numpy as np
from QuantumCodeAnalysis.QuantumCodeAnalysis import low_weight_logical, logicals, distance_lower_bound
from QuantumCodeConstruction.utils import readsparsematrix
from flinalg import invert_permutation
PATHSYSTEMATICHP = 'PCMatrices/systematichp/'
PATHSYSTEMATICHP43 = 'PCMatrices/systematichp43/toanalyse/'
PATHNARROWCC = 'PCMatrices/narrowCC/'
PATHWEIRD = 'PCMatrices/weirdcoxeter/'
PATH535 = 'PCMatrices/color_code_535/'
PATH353 = 'PCMatrices/color_code_353/'
PATHPUNCTURED = 'PCMatrices/punctured/'
PATH = PATHWEIRD
RULE = re.compile(r'(.*)[XZ]\.sms')
# FILESET = {RULE.match(f).group(1) for f in os.listdir(PATH) if '(33)' in f}
FILESET = {RULE.match(f).group(1) for f in os.listdir(PATH)}
NTRIAL = 200
for FILEPREFIX in FILESET:
PROPDICT = {}
print('Computing properties of code ' + FILEPREFIX + ':')
print('Loading check matrices')
MX = readsparsematrix(PATH + FILEPREFIX + 'X.sms').todense()
MZ = readsparsematrix(PATH + FILEPREFIX + 'Z.sms').todense()
NX, NQ = MX.shape
NZ, _ = MZ.shape
print('Checking CSS condition')
CSSCOND = (np.dot(MX, MZ.transpose()) % 2).sum() == 0
PROPDICT['CSS'] = int(CSSCOND)
PROPDICT['n'] = int(NQ)
PROPDICT['num X-checks'] = int(NX)
PROPDICT['num Z-checks'] = int(NZ)
print('computing stabilizer weigths')
XW = {MX[j, :].sum() for j in range(MX.shape[0])}
ZW = {MZ[j, :].sum() for j in range(MZ.shape[0])}
PROPDICT['X-checks weights'] = [int(w) for w in XW]
PROPDICT['Z-checks weights'] = [int(w) for w in ZW]
print('Computing logical operators')
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]])
K, _ = LX.shape
PROPDICT['k'] = int(K)
else:
print('Zero logical operator !')
PROPDICT['k'] = int(0)
with open('CodeParameters/' + FILEPREFIX + '.txt', 'w') as dictfile:
print('writing properties to file')
dictfile.write(json.dumps(PROPDICT))
continue
print('Finding distance upper bound')
LOWX, PERMX = low_weight_logical(GX, LZ, NTRIAL)
LOWZ, PERMZ = low_weight_logical(GZ, LX, NTRIAL)
DXUP = (LOWX % 2).sum()
DZUP = (LOWZ % 2).sum()
PROPDICT['dx upper bound'] = int(DXUP)
PROPDICT['small X logical'] = [int(b) for b in LOWX[invert_permutation(PERMX)]]
PROPDICT['dz upper bound'] = int(DZUP)
PROPDICT['small Z logical'] = [int(b) for b in LOWZ[invert_permutation(PERMZ)]]
DXCOND = (np.dot(MZ[:, PERMX], LOWX) % 2).sum() == 0
DXCOND = DXCOND and ((np.dot(LZ[:, PERMX], LOWX) % 2).sum() != 0)
DZCOND = (np.dot(MX[:, PERMZ], LOWZ) % 2).sum() == 0
DZCOND = DZCOND and ((np.dot(LX[:, PERMZ], LOWZ) % 2).sum() != 0)
PROPDICT['valid dx upper bound'] = int(DXCOND)
PROPDICT['valid dz upper bound'] = int(DZCOND)
# print('checking distance larger than 3')
# DZMORETHAN2, W2Z = distance_lower_bound(MX, LX, 3)
# DXMORETHAN2, W2X = distance_lower_bound(MZ, LZ, 3)
# PROPDICT['dz > 3'] = int(DZMORETHAN2)
# if not DZMORETHAN2:
# PROPDICT['small Z logical'] = list(W2Z)
# PROPDICT['dx > 3'] = int(DXMORETHAN2)
# if not DXMORETHAN2:
# PROPDICT['small X logical'] = list(W2X)
print('Checking triorthogonality')
TRICOND = True
for ilog1, ilog2 in combinations(range(K), 2):
for istab in range(NX):
TEST = np.multiply(LX[ilog1, :],
np.multiply(LX[ilog2, :],
MX[istab, :])).sum() % 2 == 0
TRICOND = TRICOND and TEST
if not TRICOND:
break
if not TRICOND:
break
PROPDICT['triorthogonal'] = int(TRICOND)
with open('CodeParameters/' + FILEPREFIX + '.txt', 'w') as dictfile:
print('writing properties to file')
dictfile.write(json.dumps(PROPDICT))