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_zen.kwargs_of #598

Merged
merged 10 commits into from Nov 24, 2023
Merged

Adds hydra_zen.kwargs_of #598

merged 10 commits into from Nov 24, 2023

Conversation

rsokl
Copy link
Contributor

@rsokl rsokl commented Nov 24, 2023

(Very excited about this one!)

This PR adds a new config-creation function:

>>> from inspect import signature
>>> from hydra_zen import kwargs_of, instantiate

>>> Config = kwargs_of(lambda x, y: None)
>>> signature(Config)
<Signature (x:Any, y: Any) -> None>
>>> config = Config(x=1, y=2)
>>> config
kwargs_of_lambda(x=1, y=2)
>>> instantiate(config)
{'x': 1, 'y': 2}

Excluding the first parameter from the target's signature:

>>> Config = kwargs_of(lambda *, x, y: None, zen_exclude=[0])
>>> signature(Config)
<Signature (y: Any) -> None>
>>> instantiate(Config(y=88))
{'y': 88}

Like builds and just, kwargs_of is a classmethod of BuildsFn and thus is customizable accordingly.

This function is powerful because it decouples a config from the target, meaning that the target need not be importable nor do you ever have to call the target.

@rsokl rsokl added this to the v0.12.0 milestone Nov 24, 2023
@rsokl rsokl merged commit be42912 into main Nov 24, 2023
18 checks passed
@rsokl rsokl deleted the kwargs-fn branch November 24, 2023 18:30
@rsokl rsokl changed the title Adds hydra_zen.kwargs_fn Adds hydra_zen.kwargs_of Nov 24, 2023
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

Successfully merging this pull request may close these issues.

None yet

1 participant