Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compose defaults list dynamically before hydra.main #2905

Closed
blackwint3r opened this issue May 17, 2024 · 2 comments
Closed

compose defaults list dynamically before hydra.main #2905

blackwint3r opened this issue May 17, 2024 · 2 comments

Comments

@blackwint3r
Copy link

Not very familiar with hydra yet, not sure if this is a silly questions. Is it possible to compose a defaults list dynamically, before the @hydra.main function is invoked?
In my scenario, I aim to generate a defaults list dynamically based on a specific keyword schema. The objective is to utilize the value associated with schema as a structured configuration schema.

For instance, consider the following config.yaml:

name: John
highschool:
    _schema_: SchoolSchema
    name: CityHigh

And a corresponding schema file named schema/SchoolSchema.yaml:

schoolname: ???
location: RiverCity

The desired outcome would be a configuration that reflects the following structure:

defaults:
    - schema@highschool: SchoolSchema

name: John
highschool:
    name: CityHigh

I want to automatically handle the package path for nested dictionaries, so that I don't have to write a complicated defaults list. But I can't find a suitable place to do this, for the defaults list of DictConfig has already been parsed after hydra.main is called.

@odelalleau
Copy link
Collaborator

A few potential options that come to mind:

  1. Use the Compose API (if you don't need the extra functionalities offered by hydra.main())
  2. If you do need those extra functionalties, you may do it in two steps (use Compose API before calling hydra.main() to generate the final config and dump it to disk first)
  3. Maybe hydra-zen can offer some flexible way to achieve this as well (if you're willing to move all your config logic to Python)

@blackwint3r
Copy link
Author

thank you for your advice! I'll go investigate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants