Version: 1.0
Using the config object
Β
Your configuration object is an instance of OmegaConf's DictConfig.
Here are some of the basic features:
config.yaml
node: # Config is hierarchical
loompa: 10 # Simple value
zippity: ${node.loompa} # Value interpolation
do: "oompa ${node.loompa}" # String interpolation
waldo: ??? # Missing value, must be populated prior to access
my_app.py
@hydra.main(config_name="config")
def my_app(cfg: DictConfig):
assert cfg.node.loompa == 10 # attribute style access
assert cfg["node"]["loompa"] == 10 # dictionary style access
assert cfg.node.zippity == 10 # Value interpolation
assert isinstance(cfg.node.zippity, int) # Value interpolation type
assert cfg.node.do == "oompa 10" # string interpolation
cfg.node.waldo # raises an exception
Outputs:
$ python my_app.py
Missing mandatory value: waldo
full_key: waldo
reference_type=Optional[Dict[Any, Any]]
object_type=dict
You can learn more about OmegaConf here.