-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun.py
More file actions
51 lines (41 loc) · 1.51 KB
/
run.py
File metadata and controls
51 lines (41 loc) · 1.51 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
import configparser
import re
import subprocess
import python.train
import time
import shutil
config = configparser.ConfigParser()
config.read('settings.ini')
docker_start_port = config.getint('docker', 'start_port')
num_threads = config.getint('control', 'num_threads')
with open('docker-compose.yml', 'r') as f:
contents = f.read()
pattern = r'(ports:\s*-\s*")(\d+)(-)(\d+):'
replacement = r'\g<1>' + str(docker_start_port) + r'\g<3>' + str(docker_start_port + num_threads - 1) + ':'
contents = re.sub(pattern, replacement, contents)
with open('docker-compose.yml', 'w') as f:
f.write(contents)
try:
print("Deleting game_logs dir")
shutil.rmtree('game_logs')
except FileNotFoundError:
pass
try:
print("Deleting models/docker dir")
shutil.rmtree('models/docker')
except FileNotFoundError:
pass
subprocess.run('docker-compose down', shell=True)
subprocess.run('docker-compose up -d --scale tensorflow_serving=' + str(num_threads), shell=True)
train = python.train.Train()
# give time for docker to update
time.sleep(1)
print('\n=============================== deeptile ' + str(0) + ' ==============================')
subprocess.run('./deeptile', shell=True)
for run in range(1, 10):
print('\n=============================== train ' + str(run) + ' ==============================')
train.iterate()
# give time for docker to update
time.sleep(1)
print('\n=============================== deeptile ' + str(run) + ' ==============================')
subprocess.run('./deeptile', shell=True)