-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
79 lines (62 loc) · 2.02 KB
/
main.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
import yaml
import copy
from simulator import get_simulator
from agent import get_agent
from logger import setup_logger
from utils.analysis_tool import Analysis_Tool
import argparse
def main():
logger = setup_logger()
args = parse_args()
round_num = args.repeat
experiment_type = args.experiment_type
with open(f"config/{experiment_type}_config.yaml", "r") as file:
cfg = yaml.safe_load(file)
analysis_tool = Analysis_Tool(cfg)
for i in range(round_num):
experiment_num = str(i + 1)
simulator = get_simulator(cfg["simulator"])
analysis_tool.record_simulator_data(simulator, experiment_num)
agent_list = cfg["agent_list"]
for agent_name, agent_cfg in agent_list.items():
logger.info(
f"---------- start experiment: round{experiment_num}/{agent_name} ----------\n"
)
agent = get_agent(copy.deepcopy(cfg), agent_cfg)
agent.record_metrics = args.record_metrics
simulator.run(agent)
analysis_tool.record_experiment_data(agent, agent_name, experiment_num)
logger.info(
f"---------- finish experiment: round{experiment_num}/{agent_name} ----------\n"
)
if not args.test_run:
analysis_tool.analyse()
def parse_args():
"""
Parse command line arguments.
"""
parser = argparse.ArgumentParser()
parser.add_argument(
"--experiment_type",
"-E",
required=True,
type=str,
help="experiment type, either planning or mapping",
)
parser.add_argument(
"--repeat",
"-R",
type=int,
default=5,
help="experiment repeat times",
)
parser.add_argument(
"--test_run", action="store_true", help="no analysis if in test_run mode"
)
parser.add_argument(
"--record_metrics", action="store_true", help="record metrics after each step"
)
args = parser.parse_args()
return args
if __name__ == "__main__":
main()