This repository was archived by the owner on Feb 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexperiments.py
57 lines (48 loc) · 2.1 KB
/
experiments.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
#!/usr/bin/env python3
import sys, os, datetime
from executor import execute
import time
import shlex
is_worktree_clean = execute("cd `git rev-parse --show-toplevel`; git diff-index --quiet HEAD -- src/ Cargo.toml nexmark/src/ nexmark/Cargo.toml", check=False)
if not is_worktree_clean:
shall = input("Work directory dirty. Continue? (y/N) ").lower() == 'y'
if not shall:
sys.exit(1)
current_commit = ("dirty-" if not is_worktree_clean else "") + execute("git rev-parse HEAD", capture=True)
current_commit = current_commit[:16]
def eprint(*args, level=None):
attr = []
if level == "info":
attr.append('1')
attr.append('37')
attr.append('4')
elif level == "run":
attr.append('32')
print("[" + datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") + "] ", '\x1b[%sm' % ';'.join(attr), *args, '\x1b[0m', file=sys.stderr, sep='')
def ensure_dir(name):
if not os.path.exists(name):
os.makedirs(name)
def wait_all(processes):
for p in processes:
# p.wait(use_spinner=False)
while p.is_running:
time.sleep(.1)
p.check_errors()
eprint("commit: {}".format(current_commit))
# assumes the experiment code is at this path on the cluster machine(s)
cluster_src_path = None
# cluster_server = "username@server"
cluster_server = None
def run_cmd(cmd, redirect=None, stderr=False, background=False, node="", dryrun=False):
full_cmd = "cd {}; {}".format(cluster_src_path, cmd)
# eprint("running on {}{}: {}".format(cluster_server, node, full_cmd))
# if redirect is not None and os.path.exists(redirect):
# return execute("echo \"skipping {}\"".format(redirect), async=background)
cmd = "ssh -o StrictHostKeyChecking=no -T {}{}.ethz.ch {}".format(cluster_server, node, shlex.quote(full_cmd))\
+ (" > {}".format(shlex.quote(redirect)) if redirect else "")\
+ (" 2> {}".format(shlex.quote(stderr)) if stderr else "")
eprint("$ {}".format(cmd), level="run")
if dryrun:
return execute("echo dryrun {}".format(node), async=background)
else:
return execute(cmd, async=background)