registry_utils
A set of utility functions for registering and tracking objects
Registry
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)
Unique_keys are other 1-to-1 mappings: i.e.: a single indexing value will return a single object. example: indexing by object.name (every object's name should be unique) Group_keys are 1-to-many mappings: 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
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 305 306 307 308 309 310 311 312 313 314 315 316 317 |
|
all_keys
property
Returns:
Type | Description |
---|---|
set of str
|
All object keys that are valid identification methods to index object(s) |
object_names
property
Get the names of the objects in this registry
Returns:
Type | Description |
---|---|
set of str
|
Names of the instances owned by this registry |
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=None)
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 or set 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 |
None
|
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:
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 Args: key (str): Key with which to grab all identifiers from
Returns:
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!
Source code in omnigibson/utils/registry_utils.py
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 |
|
uuid
property
Returns:
Type | Description |
---|---|
int
|
Unique hashed ID for this registry |
__init__(name, class_types=object, default_key='name', hash_key='uuid', unique_keys=None, group_keys=None, default_value=None)
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'
|
hash_key
|
str
|
key by which to reference a given object when serializing / deserializing its state. This key should be a publically accessible attribute in a given object (e.g.: object.name) and uniquely identify any entries via a hash value (i.e.: integer) |
'uuid'
|
unique_keys
|
None or list of str or set 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 |
None
|
Source code in omnigibson/utils/registry_utils.py
set_dump_filter(dump_filter)
Sets the internal filter that determines whether an object should be dumped or not.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dump_filter
|
function
|
Function that determines whether an object should be dumped or not. Expected signature is: def dump_filter(obj) -> bool where it takes in a given registered object @obj and returns True if the object should have its state dumped |
required |
Source code in omnigibson/utils/registry_utils.py
set_load_filter(load_filter)
Sets the internal filter that determines whether an object's state should be loaded or not.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
load_filter
|
function
|
Function that determines whether an object should have its state loaded or not Expected signature is: def load_filter(obj) -> bool where it takes in a given registered object @obj and returns True if the object should have its state loaded or not |
required |