-
Notifications
You must be signed in to change notification settings - Fork 0
/
actions.py
293 lines (263 loc) · 10.5 KB
/
actions.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
from enum import Enum
from emma_experience_hub.constants.model import END_OF_TRAJECTORY_TOKEN, PREDICTED_ACTION_DELIMITER
from emma_experience_hub.datamodels.simbot.payloads import (
SimBotAuxiliaryMetadataPayload,
SimBotDialogPayload,
SimBotGotoObjectPayload,
SimBotGotoPayload,
SimBotGotoPositionPayload,
SimBotGotoRoomPayload,
SimBotGotoViewpointPayload,
SimBotLookAroundPayload,
SimBotLookDownPayload,
SimBotLookPayload,
SimBotLookUpPayload,
SimBotMoveBackwardPayload,
SimBotMoveForwardPayload,
SimBotMovePayload,
SimBotObjectInteractionPayload,
SimBotPayload,
SimBotRotateLeftPayload,
SimBotRotatePayload,
SimBotRotateRightPayload,
SimBotSpeechRecognitionPayload,
SimBotTurnAroundPayload,
)
class SimBotActionType(Enum):
"""All action types from the SimBot Arena."""
# Navigation
Goto = "goto" # noqa: WPS115
Move = "move" # noqa: WPS115
Rotate = "rotation" # noqa: WPS115
Look = "look" # noqa: WPS115
# CameraChange = "camerachange"
# Navigation Aliases (commonly used action types)
MoveForward = "move forward" # noqa: WPS115
MoveBackward = "move backward" # noqa: WPS115
RotateLeft = "rotate left" # noqa: WPS115
RotateRight = "rotate right" # noqa: WPS115
LookUp = "look up" # noqa: WPS115
LookDown = "look down" # noqa: WPS115
LookAround = "look around" # noqa: WPS115
TurnAround = "turn around" # noqa: WPS115
GotoRoom = "goto room" # noqa: WPS115
GotoObject = "goto object" # noqa: WPS115
GotoPosition = "goto position" # noqa: WPS115
GotoViewpoint = "goto viewpoint" # noqa: WPS115
# Object interaction
Pickup = "pickup" # noqa: WPS115
Open = "open" # noqa: WPS115
Close = "close" # noqa: WPS115
Break = "break" # noqa: WPS115
Scan = "scan" # noqa: WPS115
Examine = "examine" # noqa: WPS115
Place = "place" # noqa: WPS115
Pour = "pour" # noqa: WPS115
Toggle = "toggle" # noqa: WPS115
Fill = "fill" # noqa: WPS115
Clean = "clean" # noqa: WPS115
Highlight = "highlight" # noqa: WPS115
# Burn = "burn"
# Slice = "slice"
# Throw = "throw"
# Use = "use"
# Language
Dialog = "dialog" # noqa: WPS115
LightweightDialog = "lightweightDialog" # noqa: WPS115
SpeechRecognition = "recognition" # noqa: WPS115
# Other
GameMetaData = "metaData" # noqa: WPS115
@classmethod
def sensors(cls) -> list["SimBotActionType"]:
"""Action types which are recieved from the environment."""
return [SimBotActionType.SpeechRecognition, SimBotActionType.GameMetaData]
@classmethod
def navigation(cls) -> list["SimBotActionType"]:
"""Get all navigation action types from the SimBot Arena."""
return [
SimBotActionType.Goto,
SimBotActionType.Move,
SimBotActionType.Rotate,
SimBotActionType.Look,
SimBotActionType.MoveForward,
SimBotActionType.MoveBackward,
SimBotActionType.RotateLeft,
SimBotActionType.RotateRight,
SimBotActionType.LookUp,
SimBotActionType.LookDown,
SimBotActionType.LookAround,
SimBotActionType.TurnAround,
SimBotActionType.GotoRoom,
SimBotActionType.GotoObject,
SimBotActionType.GotoPosition,
SimBotActionType.GotoViewpoint,
]
@classmethod
def low_level_navigation(cls) -> list["SimBotActionType"]:
"""Get all the low-level navigation action types.
All of these have pre-instantiated payloads too.
"""
return [
SimBotActionType.Move,
SimBotActionType.Rotate,
SimBotActionType.Look,
SimBotActionType.MoveForward,
SimBotActionType.MoveBackward,
SimBotActionType.RotateLeft,
SimBotActionType.RotateRight,
SimBotActionType.LookUp,
SimBotActionType.LookDown,
SimBotActionType.LookAround,
SimBotActionType.TurnAround,
]
@classmethod
def object_interaction(cls) -> list["SimBotActionType"]:
"""Get all object interaction action types from the SimBot Arena."""
return [
SimBotActionType.Pickup,
SimBotActionType.Open,
SimBotActionType.Close,
SimBotActionType.Break,
SimBotActionType.Scan,
SimBotActionType.Examine,
SimBotActionType.Place,
SimBotActionType.Pour,
SimBotActionType.Toggle,
SimBotActionType.Fill,
SimBotActionType.Clean,
SimBotActionType.Highlight,
]
@classmethod
def language(cls) -> list["SimBotActionType"]:
"""Get all language action types from the SimBot Arena."""
return [
SimBotActionType.Dialog,
SimBotActionType.LightweightDialog,
SimBotActionType.SpeechRecognition,
]
@classmethod
def action_type_to_payload_model(cls) -> dict[str, type[SimBotPayload]]:
"""Get a map from each action type to the payload model."""
switcher: dict[str, type[SimBotPayload]] = {
# Sensors
"SpeechRecognition": SimBotSpeechRecognitionPayload,
"GameMetaData": SimBotAuxiliaryMetadataPayload,
# Dialog
"Dialog": SimBotDialogPayload,
"LightweightDialog": SimBotDialogPayload,
# Navigation
"Goto": SimBotGotoPayload,
"Move": SimBotMovePayload,
"Rotate": SimBotRotatePayload,
"Look": SimBotLookPayload,
# Navigation Aliases
"MoveForward": SimBotMoveForwardPayload,
"MoveBackward": SimBotMoveBackwardPayload,
"RotateLeft": SimBotRotateLeftPayload,
"RotateRight": SimBotRotateRightPayload,
"LookUp": SimBotLookUpPayload,
"LookDown": SimBotLookDownPayload,
"LookAround": SimBotLookAroundPayload,
"TurnAround": SimBotTurnAroundPayload,
"GotoRoom": SimBotGotoRoomPayload,
"GotoObject": SimBotGotoObjectPayload,
"GotoViewpoint": SimBotGotoViewpointPayload,
"GotoPosition": SimBotGotoPositionPayload,
# Object interaction
"Pickup": SimBotObjectInteractionPayload,
"Open": SimBotObjectInteractionPayload,
"Close": SimBotObjectInteractionPayload,
"Break": SimBotObjectInteractionPayload,
"Scan": SimBotObjectInteractionPayload,
"Examine": SimBotObjectInteractionPayload,
"Place": SimBotObjectInteractionPayload,
"Pour": SimBotObjectInteractionPayload,
"Toggle": SimBotObjectInteractionPayload,
"Fill": SimBotObjectInteractionPayload,
"Clean": SimBotObjectInteractionPayload,
"Highlight": SimBotObjectInteractionPayload,
}
return switcher
@classmethod
def from_payload_model(cls, payload_model: SimBotPayload) -> "SimBotActionType":
"""Get the correct action type from the provided payload."""
switcher = {
payload_model: SimBotActionType[action_type_name]
for action_type_name, payload_model in SimBotActionType.action_type_to_payload_model().items()
}
return switcher[type(payload_model)]
@classmethod
def base_type_to_aliases(cls) -> dict["SimBotActionType", set["SimBotActionType"]]:
"""Map each base type to its aliases."""
return {
SimBotActionType.Move: {
SimBotActionType.MoveForward,
SimBotActionType.MoveBackward,
},
SimBotActionType.Look: {
SimBotActionType.LookAround,
SimBotActionType.LookDown,
SimBotActionType.LookUp,
},
SimBotActionType.Rotate: {
SimBotActionType.RotateLeft,
SimBotActionType.RotateRight,
SimBotActionType.TurnAround,
},
SimBotActionType.Goto: {
SimBotActionType.GotoObject,
SimBotActionType.GotoRoom,
SimBotActionType.GotoViewpoint,
SimBotActionType.GotoPosition,
},
}
@classmethod
def alias_to_base_type(cls) -> dict["SimBotActionType", "SimBotActionType"]:
"""Map each alias to its base type."""
return {
alias_type: base_type
for base_type, alias_types in cls.base_type_to_aliases().items()
for alias_type in alias_types
}
@classmethod
def move_aliases(cls) -> set["SimBotActionType"]:
"""Return all the move aliases."""
return cls.base_type_to_aliases()[SimBotActionType.Move]
@classmethod
def look_aliases(cls) -> set["SimBotActionType"]:
"""Return all the look aliases."""
return cls.base_type_to_aliases()[SimBotActionType.Look]
@classmethod
def rotate_aliases(cls) -> set["SimBotActionType"]:
"""Return all the rotate aliases."""
return cls.base_type_to_aliases()[SimBotActionType.Rotate]
@classmethod
def goto_aliases(cls) -> set["SimBotActionType"]:
"""Return all the goto action aliases."""
return cls.base_type_to_aliases()[SimBotActionType.Goto]
@classmethod
def base_types(cls) -> set["SimBotActionType"]:
"""Get all the actions with a base type."""
return set(cls.base_type_to_aliases().keys())
@property
def base_type(self) -> "SimBotActionType":
"""Given a specific type, returns the base Simbot action type."""
possible_base_type = self.alias_to_base_type().get(self)
return possible_base_type if possible_base_type else self
@property
def has_base_type(self) -> bool:
"""Return True if the current action type has a base type."""
return self.base_type != self
@property
def payload_model(self) -> type[SimBotPayload]:
"""Get the corresponding payload for the SimBot action type."""
return self.action_type_to_payload_model()[self.name]
class SimBotDummyRawActions(Enum):
"""The raw output of all dummy actions in the SimBot Arena."""
# Navigation
DummyLookDown = ( # noqa: WPS115
f"dummy look down {END_OF_TRAJECTORY_TOKEN}{PREDICTED_ACTION_DELIMITER}"
)
# Next / Previous Viewpoint
DummyNextViewpoint = f"next viewpoint {END_OF_TRAJECTORY_TOKEN}" # noqa: WPS115
DummyPreviousViewpoint = f"previous viewpoint {END_OF_TRAJECTORY_TOKEN}" # noqa: WPS115