-
Notifications
You must be signed in to change notification settings - Fork 0
/
simbot.py
180 lines (143 loc) · 6.15 KB
/
simbot.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
import json
from collections.abc import Mapping
from csv import DictReader
from functools import lru_cache
from pathlib import Path
from types import MappingProxyType
from typing import Any
import orjson
from emma_experience_hub.common.settings.simbot import SimBotRoomSearchBudget
from emma_experience_hub.datamodels.simbot.enums import SimBotActionType
constants_absolute_path = Path(__file__).parent.resolve()
def get_service_registry_file_path() -> Path:
"""Get the path to the service registry file."""
return constants_absolute_path.joinpath("simbot", "registry.yaml")
@lru_cache(maxsize=1)
def get_arena_definitions() -> dict[str, Any]:
"""Load the arena definitions from their file."""
path = constants_absolute_path.joinpath("simbot", "arena_definitions.json")
return orjson.loads(path.read_bytes())
@lru_cache(maxsize=1)
def get_simbot_objects_to_indices_map(lowercase_keys: bool = False) -> dict[str, int]:
"""Load map of object labels to their index."""
ignored_objects = ["Unassigned", "TAM Prototype"]
mapping = {
label: idx
for label, idx in get_arena_definitions()["label_to_idx"].items()
if label not in ignored_objects
}
if lowercase_keys:
mapping = {label.lower(): idx for label, idx in mapping.items()}
return mapping
@lru_cache(maxsize=1)
def get_simbot_object_id_to_class_name_map(lowercase_keys: bool = False) -> dict[str, str]:
"""Load map of objects from their Arena ID to the object class name."""
mapping = get_arena_definitions()["object_id_to_class_name"]
if lowercase_keys:
mapping = {label.lower(): output for label, output in mapping.items()}
return mapping
@lru_cache(maxsize=1)
def get_simbot_object_label_to_class_name_map(lowercase_keys: bool = False) -> dict[str, str]:
"""Load map of object labels to their class name."""
mapping = get_arena_definitions()["label_to_class_name"]
if lowercase_keys:
mapping = {label.lower(): output for label, output in mapping.items()}
return mapping
@lru_cache(maxsize=1)
def get_simbot_room_names(lowercase: bool = False) -> set[str]:
"""Load room name identifiers."""
room_names = set(get_arena_definitions()["room_names"])
if lowercase:
room_names = {room.lower() for room in room_names}
return room_names
@lru_cache(maxsize=1)
def get_simbot_room_name_map() -> dict[str, str]:
"""Map lowercase SimBot room names to their class name."""
return {room_name.lower(): room_name for room_name in get_simbot_room_names()}
@lru_cache(maxsize=1)
def get_feedback_rules() -> list[dict[str, str]]:
"""Load the feedback rules and responses from their file."""
csv_path = constants_absolute_path.joinpath("simbot", "feedback_rules.csv")
with open(csv_path, encoding="utf-8-sig") as csv_file:
raw_rule_reader = DictReader(csv_file)
return [{**rule, "id": str(idx)} for idx, rule in enumerate(raw_rule_reader, 2)]
@lru_cache(maxsize=1)
def get_search_budget() -> dict[str, SimBotRoomSearchBudget]:
"""Load the search_budget per room from file."""
json_path = constants_absolute_path.joinpath("simbot", "search_budget.json")
rooms = get_simbot_room_names()
with open(json_path) as json_file:
search_budget = json.load(json_file)
return {room: SimBotRoomSearchBudget(**search_budget[room]) for room in rooms}
ACTION_SYNONYMS: Mapping[SimBotActionType, set[str]] = MappingProxyType(
{
SimBotActionType.Goto: {"GoTo", "goto", "Goto"},
SimBotActionType.MoveForward: {"Move Forward", "move forward"},
SimBotActionType.MoveBackward: {"Move Backward", "move backward"},
SimBotActionType.RotateLeft: {"Rotate Left", "rotate left"},
SimBotActionType.RotateRight: {"Rotate Right", "rotate right"},
SimBotActionType.LookUp: {"Look Up", "look up"},
SimBotActionType.LookDown: {"Look Down", "look down"},
SimBotActionType.LookAround: {"Look Around", "look around"},
SimBotActionType.TurnAround: {"Turn Around", "turn around"},
SimBotActionType.Pickup: {"PickUp", "pickup"},
SimBotActionType.Open: {"Open", "open"},
SimBotActionType.Close: {"Close", "close"},
SimBotActionType.Break: {"Break", "break"},
SimBotActionType.Scan: {"Scan", "scan"},
SimBotActionType.Examine: {"Examine", "examine"},
SimBotActionType.Place: {"Place", "place"},
SimBotActionType.Pour: {"Pour", "pour"},
SimBotActionType.Toggle: {"Toggle", "toggle"},
SimBotActionType.Fill: {"Fill", "fill"},
SimBotActionType.Clean: {"Clean", "clean"},
SimBotActionType.Highlight: {"Highlight", "highlight"},
}
)
_ACTION_SYNONYMS_FOR_GENERATION: Mapping[str, str] = MappingProxyType(
{
"GotoRoom": "go to",
"GotoObject": "go to",
"MoveForward": "move forward",
"MoveBackward": "move backward",
"RotateLeft": "rotate left",
"RotateRight": "rotate right",
"LookUp": "look up",
"LookDown": "look down",
"LookAround": "look around",
"TurnAround": "turn around",
"Pickup": "pick up",
"Laser Shelf": "red shelf",
"Laser Monitor": "red monitor",
"Freeze Ray Shelf": "blue shelf",
"Freeze Ray Monitor": "blue computer",
"Gravity Monitor": "green computer",
"Embiggenator Monitor": "pink computer",
"Portal Generator Monitor": "black computer",
"Everything's A Carrot Machine": "carrot machine",
"Coffee Unmaker": "coffee composer",
}
)
_ROOM_SYNONYNMS: Mapping[str, str] = MappingProxyType(
{
"BreakRoom": "breakroom",
"Lab1": "robotics lab",
"Lab2": "quantum lab",
"MainOffice": "main office",
"Reception": "reception",
"SmallOffice": "small office",
"Warehouse": "warehouse",
}
)
ACTION_SYNONYMS_FOR_GENERATION: Mapping[str, str] = MappingProxyType(
{
**{k.lower(): v for k, v in _ACTION_SYNONYMS_FOR_GENERATION.items()},
**_ACTION_SYNONYMS_FOR_GENERATION,
}
)
ROOM_SYNONYNMS: Mapping[str, str] = MappingProxyType(
{
**{k.lower(): v for k, v in _ROOM_SYNONYNMS.items()},
**_ROOM_SYNONYNMS,
}
)