This repository was archived by the owner on Jul 25, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexperiments.py
More file actions
executable file
·87 lines (74 loc) · 2.53 KB
/
Copy pathexperiments.py
File metadata and controls
executable file
·87 lines (74 loc) · 2.53 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
import os, subprocess, multiprocessing, sys
import tempfile
import json
from datetime import datetime
import time
# get settings from command line
if len(sys.argv) < 3:
print("usage: test.py <directory> <timeout> <config file> <processes>? <codename>?")
problems = sys.argv[1]
srcdir = sys.argv[1]
timeout = sys.argv[2]
config_file = sys.argv[3]
numprocs = int(sys.argv[4]) if len(sys.argv) > 4 else 2
codename = sys.argv[5] if len(sys.argv) > 5 else "madmax"
tool = "./madmax"
jobs = []
def get_configs():
configs = []
for c in open(config_file, "r").readlines():
configs.append(c.rstrip())
return configs
def result_data(problem, result):
name = problem['file']
name = name[0:name.index('.')]
data = {"config": problem['config'], "result": result, "system": name}
return data
def error_data(problem):
return result_data(problem, "ERROR")
def timeout_data(problem):
return result_data(problem, "TIMEOUT")
def work(problem):
f = str(srcdir) + "/" + problem["file"]
config = problem['config']
with tempfile.NamedTemporaryFile() as temp:
cmd = "./sandbox {} {} {} {} > {}".format(timeout, tool, config, f, temp.name)
#print cmd
out,err = subprocess.Popen(cmd, shell=True).communicate()
file = open(temp.name, "r")
res = file.read()
code = "TIMEOUT" if "TIMEOUT" in res else "SUCCESS" if "YES" in res else "ERROR"
print(str(problem["number"]) + ": " + problem["file"] + " " + code)
if "TIMEOUT" in res:
return timeout_data(problem)
elif "YES" in res:
return json.loads(res)
else:
return error_data(problem)
def accumulate(results, configs):
t=datetime.fromtimestamp(time.time())
tstamp = t.strftime('%Y-%m-%d %H:%M')
data = {"timestamp": tstamp, "configurations": configs, "results": results}
res = json.dumps(data, sort_keys=True, indent=2)
rname = t.strftime('%Y-%m-%d') + codename + ".json"
rfile = open("results/"+rname, "w")
rfile.write(res)
if __name__ == "__main__":
# create job list
i = 0
configs = get_configs()
for subdir, dirs, problems in os.walk(problems):
for p in problems:
for c in configs:
job = { "number" : i, "file" : p, "config": c}
jobs.append(job)
i = i + 1
# run jobsfrom datetime import datetime
print("There are {} CPUs on this machine".format(multiprocessing.cpu_count()))
print("Doing {} jobs with {} processes".format(i,numprocs))
pool = multiprocessing.Pool(numprocs)
total_tasks = i
results = pool.map_async(work, jobs)
pool.close()
pool.join()
print accumulate(results.get(), configs)