-
Notifications
You must be signed in to change notification settings - Fork 2
/
containertest.py
executable file
·83 lines (71 loc) · 2.32 KB
/
containertest.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python3
# STAGES=( "0" "1_000" "10_000" "25_000" "50_000" "100_000" "250_000" "500_000" "1_000_000" "2_500_000" "5_000_000" )
# for STAGE in "${STAGES[@]}"
# do
# echo "Running stage $STAGE"
# echo "$STAGE" > ./containers/cfg.txt
# ./experiment.sh 10.35.6.3 containers
# done
import os
import logging
import random
import subprocess
if __name__ == "__main__":
logging.basicConfig(
level=logging.INFO, format="%(asctime)s:%(levelname)s:%(filename)s: %(message)s"
)
# STAGES = [
# 0,
# 1,
# 5,
# 10,
# 25,
# 50,
# 100,
# 250,
# 500,
# 1_000,
# ] + list(range(0, 1000, 100))
STAGES = list(range(0, 1000, 100)) + [1_000]
REPEATS = 10
experiments = [
{
"stage": stage,
"repeat": i + 1,
}
for stage in STAGES
for i in range(REPEATS)
]
# randomize
random.shuffle(experiments)
for i in range(10):
# just repeat this a bunch of times to make sure all experiments have run
for experiment in experiments:
output_file = (
f"./containers/out/{experiment['stage']}_{experiment['repeat']}.out"
)
# if there is already an output file, skip
if os.path.exists(output_file):
logging.info(f"Skipping experiment {experiment}")
continue
logging.info(f"Running experiment {experiment}")
with open("./containers/cfg.txt", "w") as f:
f.write(f"{experiment['stage']}\n")
# ./experiment.sh 10.35.6.3 containers
# redirect stdout to stdout
p = subprocess.run(
["./experiment.sh", "10.35.6.3", "containers"],
# stdout=subprocess.STDOUT,
# stderr=subprocess.STDOUT,
)
if p.returncode != 0:
logging.error(f"Experiment {experiment} failed")
continue
# output goes into the containers/out directory
os.makedirs("./containers/out", exist_ok=True)
# take the ./containers/gst-HKPU.out file and move it
os.rename(
"./containers/gst-HKPU.out",
output_file,
)
logging.info("All experiments completed")