registry_utils
A set of utility functions for registering and tracking objects
Registry
Bases: UniquelyNamed
Simple class for easily registering and tracking arbitrary objects of the same (or very similar) class types.
Elements added are automatically organized by attributes specified by @unique_keys and @group_keys, and can be accessed at runtime by specifying the desired key and indexing value to grab the object(s).
i.e.: a single indexing value will return a single object.
default: "name" -- indexing by object.name (i.e.: every object's name should be unique)
i.e.: a single indexing value will return a single object.
example: indexing by object.name (every object's name should be unique)
i.e.: a single indexing value will return a set of objects.
example: indexing by object.in_rooms (many objects can be in a single room)
Note that if a object's attribute is an array of values, then it will be stored under ALL of its values. example: object.in_rooms = ["kitchen", "living_room"], indexing by in_rooms with a value of either kitchen OR living room will return this object as part of its set!
You can also easily check for membership in this registry, via either the object's name OR the object itself, e.g.:
> object.name in registry
> object in registry
If the latter, note that default_key attribute will automatically be used to search for the object
Source code in omnigibson/utils/registry_utils.py
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 303 304 |
|
all_keys
property
Returns:
Type | Description |
---|---|
set of str: All object keys that are valid identification methods to index object(s) |
objects
property
Get the objects in this registry
Returns:
Type | Description |
---|---|
list of any: Instances owned by this registry |
__call__(key, value, default_val=None)
Grab the object in this registry based on @key and @value
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key |
str
|
What identification type to use to grab the requested object(s). Should be one of @self.all_keys. |
required |
value |
any
|
Value to grab. Should be the value of your requested object. |
required |
default_val |
any
|
Default value to return if @value is not found |
None
|
Returns:
Type | Description |
---|---|
any or set of any: requested unique object if @key is one of unique_keys, else a set if @key is one of group_keys |
Source code in omnigibson/utils/registry_utils.py
__init__(name, class_types=object, default_key='name', unique_keys=None, group_keys=None, default_value=m.DOES_NOT_EXIST)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
name of this registry |
required |
class_types |
class or list of class
|
class expected for all entries in this registry. Default is |
object
|
default_key |
str
|
default key by which to reference a given object. This key should be a publically accessible attribute in a given object (e.g.: object.name) and uniquely identify any entries |
'name'
|
unique_keys |
None or list of str
|
keys by which to reference a given object. Any key should be a publically accessible attribute in a given object (e.g.: object.name) i.e.: these keys should map to a single object |
None
|
group_keys |
None or list of str
|
keys by which to reference a group of objects, based on the key (e.g.: object.room) i.e.: these keys can map to multiple objects e.g.: default is "name" key only, so we will store objects by their object.name attribute |
None
|
default_value |
any
|
Default value to use if the attribute @key does not exist in the object |
m.DOES_NOT_EXIST
|
Source code in omnigibson/utils/registry_utils.py
add(obj)
Adds Instance @obj to this registry
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj |
any
|
Instance to add to this registry |
required |
Source code in omnigibson/utils/registry_utils.py
clear()
Removes all owned objects from this registry
get_dict(key)
Specific mapping dictionary within this registry corresponding to the mappings of @key. e.g.: if key = "name", this will return the dictionary mapping object.name to objects
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key |
str
|
Key with which to grab mapping dict from |
required |
Returns:
Name | Type | Description |
---|---|---|
dict | Mapping from identifiers to object(s) based on @key |
Source code in omnigibson/utils/registry_utils.py
get_ids(key)
All identifiers within this registry corresponding to the mappings of @key. e.g.: if key = "name", this will return all "names" stored internally that index into a object
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key |
str
|
Key with which to grab all identifiers from |
required |
Returns:
Name | Type | Description |
---|---|---|
set | All identifiers within this registry corresponding to the mappings of @key. |
Source code in omnigibson/utils/registry_utils.py
object_is_registered(obj)
Check if a given object @object is registered
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj |
any
|
Instance to check if it is internally registered |
required |
remove(obj)
Removes object @object from this registry
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj |
any
|
Instance to remove from this registry |
required |
Source code in omnigibson/utils/registry_utils.py
update(keys=None)
Updates this registry, refreshing all internal mappings in case an object's value was updated
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keys |
None or str or set or list of str
|
Which object keys to update. None is default, which corresponds to all keys |
None
|
Source code in omnigibson/utils/registry_utils.py
SerializableRegistry
Bases: Registry
, Serializable
Registry that is serializable, i.e.: entries contain states that can themselves be serialized /deserialized.
Note that this assumes that any objects added to this registry are themselves of @Serializable type!