-
Notifications
You must be signed in to change notification settings - Fork 15
/
run_birdseye.py
136 lines (116 loc) · 4.9 KB
/
run_birdseye.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import argparse
import configparser
from birdseye.actions import get_action
from birdseye.env import RFEnv
from birdseye.env import RFMultiEnv
from birdseye.method_utils import get_method
from birdseye.sensor import get_sensor
from birdseye.state import get_state
AVAIL_ENVS = {"RFEnv": RFEnv, "RFMultiEnv": RFMultiEnv}
def batch_run(): # pragma: no cover
# TODO this function no longer works with the rest of the codebase
# Setup requested method objects
for method_name in ["mcts"]:
for sensor_config in ["doublerssi"]:
for reward in ["range_reward", "entropy_collision_reward"]:
for target_start in ["78"]:
for target_speed in ["1"]:
print("===========================")
print("Batch Run: ")
print(f"method = {method_name}")
print(f"sensor_config = {sensor_config}")
print(f"reward = {reward}")
print(f"target_speed = {target_speed}")
print(f"target_start = {target_start}")
print("===========================")
run_method = get_method(method_name)
action_config = "simpleactions"
state_config = "rfmultistate"
actions = get_action(action_config)
sensor = get_sensor(sensor_config)
state = get_state(state_config)
# Setup environment
env = RFEnv(
sensor(),
actions(),
state(
target_speed=target_speed,
target_movement=None,
target_start=target_start,
reward=reward,
),
)
config = configparser.ConfigParser()
config.read([f"configs/{method_name}.yaml"])
config.set("Methods", "action", action_config)
config.set("Methods", "sensor", sensor_config)
config.set("Methods", "state", state_config)
config.set("Methods", "target_speed", target_speed)
config.set("Methods", "target_start", target_start)
config.set("Methods", "reward", reward)
# Run the requested algorithm
run_method(args=config, env=env)
def run_birdseye(args=None, env=None):
# Grab Methods information from config file
config = configparser.ConfigParser()
config.read([args.config])
config_dict = dict(config.items("Methods"))
config_dict = {k: v.strip("\"'") for k, v in config_dict.items()}
env_name = config_dict["env"]
method_name = config_dict["method"]
action_name = config_dict["action"]
sensor_name = config_dict["sensor"]
state_name = config_dict["state"]
n_targets = config_dict.get("n_targets")
target_speed = config_dict.get("target_speed")
target_speed_range = config_dict.get("target_speed_range")
target_movement = config_dict.get("target_movement")
target_start = config_dict.get("target_start")
reward = config_dict.get("reward")
fading_sigma = config_dict.get("fading_sigma")
# print({section: dict(config[section]) for section in config.sections()})
# Setup requested method objects
run_method = get_method(method_name)
env_class = AVAIL_ENVS[env_name]
action_class = get_action(action_name)
sensor_class = get_sensor(sensor_name)
state_class = get_state(state_name)
sensor = sensor_class(
antenna_filename="radiation_pattern_yagi_5.csv", fading_sigma=fading_sigma
)
actions = action_class()
state = state_class(
n_targets=n_targets,
target_speed=target_speed,
target_speed_range=target_speed_range,
target_movement=target_movement,
target_start=target_start,
reward=reward,
)
# Setup environment
env = env_class(sensor, actions, state)
# Run the requested algorithm
run_method(args=config, env=env)
def main():
arg_parser = argparse.ArgumentParser()
arg_parser.add_argument(
"-b", "--batch", action="store_true", help="Specify batch run option"
)
args, remaining_args = arg_parser.parse_known_args()
if not args.batch:
arg_parser.add_argument(
"-c",
"--config",
help="Specify a configuration file",
required=True,
metavar="FILE",
)
args, remaining_args = arg_parser.parse_known_args(
remaining_args, namespace=args
)
if args.batch:
batch_run()
else:
run_birdseye(args=args)
if __name__ == "__main__":
main()