-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunSim.py
55 lines (43 loc) · 1.79 KB
/
runSim.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
'''
Runs a simulation
Command line args:
-cfg: Path to simulation cfg json. Defaults to "SimulationSettings/test.json
-log: Determine output level for agent/controller log files. Options are [CRITICAL, ERROR, WARNING, INFO, DEBUG]. Defaults to WARNING.
'''
import argparse
import json
import traceback
import os
from SimulationRunner import RunSimulation
def runSim(settingsFilePath, logLevel="INFO"):
try:
if (not os.path.exists(settingsFilePath)):
raise ValueError("\"{}\" does not exist".format(settingsFilePath))
fileDict = {}
try:
file = open(settingsFilePath, "r")
fileDict = json.load(file)
file.close()
except:
print(traceback.format_exc())
raise ValueError("Could not open \"{}\"".format(settingsFilePath))
outputDirPath = None
if ("name" in fileDict):
print("#### {} ####".format(fileDict["name"]))
outputDirPath = os.path.join("OUTPUT", fileDict["name"])
if ("description" in fileDict):
description = fileDict["description"]
print("\n{}\n".format(description))
if (not "settings" in fileDict):
raise ValueError("\"settings\" missing from \"{}\"".format(settingsFilePath))
settingsDict = fileDict["settings"]
RunSimulation(settingsDict, logLevel, outputDir=outputDirPath)
except:
print(traceback.format_exc())
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("-cfg", dest="cfgPath", default="SimulationSettings\\test.json", help="Path to simulation cfg json. Defaults to \"SimulationSettings\\test.json\"")
parser.add_argument("-log", dest="logLevel", default="INFO", help="Determine output level for generated agent/controller log files. Options are [CRITICAL, ERROR, WARNING, INFO, DEBUG]. Defaults to INFO.")
args = parser.parse_args()
settingsFilePath = args.cfgPath
runSim(settingsFilePath, args.logLevel)