⚙️ Setting Macros
Macros are a global set of hard-coded, "magic" numbers that are used as default values across OmniGibson. These values can have significant implications that broadly impact OmniGibson's runtime (such as setting HEADLESS
or DEFAULT_PHYSICS_FREQ
), or can have a much more narrow scope that impacts only a specific module within OmniGibson (such as FIRE_EMITTER_HEIGHT_RATIO
).
All macros within OmniGibson can be directly accessed and set via the omnigibson/macros.py
module. There are two sets of macros:
- Global Macros: Accessed via the
gm
module variable, these are fundamental settings that generally impact all parts of OmniGibson runtime, and include values such asgm.HEADLESS
,gm.DEFAULT_PHYSICS_FREQ
, andgm.ENABLE_HQ_RENDERING
. Descriptions of each global macro can be seen directly in theomnigibson/macros.py
file. - Module Macros Accessed via the
macros
module variable, these are module-level settings used by individual modules throughout OmniGibson. These tend to only impact the module they are defined in, though they can be referenced by other modules as well. Examples include values such asmacros.objects.stateful_object.FIRE_EMITTER_HEIGHT_RATIO
andmacros.robots.manipulation_robot.ASSIST_GRASP_MASS_THRESHOLD
. Descriptions of each module-level macro can be seen directly at the top of the module that it is defined in.
Reading Values
Macros can be read like any other python value. Both gm
and macros
are Addict dictionary-like objects, and whose keyword-indexed values can be queried via dot notation. Note that for macros
, this is a nested addict object and represents values as keyword-entries indexed by the relative path of the module it is specified in, expressed in dot notation. For example, to read a macro from omnigibson/prims/entity_prim.py
, you would query macros.prims.entity_prim.<MACRO_NAME>
. We provide an example snippet of code below:
read_macros.py
Setting Values
Macros can be set like any other python value, and utilize the same convention for accessing as stated above. However, a key caveat is that once a macro is read, it cannot be set. This is to guarantee consistent runtime performance and avoid silent bugs due to macros being updated but not read by relevant downstream use cases. For example, gm.HEADLESS
is read when og.launch()
or og.Environment()
is called to start up the OmniGibson application, and cannot be modified afterward. If there was no guard in place, setting this macro after OmniGibson is launched would result in an inconsistency between the observed state (i.e.: the mode requested when OmniGibson was originally launched) and the read state (modified value of gm.HEADLESS
). In general, we recommend setting all macros before og.launch()
or og.Environment()
is called. We provide an example snippet of code below: