forked from QEC-pages/how-to-use-weilei-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocessing-codes.py
More file actions
executable file
·105 lines (88 loc) · 3.06 KB
/
Copy pathprocessing-codes.py
File metadata and controls
executable file
·105 lines (88 loc) · 3.06 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
#!python3
# processing the json files for CSS codes
import os #mv files
import fileinput #read (json) files
import json
import datetime
def dot_row(row):
s=''
for i in str(row):
if i == '0' or i == ',':
s += ' '
else:
s += i
return s
def pretty_2D_list(table):
n=0
string = ''
for row in table[n:]:
print(' n='+str(n)+':\t'+dot_row(row))
string += 'n='+str(n)+':\t'+dot_row(row) +'\n'
n+=1
return string
# print(row)
# print(''.join(str(row)))
# not in use. too slow compared to system bash commands
def get_json_list():
path_of_the_directory = '../data/CSS-Codes/run1'
ext = ('.json')
for files in os.scandir(path_of_the_directory):
if files.path.endswith(ext):
print(files)
print(files.name)
print(files.path[:-5])
break
#get_json_list()
#exit()
def main():
print(r''' This function exract max [n,k,d] and save d in a 2D array/list with respect to n and k.
Invalid json will be skipped and reported. They exist due to parallel file writing when generating codes on qlab''')
data_folder = "json1"
# data_folder = "codes"
data_folder = '../data/CSS-Codes/run2'
trash_folder = '../data/CSS-Codes/trash'
# filename_list = '../data/CSS-Codes/filelist-run1.txt'
filename_list = 'filelist-run2.txt' #./get-filelist.sh
log_file = 'run.log'
print('data_folder:\t'+data_folder)
print('trash_folder:\t'+trash_folder)
print('filename_list:\t'+filename_list)
print('log_file:\t'+log_file)
print(datetime.datetime.now())
num_of_codes=0
n,k,d=-1,-1,-1
max_distance_table=[[ 0 for k in range(28)] for n in range(31) ]
max_distance_table[0]=[_ % 10 for _ in range(28)]
# d=table[n][k]
for line in fileinput.input(filename_list):
num_of_codes += 1
if (num_of_codes % 10000 == 0):
print('finish processing '+str(num_of_codes)+' codes')
try:
with open(data_folder+'/'+ line[:-1]+'','r') as fjson:
js = json.load(fjson)
n,k,d=js['n'],js['k'],js['d']
if d > max_distance_table[n][k]:
max_distance_table[n][k] = d
except:
print('invalid json: '+line)
# move it to trash
os.system('mv '+ data_folder+'/'+ line[:-1]+' ' +data_folder+'/'+ line[:-6]+'Gx.mm '+data_folder+'/'+ line[:-6]+'Gz.mm ' +trash_folder)
print(line+' moved to trash')
print('[n,k,d] table')
string = pretty_2D_list(max_distance_table)
print(["total number of codes:", num_of_codes])
print(datetime.datetime.now())
with open(log_file,'a') as f:
f.write(string)
def test():
with open('codes/n15k3d2-x5z7dx3dz2-1.json','r') as fjson:
print(fjson.read())
js = json.load(fjson)
print(js)
n,k,d=js['n'],js['k'],js['d']
if d > max_distance_table[n][k]:
max_distance_table[n][k] = d
#test()
#exit()
main()