-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathevaluate_qor.py
68 lines (44 loc) · 1.72 KB
/
evaluate_qor.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
# This script is used to generate the lib_tuples.cpp file
import gzip
import json
import uuid
import argparse
from autoax import Config
import os
def main():
p = argparse.ArgumentParser()
p.add_argument('config', help='Config file (yaml)')
p.add_argument('dataset', help='Dataset file form results (e.g. random)')
args = p.parse_args()
c = Config(args.config)
lib_tuples = os.path.join(c.cwd, c.config["evaluate_lib"])
c.block_on_result(filename=lib_tuples, relative=False)
fn = c.result_path(args.dataset + ".json.gz")
print(f"# Reading {fn}")
data = json.load(gzip.open(fn))
cfile = ["// generated by " + __file__ +
" from " + args.config + " and " + args.dataset]
for i in data:
setting = {"name": i}
funs = []
for k, lib in c.components().items():
funs.append(lib[data[i][k]]["cfun"])
cfile.append(" ops[\"%(name)s\"] = make_tuple(%(funs)s);" % {
"name": i, "funs": ", ".join(funs)})
# "op1": data[i]["circ"]["opAdd1"]["cfun"],
# "op2": data[i]["circ"]["opAdd2"]["cfun"],
# "op3": data[i]["circ"]["opAdd3"]["cfun"],
# "op4": data[i]["circ"]["opAdd4"]["cfun"],
# "op5": data[i]["circ"]["opSub1"]["cfun"]
# }
# cfile.append(
# " ops[\"%(name)s\"] = make_tuple(%(op1)s, %(op2)s, %(op3)s, %(op4)s, %(op5)s);" % setting)
print("# Creating " , lib_tuples )
open(lib_tuples, "w").write(
"\n".join(cfile))
run_list = c.result_path(args.dataset + ".runlist")
print("# Creating " , run_list )
open(run_list, "w").write(
"\n".join(data.keys()))
if __name__ == "__main__":
main()