This repository has been archived by the owner on Dec 5, 2024. It is now read-only.
forked from ARISE-Initiative/robomimic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_iris.py
302 lines (244 loc) · 13.6 KB
/
test_iris.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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
"""
Test script for IRIS algorithms. Each test trains a variant of IRIS
for a handful of gradient steps and tries one rollout with
the model. Excludes stdout output by default (pass --verbose
to see stdout output).
"""
import argparse
from collections import OrderedDict
import robomimic
import robomimic.utils.test_utils as TestUtils
from robomimic.utils.log_utils import silence_stdout
from robomimic.utils.torch_utils import dummy_context_mgr
def get_algo_base_config():
"""
Base config for testing BCQ algorithms.
"""
# config with basic settings for quick training run
config = TestUtils.get_base_config(algo_name="iris")
# low-level obs (note that we define it here because @observation structure might vary per algorithm,
# for example iris)
config.observation.value_planner.planner.modalities.obs.low_dim = ["robot0_eef_pos", "robot0_eef_quat", "robot0_gripper_qpos", "object"]
config.observation.value_planner.planner.modalities.obs.rgb = []
config.observation.value_planner.planner.modalities.subgoal.low_dim = ["robot0_eef_pos", "robot0_eef_quat", "robot0_gripper_qpos", "object"]
config.observation.value_planner.planner.modalities.subgoal.rgb = []
config.observation.value_planner.value.modalities.obs.low_dim = ["robot0_eef_pos", "robot0_eef_quat", "robot0_gripper_qpos", "object"]
config.observation.value_planner.value.modalities.obs.rgb = []
config.observation.actor.modalities.obs.low_dim = ["robot0_eef_pos", "robot0_eef_quat", "robot0_gripper_qpos", "object"]
config.observation.actor.modalities.obs.rgb = []
# by default, basic N(0, 1) prior for both planner VAE and BCQ cVAE
config.algo.value_planner.planner.vae.enabled = True
config.algo.value_planner.planner.vae.prior.learn = False
config.algo.value_planner.planner.vae.prior.is_conditioned = False
config.algo.value_planner.value.action_sampler.vae.enabled = True
config.algo.value_planner.value.action_sampler.vae.prior.learn = False
config.algo.value_planner.value.action_sampler.vae.prior.is_conditioned = False
return config
# mapping from test name to config modifier functions
MODIFIERS = OrderedDict()
def register_mod(test_name):
def decorator(config_modifier):
MODIFIERS[test_name] = config_modifier
return decorator
@register_mod("iris")
def iris_modifier_1(config):
# no-op
return config
@register_mod("iris, planner vae Gaussian prior (obs-independent)")
def iris_modifier_2(config):
# learn parameters of Gaussian prior (obs-independent)
config.algo.value_planner.planner.vae.enabled = True
config.algo.value_planner.planner.vae.prior.learn = True
config.algo.value_planner.planner.vae.prior.is_conditioned = False
config.algo.value_planner.planner.vae.prior.use_gmm = False
config.algo.value_planner.planner.vae.prior.use_categorical = False
return config
@register_mod("iris, planner vae Gaussian prior (obs-dependent)")
def iris_modifier_3(config):
# learn parameters of Gaussian prior (obs-dependent)
config.algo.value_planner.planner.vae.enabled = True
config.algo.value_planner.planner.vae.prior.learn = True
config.algo.value_planner.planner.vae.prior.is_conditioned = True
config.algo.value_planner.planner.vae.prior.use_gmm = False
config.algo.value_planner.planner.vae.prior.use_categorical = False
return config
@register_mod("iris, planner vae GMM prior (obs-independent, weights-fixed)")
def iris_modifier_4(config):
# learn parameters of GMM prior (obs-independent, weights-fixed)
config.algo.value_planner.planner.vae.enabled = True
config.algo.value_planner.planner.vae.prior.learn = True
config.algo.value_planner.planner.vae.prior.is_conditioned = False
config.algo.value_planner.planner.vae.prior.use_gmm = True
config.algo.value_planner.planner.vae.prior.gmm_learn_weights = False
config.algo.value_planner.planner.vae.prior.use_categorical = False
return config
@register_mod("iris, planner vae GMM prior (obs-independent, weights-learned)")
def iris_modifier_5(config):
# learn parameters of GMM prior (obs-independent, weights-learned)
config.algo.value_planner.planner.vae.enabled = True
config.algo.value_planner.planner.vae.prior.learn = True
config.algo.value_planner.planner.vae.prior.is_conditioned = False
config.algo.value_planner.planner.vae.prior.use_gmm = True
config.algo.value_planner.planner.vae.prior.gmm_learn_weights = True
config.algo.value_planner.planner.vae.prior.use_categorical = False
return config
@register_mod("iris, planner vae GMM prior (obs-dependent, weights-fixed)")
def iris_modifier_6(config):
# learn parameters of GMM prior (obs-dependent, weights-fixed)
config.algo.value_planner.planner.vae.enabled = True
config.algo.value_planner.planner.vae.prior.learn = True
config.algo.value_planner.planner.vae.prior.is_conditioned = True
config.algo.value_planner.planner.vae.prior.use_gmm = True
config.algo.value_planner.planner.vae.prior.gmm_learn_weights = False
config.algo.value_planner.planner.vae.prior.use_categorical = False
return config
@register_mod("iris, planner vae GMM prior (obs-dependent, weights-learned)")
def iris_modifier_7(config):
# learn parameters of GMM prior (obs-dependent, weights-learned)
config.algo.value_planner.planner.vae.enabled = True
config.algo.value_planner.planner.vae.prior.learn = True
config.algo.value_planner.planner.vae.prior.is_conditioned = True
config.algo.value_planner.planner.vae.prior.use_gmm = True
config.algo.value_planner.planner.vae.prior.gmm_learn_weights = True
config.algo.value_planner.planner.vae.prior.use_categorical = False
return config
@register_mod("iris, planner vae uniform categorical prior")
def iris_modifier_8(config):
# uniform categorical prior
config.algo.value_planner.planner.vae.enabled = True
config.algo.value_planner.planner.vae.prior.learn = False
config.algo.value_planner.planner.vae.prior.is_conditioned = False
config.algo.value_planner.planner.vae.prior.use_gmm = False
config.algo.value_planner.planner.vae.prior.use_categorical = True
return config
@register_mod("iris, planner vae categorical prior (obs-independent)")
def iris_modifier_9(config):
# learn parameters of categorical prior (obs-independent)
config.algo.value_planner.planner.vae.enabled = True
config.algo.value_planner.planner.vae.prior.learn = True
config.algo.value_planner.planner.vae.prior.is_conditioned = False
config.algo.value_planner.planner.vae.prior.use_gmm = False
config.algo.value_planner.planner.vae.prior.use_categorical = True
return config
@register_mod("iris, planner vae categorical prior (obs-dependent)")
def iris_modifier_10(config):
# learn parameters of categorical prior (obs-dependent)
config.algo.value_planner.planner.vae.enabled = True
config.algo.value_planner.planner.vae.prior.learn = True
config.algo.value_planner.planner.vae.prior.is_conditioned = True
config.algo.value_planner.planner.vae.prior.use_gmm = False
config.algo.value_planner.planner.vae.prior.use_categorical = True
return config
@register_mod("iris, bcq gmm")
def iris_modifier_11(config):
# bcq action sampler is GMM
config.algo.value_planner.value.action_sampler.gmm.enabled = True
config.algo.value_planner.value.action_sampler.vae.enabled = False
return config
@register_mod("iris, bcq distributional")
def iris_modifier_12(config):
# bcq value function is distributional
config.algo.value_planner.value.critic.distributional.enabled = True
config.algo.value_planner.value.critic.value_bounds = [-100., 100.]
return config
@register_mod("iris, bcq cVAE Gaussian prior (obs-independent)")
def iris_modifier_13(config):
# learn parameters of Gaussian prior (obs-independent)
config.algo.value_planner.value.action_sampler.vae.enabled = True
config.algo.value_planner.value.action_sampler.vae.prior.learn = True
config.algo.value_planner.value.action_sampler.vae.prior.is_conditioned = False
config.algo.value_planner.value.action_sampler.vae.prior.use_gmm = False
config.algo.value_planner.value.action_sampler.vae.prior.use_categorical = False
return config
@register_mod("iris, bcq cVAE Gaussian prior (obs-dependent)")
def iris_modifier_14(config):
# learn parameters of Gaussian prior (obs-dependent)
config.algo.value_planner.value.action_sampler.vae.enabled = True
config.algo.value_planner.value.action_sampler.vae.prior.learn = True
config.algo.value_planner.value.action_sampler.vae.prior.is_conditioned = True
config.algo.value_planner.value.action_sampler.vae.prior.use_gmm = False
config.algo.value_planner.value.action_sampler.vae.prior.use_categorical = False
return config
@register_mod("iris, bcq cVAE GMM prior (obs-independent, weights-fixed)")
def iris_modifier_15(config):
# learn parameters of GMM prior (obs-independent, weights-fixed)
config.algo.value_planner.value.action_sampler.vae.enabled = True
config.algo.value_planner.value.action_sampler.vae.prior.learn = True
config.algo.value_planner.value.action_sampler.vae.prior.is_conditioned = False
config.algo.value_planner.value.action_sampler.vae.prior.use_gmm = True
config.algo.value_planner.value.action_sampler.vae.prior.gmm_learn_weights = False
config.algo.value_planner.value.action_sampler.vae.prior.use_categorical = False
return config
@register_mod("iris, bcq cVAE GMM prior (obs-independent, weights-learned)")
def iris_modifier_16(config):
# learn parameters of GMM prior (obs-independent, weights-learned)
config.algo.value_planner.value.action_sampler.vae.enabled = True
config.algo.value_planner.value.action_sampler.vae.prior.learn = True
config.algo.value_planner.value.action_sampler.vae.prior.is_conditioned = False
config.algo.value_planner.value.action_sampler.vae.prior.use_gmm = True
config.algo.value_planner.value.action_sampler.vae.prior.gmm_learn_weights = True
config.algo.value_planner.value.action_sampler.vae.prior.use_categorical = False
return config
@register_mod("iris, bcq cVAE GMM prior (obs-dependent, weights-fixed)")
def iris_modifier_17(config):
# learn parameters of GMM prior (obs-dependent, weights-fixed)
config.algo.value_planner.value.action_sampler.vae.enabled = True
config.algo.value_planner.value.action_sampler.vae.prior.learn = True
config.algo.value_planner.value.action_sampler.vae.prior.is_conditioned = True
config.algo.value_planner.value.action_sampler.vae.prior.use_gmm = True
config.algo.value_planner.value.action_sampler.vae.prior.gmm_learn_weights = False
config.algo.value_planner.value.action_sampler.vae.prior.use_categorical = False
return config
@register_mod("iris, bcq cVAE GMM prior (obs-dependent, weights-learned)")
def iris_modifier_18(config):
# learn parameters of GMM prior (obs-dependent, weights-learned)
config.algo.value_planner.value.action_sampler.vae.enabled = True
config.algo.value_planner.value.action_sampler.vae.prior.learn = True
config.algo.value_planner.value.action_sampler.vae.prior.is_conditioned = True
config.algo.value_planner.value.action_sampler.vae.prior.use_gmm = True
config.algo.value_planner.value.action_sampler.vae.prior.gmm_learn_weights = True
config.algo.value_planner.value.action_sampler.vae.prior.use_categorical = False
return config
@register_mod("iris, bcq cVAE uniform categorical prior")
def iris_modifier_19(config):
# uniform categorical prior
config.algo.value_planner.value.action_sampler.vae.enabled = True
config.algo.value_planner.value.action_sampler.vae.prior.learn = False
config.algo.value_planner.value.action_sampler.vae.prior.is_conditioned = False
config.algo.value_planner.value.action_sampler.vae.prior.use_gmm = False
config.algo.value_planner.value.action_sampler.vae.prior.use_categorical = True
return config
@register_mod("iris, bcq cVAE categorical prior (obs-independent)")
def iris_modifier_20(config):
# learn parameters of categorical prior (obs-independent)
config.algo.value_planner.value.action_sampler.vae.enabled = True
config.algo.value_planner.value.action_sampler.vae.prior.learn = True
config.algo.value_planner.value.action_sampler.vae.prior.is_conditioned = False
config.algo.value_planner.value.action_sampler.vae.prior.use_gmm = False
config.algo.value_planner.value.action_sampler.vae.prior.use_categorical = True
return config
@register_mod("iris, bcq cVAE categorical prior (obs-dependent)")
def iris_modifier_21(config):
# learn parameters of categorical prior (obs-dependent)
config.algo.value_planner.value.action_sampler.vae.enabled = True
config.algo.value_planner.value.action_sampler.vae.prior.learn = True
config.algo.value_planner.value.action_sampler.vae.prior.is_conditioned = True
config.algo.value_planner.value.action_sampler.vae.prior.use_gmm = False
config.algo.value_planner.value.action_sampler.vae.prior.use_categorical = True
return config
def test_iris(silence=True):
for test_name in MODIFIERS:
context = silence_stdout() if silence else dummy_context_mgr()
with context:
base_config = get_algo_base_config()
res_str = TestUtils.test_run(base_config=base_config, config_modifier=MODIFIERS[test_name])
print("{}: {}".format(test_name, res_str))
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"--verbose",
action='store_true',
help="don't suppress stdout during tests",
)
args = parser.parse_args()
test_iris(silence=(not args.verbose))