forked from L30nardoSV/reproduce-parcosi-moleculardocking
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathparse_adgpu_log.py
346 lines (302 loc) · 12.6 KB
/
parse_adgpu_log.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
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
import sys
import os
import re
import csv
import pandas as pd
def parse_filename(filename):
"""Parse file name"""
# Actual parsing
head, tail = os.path.split(filename)
name_field_list = tail.replace('.', '_')
name_field_list = name_field_list.split('_')
print(name_field_list)
def retrieve_runtimes(filename, is_print_enabled):
"""Retrieve runtimes (s) from log file"""
# Metacharacter "+" is escaped with preceding "\"
label_start_measurement = "\+ ./autodock_"
searchpattern_start_measurement = "^" + label_start_measurement
index_cmd_name_dlg = -4 # Negative index: starts count from last element
# *.dlg filename is parsed to extract execution information
index_dlg_device = 5
index_dlg_numwi = 6
index_dlg_version = 7
index_dlg_pdb = 8
index_dlg_ls = 9
# Metacharacter "." matches any character except newline character
label_time_setup = "Setup time"
searchpattern_time_setup = "." + label_time_setup
index_time_setup = 3
# Metacharacter "^" searches for a line starting with a given pattern
label_time_restofsetup = "Rest of Setup time"
searchpattern_time_restofsetup = "^" + label_time_restofsetup
index_time_restofsetup = 4
label_time_docking = "Docking time"
searchpattern_time_docking = "^" + label_time_docking
index_time_docking = 2
label_time_shutdown = "Shutdown time"
searchpattern_time_shutdown = "^" + label_time_shutdown
index_time_shutdown = 2
label_time_job = "Job #[0-9]"
searchpattern_time_job = "^" + label_time_job
index_time_job = 3
index_time_job_wait = 7
label_time_processing = "Processing time"
searchpattern_time_processing = "^" + label_time_processing
index_time_processing = 2
# Lists for collecting all measurements
num_of_entries_per_dlg = 40
num_measurements_per_entry = 12
num_elements_per_entry = num_measurements_per_entry
list_measurements = [['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'] for i in range(num_of_entries_per_dlg)]
#print(list_measurements)
with open(filename, "rt") as myfile: # open file for reading text
lines = myfile.readlines()
found_new_measurement = False
count_new_measurement = 0
for line in lines:
found_start_measurement = re.search(searchpattern_start_measurement, line)
found_time_setup = re.search(searchpattern_time_setup, line)
found_time_restofsetup = re.search(searchpattern_time_restofsetup, line)
found_time_docking = re.search(searchpattern_time_docking, line)
found_time_shutdown = re.search(searchpattern_time_shutdown, line)
found_time_job = re.search(searchpattern_time_job, line)
found_time_processing = re.search(searchpattern_time_processing, line)
if found_start_measurement:
print("\n")
found_new_measurement = True
print("# measurement: ", count_new_measurement)
split_line = re.split("\s", line) # Splits AD-GPU command based on the blank space character
name_dlg = split_line[index_cmd_name_dlg]
name_dlg = re.split("_", name_dlg) # Splits dlg filename based on the underscore "_" character
device = name_dlg[index_dlg_device]
numwi = name_dlg[index_dlg_numwi]
version = name_dlg[index_dlg_version]
pdb = name_dlg[index_dlg_pdb]
ls = name_dlg[index_dlg_ls]
list_measurements[count_new_measurement][0] = device
list_measurements[count_new_measurement][1] = numwi
list_measurements[count_new_measurement][2] = version
list_measurements[count_new_measurement][3] = pdb
list_measurements[count_new_measurement][4] = ls
if (is_print_enabled == True):
print("Device:\t", device)
print("NUMWI:\t", numwi)
print("Version:\t", version)
print("Test case:\t", pdb)
print("Local search:\t", ls)
if found_time_setup:
split_line = re.split("\s", line)
if split_line[0] != "Rest": # Avoids matching pattern "found_time_restofsetup"
time_setup = split_line[index_time_setup]
time_setup = re.sub("s$", " ", time_setup) # Replaces trailing "s" character with blank space
list_measurements[count_new_measurement][5] = time_setup
if (is_print_enabled == True):
print(split_line[0] + " " + label_time_setup, ":\t", time_setup) # Prints CUDA/OpenCL/DPC++ label at the beginning
if found_time_restofsetup:
split_line = re.split("\s", line)
time_restofsetup = split_line[index_time_restofsetup]
time_restofsetup = re.sub("s$", " ", time_restofsetup) # Replaces trailing "s" character with blank space
list_measurements[count_new_measurement][6] = time_restofsetup
if (is_print_enabled == True):
print(label_time_restofsetup, ":\t", time_restofsetup)
if found_time_docking:
split_line = re.split("\s", line)
time_docking = split_line[index_time_docking]
time_docking = re.sub("s$", " ", time_docking) # Replaces trailing "s" character with blank space
list_measurements[count_new_measurement][7] = time_docking
if (is_print_enabled == True):
print(label_time_docking, ":\t", time_docking)
if found_time_shutdown:
split_line = re.split("\s", line)
time_shutdown = split_line[index_time_shutdown]
time_shutdown = re.sub("s$", " ", time_shutdown) # Replaces trailing "s" character with blank space
list_measurements[count_new_measurement][8] = time_shutdown
if (is_print_enabled == True):
print(label_time_shutdown, ":\t", time_shutdown)
if found_time_job:
split_line = re.split("\s", line)
time_job = split_line[index_time_job]
time_job_wait = split_line[index_time_job_wait]
list_measurements[count_new_measurement][9] = time_job
list_measurements[count_new_measurement][10] = time_job_wait
if (is_print_enabled == True):
print("Job time", ":\t", time_job)
print("Job wait time", ":\t", time_job_wait)
if found_time_processing:
split_line = re.split("\s", line)
time_processing = split_line[index_time_processing]
list_measurements[count_new_measurement][11] = time_processing
if (is_print_enabled == True):
print(label_time_processing, ":\t", time_processing)
if found_new_measurement == True:
print(list_measurements[count_new_measurement])
found_new_measurement = False
count_new_measurement = count_new_measurement + 1
return list_measurements
def group_measurements(measurements):
#print(measurements)
# Indexes within measurement lists
index_device = 0
index_numwi = 1
index_version = 2
index_pdb = 3
index_ls = 4
index_time_setup = 5
index_time_restofsetup = 6
index_time_docking = 7
index_time_shutdown = 8
index_time_job = 9
index_time_job_wait = 10
index_processing = 11
# Sublists for Solis-Wets & ADADELTA
# Each sublist carries the entire entry for a pdb ordered by numwi
num_pdbs = 5
list_sw_1u4d, list_sw_1oyt, list_sw_1mzc, list_sw_3s8o, list_sw_2d1o = [['0', '0', '0', '0'] for i in range(num_pdbs)]
list_ad_1u4d, list_ad_1oyt, list_ad_1mzc, list_ad_3s8o, list_ad_2d1o = [['0', '0', '0', '0'] for i in range(num_pdbs)]
for idx in measurements:
pdb = idx[index_pdb]
numwi = idx[index_numwi]
ls = idx[index_ls]
time_docking = idx[index_time_docking]
if ls == 'sw':
if pdb == '1u4d':
if numwi == '32wi' : list_sw_1u4d[0] = idx
elif numwi == '64wi' : list_sw_1u4d[1] = idx
elif numwi == '128wi': list_sw_1u4d[2] = idx
elif numwi == '256wi': list_sw_1u4d[3] = idx
else: print('error')
elif pdb == '1oyt':
if numwi == '32wi' : list_sw_1oyt[0] = idx
elif numwi == '64wi' : list_sw_1oyt[1] = idx
elif numwi == '128wi': list_sw_1oyt[2] = idx
elif numwi == '256wi': list_sw_1oyt[3] = idx
else: print('error')
elif pdb == '1mzc':
if numwi == '32wi' : list_sw_1mzc[0] = idx
elif numwi == '64wi' : list_sw_1mzc[1] = idx
elif numwi == '128wi': list_sw_1mzc[2] = idx
elif numwi == '256wi': list_sw_1mzc[3] = idx
else: print('error')
elif pdb == '3s8o':
if numwi == '32wi' : list_sw_3s8o[0] = idx
elif numwi == '64wi' : list_sw_3s8o[1] = idx
elif numwi == '128wi': list_sw_3s8o[2] = idx
elif numwi == '256wi': list_sw_3s8o[3] = idx
else: print('error')
elif pdb == '2d1o':
if numwi == '32wi' : list_sw_2d1o[0] = idx
elif numwi == '64wi' : list_sw_2d1o[1] = idx
elif numwi == '128wi': list_sw_2d1o[2] = idx
elif numwi == '256wi': list_sw_2d1o[3] = idx
else: print('error')
else:
print('error!, \t%s, \t%f' %(pdb, time_docking))
elif ls == 'ad':
if pdb == '1u4d':
if numwi == '32wi' : list_ad_1u4d[0] = idx
elif numwi == '64wi' : list_ad_1u4d[1] = idx
elif numwi == '128wi': list_ad_1u4d[2] = idx
elif numwi == '256wi': list_ad_1u4d[3] = idx
else: print('error')
elif pdb == '1oyt':
if numwi == '32wi' : list_ad_1oyt[0] = idx
elif numwi == '64wi' : list_ad_1oyt[1] = idx
elif numwi == '128wi': list_ad_1oyt[2] = idx
elif numwi == '256wi': list_ad_1oyt[3] = idx
else: print('error')
elif pdb == '1mzc':
if numwi == '32wi' : list_ad_1mzc[0] = idx
elif numwi == '64wi' : list_ad_1mzc[1] = idx
elif numwi == '128wi': list_ad_1mzc[2] = idx
elif numwi == '256wi': list_ad_1mzc[3] = idx
else: print('error')
elif pdb == '3s8o':
if numwi == '32wi' : list_ad_3s8o[0] = idx
elif numwi == '64wi' : list_ad_3s8o[1] = idx
elif numwi == '128wi': list_ad_3s8o[2] = idx
elif numwi == '256wi': list_ad_3s8o[3] = idx
else: print('error')
elif pdb == '2d1o':
if numwi == '32wi' : list_ad_2d1o[0] = idx
elif numwi == '64wi' : list_ad_2d1o[1] = idx
elif numwi == '128wi': list_ad_2d1o[2] = idx
elif numwi == '256wi': list_ad_2d1o[3] = idx
else: print('error')
else:
print('error!, \t%s, \t%f' %(pdb, time_docking))
else:
print('error!, \t%s' %(ls))
# Reorder docking times
# Sublists: pdb vs docking times (R)
R_sw_1u4d, R_sw_1oyt, R_sw_1mzc, R_sw_3s8o, R_sw_2d1o = [['0', '0', '0', '0', '0'] for i in range(num_pdbs)]
R_ad_1u4d, R_ad_1oyt, R_ad_1mzc, R_ad_3s8o, R_ad_2d1o = [['0', '0', '0', '0', '0'] for i in range(num_pdbs)]
R_sw_1u4d[0] = R_ad_1u4d[0] = '1u4d'
R_sw_1oyt[0] = R_ad_1oyt[0] = '1oyt'
R_sw_1mzc[0] = R_ad_1mzc[0] = '1mzc'
R_sw_3s8o[0] = R_ad_3s8o[0] = '3s8o'
R_sw_2d1o[0] = R_ad_2d1o[0] = '2d1o'
# CAUTION
# Might need to replaced range(4) for range(1),
# as some folders might contain results only for one case (numwi=32)
# instead of four ones (numwi={32, 64, 128, 256})
for i in range(4):
# SW
R_sw_1u4d[i+1] = list_sw_1u4d[i][index_time_docking]
R_sw_1oyt[i+1] = list_sw_1oyt[i][index_time_docking]
R_sw_1mzc[i+1] = list_sw_1mzc[i][index_time_docking]
R_sw_3s8o[i+1] = list_sw_3s8o[i][index_time_docking]
R_sw_2d1o[i+1] = list_sw_2d1o[i][index_time_docking]
# AD
R_ad_1u4d[i+1] = list_ad_1u4d[i][index_time_docking]
R_ad_1oyt[i+1] = list_ad_1oyt[i][index_time_docking]
R_ad_1mzc[i+1] = list_ad_1mzc[i][index_time_docking]
R_ad_3s8o[i+1] = list_ad_3s8o[i][index_time_docking]
R_ad_2d1o[i+1] = list_ad_2d1o[i][index_time_docking]
#print(R_sw_1u4d)
#print(R_ad_1u4d)
# Grouping & returning reordered docking times
reordered_sw_time_docking = []
reordered_sw_time_docking = [R_sw_1u4d] + [R_sw_1oyt] + [R_sw_1mzc] + [R_sw_3s8o] + [R_sw_2d1o]
reordered_ad_time_docking = []
reordered_ad_time_docking = [R_ad_1u4d] + [R_ad_1oyt] + [R_ad_1mzc] + [R_ad_3s8o] + [R_ad_2d1o]
return reordered_sw_time_docking, reordered_ad_time_docking
def write_outputs(list_sw, list_ad):
filename_sw = 'dockingtime_sw'
filename_ad = 'dockingtime_ad'
file_sw_csv = filename_sw + '.csv'
file_ad_csv = filename_ad + '.csv'
file_sw_txt = filename_sw + '.txt'
file_ad_txt = filename_ad + '.txt'
file_sw_excel = filename_sw + '.xlsx'
file_ad_excel = filename_ad + '.xlsx'
with open(file_sw_csv, 'w', newline='') as file:
writer = csv.writer(file)
writer.writerow(["pdb", "32wi", "64wi", "128wi", "256wi"])
for row in list_sw:
writer.writerow(row)
with open(file_ad_csv, 'w', newline='') as file:
writer = csv.writer(file)
writer.writerow(["pdb", "32wi", "64wi", "128wi", "256wi"])
for row in list_ad:
writer.writerow(row)
# Changing file extension: from csv into txt
os.rename(file_sw_csv, file_sw_txt)
os.rename(file_ad_csv, file_ad_txt)
# Transforming files: from txt into excel
pd.read_csv(file_sw_txt, delimiter=",").to_excel(file_sw_excel, index=False)
pd.read_csv(file_ad_txt, delimiter=",").to_excel(file_ad_excel, index=False)
def main():
# First argument is the log file
log_file = sys.argv[1]
parse_filename(log_file)
# Extract measurements
measurements = []
measurements = retrieve_runtimes(log_file, False) # True
# Group measurements
reordered_sw_time_docking = []
reordered_ad_time_docking = []
reordered_sw_time_docking, reordered_ad_time_docking = group_measurements(measurements)
# Write output
write_outputs(reordered_sw_time_docking, reordered_ad_time_docking)
main()
#python3 parse_adgpu_log.py <log_file>