-
Notifications
You must be signed in to change notification settings - Fork 0
/
extractor.py
142 lines (130 loc) · 5.29 KB
/
extractor.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
"""@package extractor
uses regular expression to extract results from pimpact resuls and stores them
in numpy array files
TODO: include string variables for recurrin patterns
"""
import re
import numpy
INF = 1e9999
# helper string
FLOAT_STR = r"[\-]{0,1}\d+.{0,1}\d+e{0,1}[-+]{0,1}\d*"
INT_STR = r"\d+"
# lin solver
BelosIterPattern = re.compile(
r"Iter[ ]+(" + INT_STR + r"), \[ +" + INT_STR + r"\] : (" + FLOAT_STR +
r")")
BelosMaxItPattern = re.compile(
r"\s+[OK,Failed]+[.]+Number of Iterations = (" + INT_STR + r") [<=]+ " +
INT_STR)
BelosArTolPattern = re.compile(
r"\s+residual \[ " + INT_STR + r" \] = (" + FLOAT_STR + r") [<>] ")
# nonlin solver
NOXIterPattern = re.compile(r"-- Nonlinear Solver Step (" + INT_STR + r") -- ")
NOXResPattern = re.compile(
r"\|\|F\|\| = (" + FLOAT_STR + r") step = " + r"(" + FLOAT_STR +
r") dx = ([\-]{0,1}\d+\.\d+[e]{0,1}[-+]\d+)[^\d]*")
PimpOmPattern = re.compile(r" \tomega=(\d+.{0,1}\d*)")
PimpDofPattern = re.compile(r"\t--- Nf: \d+\tdof: (\d+)\t---")
PimpNfPattern = re.compile(r"\t--- Nf: (\d)+\tdof: \d+\t---")
PimpRefPattern = re.compile(
r"\|\|u\[nf\]\|\|/\|\|u\[1\]\|\| = (\d+.{0,1}\d*e{0,1}[-,+]{0,1}\d*)")
# timer
PimpSolveTimePattern = re.compile(
r"Pimpact:: Solving Time\s+(\d+.{0,1}\d*e{0,1}[-,+]{0,1}\d*) \(\d+\)")
PimpSolveTime = re.compile(
r"Pimpact:: Solving Time\s+(\d+.{0,1}\d*e{0,1}[-,+]{0,1}\d*) " +
r"\((\d+)\)\s+(\d+.{0,1}\d*e{0,1}[-,+]{0,1}\d*) \((\d+)\)\s+" +
r"(\d+.{0,1}\d*e{0,1}[-,+]{0,1}\d*) \((\d+)\)\s+(\d+.{0,1}\d*" +
r"e{0,1}[-,+]{0,1}\d*) \((\d+)\)")
NOXCompFTime = re.compile(
r"NOX: compute F\s+(" + FLOAT_STR + r") \((" + INT_STR + r")\)\s+(" +
FLOAT_STR + r") \((" + INT_STR + r")\)\s+(" + FLOAT_STR + r") \((" +
INT_STR + r")\)\s+(" + FLOAT_STR + r") \((" + INT_STR + r")\)")
NOXSolveDXTime = re.compile(
r"NOX: solve dx\s+(" + FLOAT_STR + r") \((" + INT_STR + r")\)\s+(" +
FLOAT_STR + r") \((" + INT_STR + r")\)\s+(" + FLOAT_STR + r") \((" +
INT_STR + r")\)\s+(" + FLOAT_STR + r") \((" + INT_STR + r")\)")
NOXUpdateXTime = re.compile(
r"NOX: update X\s+(" + FLOAT_STR + r") \((" + INT_STR + r")\)\s+(" +
FLOAT_STR + r" ) \((" + FLOAT_STR + r") \((" + INT_STR + r")\)\s+(" +
FLOAT_STR + r") \((" + INT_STR + r")\)")
BelosTotTime = re.compile(
r"Compound\( MHDtConvectionDiffusion\, MH_Grad\, MH_Div \): " +
r"BlockGmresSolMgr total solve time\s+(" + FLOAT_STR + r") \((" + INT_STR +
r")\)\s+(" + FLOAT_STR + r") \((" + INT_STR + r")\)\s+(" + FLOAT_STR +
r") \((" + INT_STR + r")\)\s+(" + FLOAT_STR + r") \((" + INT_STR + r")\)")
FTime = re.compile(
r"MHDtConvectionDiffusion: BlockGmresSolMgr total solve time\s+" +
FLOAT_STR + r" \(" + INT_STR + r"\)\s+" + FLOAT_STR + r" \(" + INT_STR +
r"\)\s+" + FLOAT_STR + r" \(" + INT_STR + r"\)\s+(" + FLOAT_STR + r") \(("
+ INT_STR + r")\)")
DivGradTime = re.compile(
r"DivGrad: BlockGmresSolMgr total solve time\s+" + FLOAT_STR + r" \(" +
INT_STR + r"\)\s+" + FLOAT_STR + r" \(" + INT_STR + r"\)\s+" + FLOAT_STR +
r" \(" + INT_STR + r"\)\s+(" + FLOAT_STR + r") \((" + INT_STR + r")\)")
FZTime = re.compile(
r"ConvectionDiffusionVOp: BlockGmresSolMgr total solve time\s+" + FLOAT_STR
+ r" \(" + INT_STR + r"\)\s+" + FLOAT_STR + r" \(" + INT_STR + r"\)\s+" +
FLOAT_STR + r" \(" + INT_STR + r"\)\s+(" + FLOAT_STR + r") \((" + INT_STR +
r")\)")
def extract(datafile, pattern, isfloat=True, isarray=True, outfile=''):
""" extractor function """
m = pattern.groups
try:
data = open(datafile).read()
except:
print('Error: couldnot open file:', datafile)
raise
#return ['*']
dat = []
for line in data.split("\n"):
match = pattern.match(line)
if match:
dat.append(match.groups())
#print( dat )
n = len(dat)
#print( n )
out = numpy.empty([n, m])
for i in range(n):
for j in range(m):
if isfloat:
out[i][j] = float(dat[i][j])
else:
out[i][j] = int(dat[i][j])
if len(outfile) != 0:
numpy.save(outfile, out)
#print 'n:',n,'m:',m
#if( n==1 ):
#out = out[0]
#if(m==1):
#out = out[0]
#print 'out:',out
return out
# what we're gonna do, is search through it line-by-line
# and parse out the numbers, using regular expressions
# what this basically does is, look for any number of characters
# that aren't digits or '-' [^-\d] ^ means NOT
# then look for 0 or 1 dashes ('-') followed by one or more decimals
# and a dot and decimals again: [\-]{0,1}\d+\.\d+
# and then the same as first..
def extracttime(path):
""" extracts time """
pattern = re.compile(r'elapsed time \[sec\] (\d\.\d+E[-,+]\d+)')
time = extract(path+'/test_wallclocktime_restart000.txt',
pattern, isarray=False)
return time
def extractmint(path, runs):
""" extract minimum from multiple runs """
time = INF
fails = 0
for run in runs:
tnew = extracttime(path+'/run'+str(run))
time = min(time, tnew)
if tnew == INF:
fails += 1
# print '\t', float(run)/(len(runs)-1)*100., '% failed'
# else:
# print '\t', float(run)/(len(runs)-1)*100., '% done'
print(fails, 'fails of', len(runs))
print()
return time