itamar kanter
itamar kanter

Reputation: 1360

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.)

Upvotes: 4

Views: 1564

Answers (1)

Omry Yadan
Omry Yadan

Reputation: 33646

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.

Upvotes: 3

Related Questions