-
Notifications
You must be signed in to change notification settings - Fork 1
/
context_changers.py
127 lines (91 loc) · 4.54 KB
/
context_changers.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
import random
import numpy as np
class ContextChanger:
def __init__(self):
self.reset()
def reset(self):
raise NotImplementedError
def reset_env(self, env):
raise NotImplementedError
def change_env(self, env):
raise NotImplementedError
class NullContextChanger(ContextChanger):
def reset(self):
pass
def reset_env(self, env):
pass
def change_env(self, env):
pass
class ReacherHardContextChanger(ContextChanger):
def __init__(self, multi_reset=True):
self.multi_reset = multi_reset
self.is_reset = False
super().__init__()
def reset(self):
if not self.multi_reset and self.is_reset:
return
self.c1_pos = [random.random() * 0.6 - 0.3, random.random() * 0.6 - 0.3, 2.5e-6]
self.c2_pos = [random.random() * 0.6 - 0.3, random.random() * 0.6 - 0.3, 2.5e-6]
self.c3_pos = [random.random() * 0.6 - 0.3, random.random() * 0.6 - 0.3, 2.5e-6]
self.c4_pos = [random.random() * 0.6 - 0.3, random.random() * 0.6 - 0.3, 2.5e-6]
self.c5_pos = [random.random() * 0.6 - 0.3, random.random() * 0.6 - 0.3, 2.5e-6]
self.c1_visible = round(random.random())
self.c2_visible = round(random.random())
self.c3_visible = round(random.random())
self.c4_visible = round(random.random())
self.c5_visible = round(random.random())
self.c1_color = [random.random() * 0.5, random.random() * 0.5, random.random() * 0.5, self.c1_visible]
self.c2_color = [random.random() * 0.5, random.random() * 0.5, random.random() * 0.5, self.c2_visible]
self.c3_color = [random.random() * 0.5, random.random() * 0.5, random.random() * 0.5, self.c3_visible]
self.c4_color = [random.random() * 0.5, random.random() * 0.5, random.random() * 0.5, self.c4_visible]
self.c5_color = [random.random() * 0.5, random.random() * 0.5, random.random() * 0.5, self.c5_visible]
self.is_reset = True
def change_env(self, env):
env.physics.named.model.mat_texid['grid'] = -1
env.physics.named.model.geom_rgba['ground'] = [1., 1., 1., 1]
env.physics.named.data.geom_xpos['c1'] = self.c1_pos
env.physics.named.data.geom_xpos['c2'] = self.c2_pos
env.physics.named.data.geom_xpos['c3'] = self.c3_pos
env.physics.named.data.geom_xpos['c4'] = self.c4_pos
env.physics.named.data.geom_xpos['c5'] = self.c5_pos
env.physics.named.model.geom_rgba['c1'] = self.c1_color
env.physics.named.model.geom_rgba['c2'] = self.c2_color
env.physics.named.model.geom_rgba['c3'] = self.c3_color
env.physics.named.model.geom_rgba['c4'] = self.c4_color
env.physics.named.model.geom_rgba['c5'] = self.c5_color
def reset_env(self, env):
env.physics.named.model.mat_texid['grid'] = 1
env.physics.named.model.geom_rgba['ground'] = [0.5, 0.5, 0.5, 1]
env.physics.named.data.geom_xpos['c1'] = [0, 0, 2.5e-6]
env.physics.named.data.geom_xpos['c2'] = [0, 0, 2.5e-6]
env.physics.named.data.geom_xpos['c3'] = [0, 0, 2.5e-6]
env.physics.named.data.geom_xpos['c4'] = [0, 0, 2.5e-6]
env.physics.named.data.geom_xpos['c5'] = [0, 0, 2.5e-6]
env.physics.named.model.geom_rgba['c1'] = [0, 0, 0, 0]
env.physics.named.model.geom_rgba['c2'] = [0, 0, 0, 0]
env.physics.named.model.geom_rgba['c3'] = [0, 0, 0, 0]
env.physics.named.model.geom_rgba['c4'] = [0, 0, 0, 0]
env.physics.named.model.geom_rgba['c5'] = [0, 0, 0, 0]
class ReacherHardWCContextChanger(ContextChanger):
def __init__(self):
super().__init__()
def reset(self):
pass
def change_env(self, env):
env.physics.named.model.mat_texid['grid'] = -1
env.physics.named.model.geom_rgba['ground'] = [1., 1., 1., 1]
def reset_env(self, env):
env.physics.named.model.mat_texid['grid'] = 1
env.physics.named.model.geom_rgba['ground'] = [0.5, 0.5, 0.5, 1]
class WalkerRunContextChanger(ContextChanger):
def reset(self):
# self.ground_color = [random.random() * 0.5, random.random() * 0.5, random.random() * 0.5, 1]
self.floor = np.random.uniform([0., 0., 0., 1.], [0.5, 0.5, 0.5, 1])
def change_env(self, env):
pass
# env.physics.named.model.mat_texid['grid'] = -1
# env.physics.named.model.geom_rgba['floor'] = self.floor
def reset_env(self, env):
pass
# env.physics.named.model.mat_texid['grid'] = 1
# env.physics.named.model.geom_rgba['floor'] = [0.5, 0.5, 0.5, 1]