-
Notifications
You must be signed in to change notification settings - Fork 7
/
run.py
54 lines (43 loc) · 1.47 KB
/
run.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
#!/usr/bin/python3
import yaml
import sys
import subprocess
import os
if len(sys.argv) < 2:
print(f"Usage: {sys.argv[0]} <the yaml file to run> <optinal additional arguments>")
sys.exit(-1)
with open(sys.argv[1]) as f:
config = yaml.safe_load(f)
args = []
for p, pval in config["parameters"].items():
if p in ["log", "sweep_id_for_grid_search"]:
continue
args.append("-" + p)
if "value" in pval:
assert "values" not in pval
args.append(pval["value"])
elif "values" in pval:
if len(pval["values"]) == 1:
args.append(pval["values"][0])
else:
while True:
print(f"Choose value for \"{p}\"")
for i, v in enumerate(pval["values"]):
print(f" {i+1}: {v}")
choice = input("> ")
if not choice.isdigit() or int(choice) < 1 or int(choice) > len(pval["values"]):
print("Invalid choice.")
continue
args.append(pval["values"][int(choice) - 1])
break
if "name" not in config["parameters"]:
args.append("-name")
args.append(os.path.basename(sys.argv[1]).replace(".yaml", ""))
replace = {
"${env}": "",
"${program}": config["program"],
"${args}": " ".join([str(a) for a in args])
}
cmd = (" ".join([replace.get(c, c) for c in config["command"]])).strip() + " " + " ".join(sys.argv[2:])
print(f"Running {cmd}")
subprocess.run(cmd, shell=True)