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

Adds hydra_defaults to builds and make_config #264

Merged
merged 8 commits into from Apr 22, 2022
Merged

Adds hydra_defaults to builds and make_config #264

merged 8 commits into from Apr 22, 2022

Conversation

rsokl
Copy link
Contributor

@rsokl rsokl commented Apr 22, 2022

Closes #253

There is now formal support for specifying a Defaults List via builds and make_config:

cs = ConfigStore.instance()

config_store.store(group="x", name="a", node=builds(int, 10))
Conf = builds(dict, x=None, y="hi", hydra_defaults=["_self_", {"x": "a"}])
job = launch(Conf, instantiate)

print(job.return_value)
# prints: {"x": 10, "y": "hi"}

Previously, one needed to specify defaults as a meta-field in builds, which was more complex for the user and which made the resulting yaml more verbose.

For make_config, one can specify defaults instead of hydra_defaults -- for the sake of parity with how a structured config is written -- to the same effect. Specifying defaults and hydra_defaults simultaneously raises an error.

Validation performed on hydra_defaults

Basic runtime type-checking is performed on hydra_defaults:

>>> make_config(hydra_defaults="not a list")
HydraZenValidationError: `hydra_defaults` must be type `list[str | dict[str, str | list[str]]`, Got: 'not a list'

>>> make_config(hydra_defaults=[{"a": 1}])
HydraZenValidationError: `hydra_defaults` must be type `list[str | dict[str, str | list[str]]`, Got: [{'a': 1}]

Static type checkers will also flag bad defaults lists:

image

We also make some attempt to do some basic value validation as well. Specifically, we raise on duplicate "_self_" entries:

>>> make_config(hydra_defaults=["_self_", "_self_"])
HydraZenValidationError: `hydra_defaults` cannot have more than one '_self_' entry

And we warn users when "_self_" is not present:

>>> make_config(hydra_defaults=[])
UserWarning: Defaults list is missing `_self_`. See https://hydra.cc/docs/upgrades/1.0_to_1.1/default_composition_order for more information
types.Config

Presently, hydra_defaults is overly permissive; it would be nice to provide stricter value-validation on its contents.

@rsokl rsokl added the enhancement New feature or request label Apr 22, 2022
@rsokl rsokl added this to the hydra-zen 0.7.0 milestone Apr 22, 2022
@rsokl rsokl merged commit 6a157fc into main Apr 22, 2022
@rsokl rsokl deleted the support-defaults branch April 22, 2022 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add hydra_defaults argument to builds
1 participant