-
Notifications
You must be signed in to change notification settings - Fork 1
/
run_model.py
executable file
·74 lines (51 loc) · 2.1 KB
/
run_model.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
#!/usr/bin/python3
from fluid_model.names import *
from fluid_model.compute_trace import *
from fluid_model.process_trace import *
from fluid_model.cc import reno
from fluid_model.helpers import *
import sys
import os
import argparse
import random
import copy
import string
from datetime import datetime
# -----------------------------------------------------------------------------
# Use Python implementation for computing trace (slow but easy to debug)
def run_model_for_config(cfg, dump_trace_flag=True, plot_trace_flag=True):
analysis_results = []
result_file_name = cfg['result_folder'] + datetime.strftime(datetime.now(), "%Y-%m-%d--%H-%M-%S") + '.json'
if not os.path.exists(cfg['result_folder'] + 'traces/'):
os.mkdir(cfg['result_folder'] + 'traces/')
for cmb in cfg[vary]:
env = get_environment(cmb)
state = generate_trace(cfg, cmb,env)
trace_file_name = cfg['result_folder'] + 'traces/' + datetime.strftime(datetime.now(), "%Y-%m-%d--%H-%M-%S-%f") + '.json'
# Dump aggregate statistics
analysis_results.append( {**cmb, **(analyze_trace(cfg, env, state, trace_file_name))} )
with open(result_file_name, 'w+') as result_file:
json.dump(analysis_results, result_file, indent=4)
# Dump trace
if dump_trace_flag:
dump_trace(cfg, cmb, env, state, trace_file_name)
if plot_trace_flag:
plot_trace(cfg, cmb, env, state, cfg['result_folder'])
return analysis_results
def main():
parser = argparse.ArgumentParser(description='Run fluid model.')
parser.add_argument('-c', '--config', required=True)
args = parser.parse_args()
cfg = parse_config(args.config)
result_folder = 'results/'
if not os.path.exists(result_folder):
os.mkdir(result_folder)
result_folder += cfg['name'] + '/'
if not os.path.exists(result_folder):
os.mkdir(result_folder)
result_folder += 'fluid_model/'
if not os.path.exists(result_folder):
os.mkdir(result_folder)
cfg['result_folder'] = result_folder
run_model_for_config(cfg)
main()