The compose API can compose a config similarly to
@hydra.main() anywhere in the code.
Prior to calling compose(), you have to initialize Hydra: This can be done by using the standard
or by calling one of the initialization methods listed below.
The Compose API is useful when
@hydra.main() is not applicable.
- Inside a Jupyter notebook (Example)
- Inside a unit test (Example)
- In parts of your application that does not have access to the command line (Example).
- To compose multiple configuration objects (Example with Ray).
There are 3 initialization methods:
initialize(): Initialize with a config path relative to the caller
initialize_config_module(): Initialize with config_module (absolute)
initialize_config_dir(): Initialize with a config_dir on the file system (absolute)
All 3 can be used as methods or contexts. When used as methods, they are are initializing Hydra globally and should only be called once. When used as contexts, they are initializing Hydra within the context can be used multiple times.