forked from ARISE-Initiative/robosuite-benchmark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
arguments.py
286 lines (262 loc) · 7.96 KB
/
arguments.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
"""
Utility functions for parsing / processing command line arguments
"""
import argparse
from util.rlkit_utils import AGENTS
# Define mapping from string True / False to bool True / False
BOOL_MAP = {
"true" : True,
"false" : False
}
# Define parser
parser = argparse.ArgumentParser(description='RL args using agents / algs from rlkit and envs from robosuite')
# Add seed arg always
parser.add_argument(
'--seed', type=int, default=1, help='random seed (default: 1)')
def add_robosuite_args():
"""
Adds robosuite args to command line arguments list
"""
parser.add_argument(
'--env',
type=str,
default='Lift',
help='Robosuite env to run test on')
parser.add_argument(
'--robots',
nargs="+",
type=str,
default='Panda',
help='Robot(s) to run test with')
parser.add_argument(
'--eval_horizon',
type=int,
default=500,
help='max num of timesteps for each eval simulation')
parser.add_argument(
'--expl_horizon',
type=int,
default=500,
help='max num of timesteps for each eval simulation')
parser.add_argument(
'--policy_freq',
type=int,
default=20,
help='Policy frequency for environment (Hz)')
parser.add_argument(
'--controller',
type=str,
default="OSC_POSE",
help='controller to use for robot environment. Either name of controller for default config or filepath to custom'
'controller config')
parser.add_argument(
'--reward_scale',
type=float,
default=1.0,
help='max reward from single environment step'
)
parser.add_argument(
'--hard_reset',
action="store_true",
help='If set, uses hard resets for this env'
)
# Environment-specific arguments
parser.add_argument(
'--env_config',
type=str,
default=None,
choices=['single-arm-parallel', 'single-arm-opposed', 'bimanual'],
help='Robosuite env configuration. Only necessary for bimanual environments')
parser.add_argument(
'--prehensile',
type=str,
default=None,
choices=["True", "False", "true", "false"],
help='Whether to use prehensile config. Only necessary for TwoArmHandoff env'
)
def add_agent_args():
"""
Adds args necessary to define a general agent and trainer in rlkit
"""
parser.add_argument(
'--agent',
type=str,
default="SAC",
choices=AGENTS,
help='Agent to use for training')
parser.add_argument(
'--qf_hidden_sizes',
nargs="+",
type=int,
default=[256, 256],
help='Hidden sizes for Q network ')
parser.add_argument(
'--policy_hidden_sizes',
nargs="+",
type=int,
default=[256, 256],
help='Hidden sizes for policy network ')
parser.add_argument(
'--gamma',
type=float,
default=0.99,
help='Discount factor')
parser.add_argument(
'--policy_lr',
type=float,
default=3e-4,
help='Learning rate for policy')
parser.add_argument(
'--qf_lr',
type=float,
default=3e-4,
help='Quality function learning rate')
# SAC-specific
parser.add_argument(
'--soft_target_tau',
type=float,
default=5e-3,
help='Soft Target Tau value for Value function updates')
parser.add_argument(
'--target_update_period',
type=int,
default=1,
help='Number of steps between target updates')
parser.add_argument(
'--no_auto_entropy_tuning',
action='store_true',
help='Whether to automatically tune entropy or not (default is ON)')
# TD3-specific
parser.add_argument(
'--target_policy_noise',
type=float,
default=0.2,
help='Target noise for policy')
parser.add_argument(
'--policy_and_target_update_period',
type=int,
default=2,
help='Number of steps between policy and target updates')
parser.add_argument(
'--tau',
type=float,
default=0.005,
help='Tau value for training')
def add_training_args():
"""
Adds training parameters used during the experiment run
"""
parser.add_argument(
'--variant',
type=str,
default=None,
help='If set, will use stored configuration from the specified filepath (should point to .json file)')
parser.add_argument(
'--n_epochs',
type=int,
default=2000,
help='Number of epochs to run')
parser.add_argument(
'--trains_per_train_loop',
type=int,
default=1000,
help='Number of training steps to take per training loop')
parser.add_argument(
'--expl_ep_per_train_loop',
type=int,
default=10,
help='Number of exploration episodes to take per training loop')
parser.add_argument(
'--steps_before_training',
type=int,
default=1000,
help='Number of exploration steps to take before starting training')
parser.add_argument(
'--batch_size',
type=int,
default=256,
help='Batch size per training step')
parser.add_argument(
'--num_eval',
type=int,
default=10,
help='Num eval episodes to run for each trial run')
parser.add_argument(
'--log_dir',
type=str,
default='../log/runs/',
help='directory to save runs')
def add_rollout_args():
"""
Adds rollout arguments needed for evaluating / visualizing a trained rlkit policy
"""
parser.add_argument(
'--load_dir',
type=str,
required=True,
help='path to the snapshot directory folder')
parser.add_argument(
'--num_episodes',
type=int,
default=10,
help='Num rollout episodes to run')
parser.add_argument(
'--horizon',
type=int,
default=None,
help='Horizon to use for rollouts (overrides default if specified)')
parser.add_argument(
'--gpu',
action='store_true',
help='If true, uses GPU to process model')
parser.add_argument(
'--camera',
type=str,
default='frontview',
help='Name of camera for visualization')
parser.add_argument(
'--record_video',
action='store_true',
help='If set, will save video of rollouts')
def get_expl_env_kwargs(args):
"""
Grabs the robosuite-specific arguments and converts them into an rlkit-compatible dict for exploration env
"""
env_kwargs = dict(
env_name=args.env,
robots=args.robots,
horizon=args.expl_horizon,
control_freq=args.policy_freq,
controller=args.controller,
reward_scale=args.reward_scale,
hard_reset=args.hard_reset,
ignore_done=True,
)
# Add in additional ones that may not always be specified
if args.env_config is not None:
env_kwargs["env_configuration"] = args.env_config
if args.prehensile is not None:
env_kwargs["prehensile"] = BOOL_MAP[args.prehensile.lower()]
# Lastly, return the dict
return env_kwargs
def get_eval_env_kwargs(args):
"""
Grabs the robosuite-specific arguments and converts them into an rlkit-compatible dict for evaluation env
"""
env_kwargs = dict(
env_name=args.env,
robots=args.robots,
horizon=args.eval_horizon,
control_freq=args.policy_freq,
controller=args.controller,
reward_scale=1.0,
hard_reset=args.hard_reset,
ignore_done=True,
)
# Add in additional ones that may not always be specified
if args.env_config is not None:
env_kwargs["env_configuration"] = args.env_config
if args.prehensile is not None:
env_kwargs["prehensile"] = BOOL_MAP[args.prehensile.lower()]
# Lastly, return the dict
return env_kwargs