Set of macros to use globally for OmniGibson. These are generally magic numbers that were tuned heuristically.
NOTE: This is generally decentralized -- the monolithic @settings variable is created here with some global values,
but submodules within OmniGibson may import this dictionary and add to it dynamically
create_module_macros(module_path)
Creates a dictionary that can be populated with module macros based on the module's @module_path
Parameters:
Name |
Type |
Description |
Default |
module_path
|
str
|
Relative path from the package root directory pointing to the module. This will be parsed
to generate the appropriate sub-macros dictionary, e.g., for module "dirty" in
omnigibson/object_states_dirty.py, this would generate a dictionary existing at macros.object_states.dirty
|
required
|
Returns:
Type |
Description |
MacroDict
|
addict/macro dictionary which can be populated with values
|
Source code in omnigibson/macros.py
| def create_module_macros(module_path):
"""
Creates a dictionary that can be populated with module macros based on the module's @module_path
Args:
module_path (str): Relative path from the package root directory pointing to the module. This will be parsed
to generate the appropriate sub-macros dictionary, e.g., for module "dirty" in
omnigibson/object_states_dirty.py, this would generate a dictionary existing at macros.object_states.dirty
Returns:
MacroDict: addict/macro dictionary which can be populated with values
"""
# Sanity check module path, make sure omnigibson/ is in the path
module_path = pathlib.Path(module_path)
omnigibson_path = pathlib.Path(__file__).parent
# Trim the .py, and anything before and including omnigibson/, and split into its appropriate parts
try:
subsections = module_path.with_suffix("").relative_to(omnigibson_path).parts
except ValueError:
raise ValueError(
"module_path is expected to be a filepath including the omnigibson root directory, got: {module_path}!"
)
# Create and return the generated sub-dictionary
def _recursively_get_or_create_dict(dic, keys):
# If no entry is in @keys, it returns @dic
# Otherwise, checks whether the dictionary contains the first entry in @keys, if so, it grabs the
# corresponding nested dictionary, otherwise, generates a new MacroDict() as the value
# It then recurisvely calls this function with the new dic and the remaining keys
if len(keys) == 0:
return dic
else:
key = keys[0]
if key not in dic:
dic[key] = MacroDict()
return _recursively_get_or_create_dict(dic=dic[key], keys=keys[1:])
return _recursively_get_or_create_dict(dic=macros, keys=subsections)
|