forked from locuslab/convex_adversarial
-
Notifications
You must be signed in to change notification settings - Fork 2
/
run.py
24 lines (17 loc) · 875 Bytes
/
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
import os
import subprocess
import argparse
def docker_run(cmd):
uid = int(subprocess.run(['id', '-u'], stdout=subprocess.PIPE).stdout)
gid = int(subprocess.run(['id', '-g'], stdout=subprocess.PIPE).stdout)
subprocess.run(['docker', 'build', '-t', 'convex_adversarial', '.'])
s = """docker run -it --runtime=nvidia --rm -w /home -v ${{PWD}}/nips/:/home/nips/ convex_adversarial zsh -c '{}; {}'"""
fix_permissions = 'chown -R {}:{} /home/nips/'.format(uid, gid)
os.system(s.format(cmd, fix_permissions))
if __name__ == "__main__":
uid = int(subprocess.run(['id', '-u'], stdout=subprocess.PIPE).stdout)
gid = int(subprocess.run(['id', '-g'], stdout=subprocess.PIPE).stdout)
parser = argparse.ArgumentParser()
parser.add_argument('cmd', type=str, help='command to run')
args = parser.parse_args()
docker_run(args.cmd)