-
Notifications
You must be signed in to change notification settings - Fork 1
/
dump.py
94 lines (77 loc) · 2.63 KB
/
dump.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
from __future__ import print_function
from StringIO import StringIO
import optparse
from memsim import database, lex, model
from memsim.memory import memlist
parser = optparse.OptionParser()
parser.add_option('-u', '--url', dest='url', default=None,
help='database URL')
parser.add_option('-s', '--show', default=False, action='store_true',
help='show results')
parser.add_option('-m', '--memory', default=False, action='store_true',
help='dump memory spec')
def print_print_ml(ml):
s = str(ml)
return s.replace(') (', ')\n (')
def get_name_map(db, experiments):
names = dict()
for name in experiments:
try:
with open(name, 'r') as f:
m = model.parse_model(lex.Lexer(f))
key = db.get_hash(m)
names[key] = name
except:
pass
return names
def show_state(db, experiments):
names = get_name_map(db, experiments)
for mname, label, evals in db.get_status():
key = db.get_hash(mname)
if key in names:
print(label)
best_name, best_value, best_cost = db.get_best(mname)
print(' Hash: ', db.get_hash(mname))
print(' Iter: ', evals)
print(' Best: ', print_print_ml(best_name))
print(' Value:', best_value)
print(' Cost: ', best_cost)
print()
def dump_spec(db, experiments):
names = get_name_map(db, experiments)
for mname, _, _ in db.get_status():
key = db.get_hash(mname)
if key in names:
bname, _, _ = db.get_best(mname)
m = model.parse_model(lex.Lexer(StringIO(mname)))
m.memory = memlist.parse_memory_list(lex.Lexer(StringIO(bname)))
print(m)
def show_pending(db, experiments):
names = get_name_map(db, experiments)
for mname, label, evals in db.get_status():
key = db.get_hash(mname)
if key in names:
best_name, best_value, best_cost = db.get_best(mname)
name = names[key]
pad1 = max(32 - len(name), 0)
pad2 = max(8 - len(str(evals)), 0)
strs = [
name,
':',
' ' * pad1,
str(evals),
' ' * pad2,
str(best_value),
]
print(''.join(strs))
def main():
options, args = parser.parse_args()
db = database.get_instance(options.url)
if options.show:
show_state(db, args)
elif options.memory:
dump_spec(db, args)
else:
show_pending(db, args)
if __name__ == '__main__':
main()