Zranz
Zranz

Reputation: 67

Access hydra configuration within decorated method

I would like to access hydra configuration, e.g., sweeper, from the decorated function:

@hydra.main(config_name="config")
def my_app(cfg: Config) -> None:
    OmegaConf.to_yaml(cfg.hydra.sweeper)

Is there any parameter I can pass to @hydra.main() not to remove that configuration, or is there other place where I can find it? Thanks.

Upvotes: 0

Views: 377

Answers (1)

Omry Yadan
Omry Yadan

Reputation: 33646

from hydra.core.hydra_config import HydraConfig

@hydra.main()
def my_app(cfg: DictConfig) -> None:
    print(HydraConfig.get().sweeper)

You can also access it through the configuration with interpolation:

config.yaml:

hydra_sweeper: ${hydra:sweeper}

See this.

Upvotes: 2

Related Questions