Search code examples
pythonfb-hydra

Returning the config from the function decorated with hydra.main()


Is there an option to get from the function under @hydra.main decorator the configuration object as a dictionary?

I tried something like this, but it returns None

@hydra.main(config_path="conf", config_name="config")
def my_app(cfg) -> dict:
    print(cfg) # --> work, the cfg object exists inside the function scope
    return cfg
a = my_app()
print(a)

I know I can use the compose API, but I prefer not to use it due to its limited functionality (Tab completion, Multirun etc.)


Solution

  • No. @hydra.main() does not return a value intentionally. (What would you expect the return value to be if you use --multirun and your function returns multiple times?)

    Call your logic from within your @hydra.main function and pass the cfg object to it.