-
Notifications
You must be signed in to change notification settings - Fork 14
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
Implements zen-wrappers #122
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jgbos
approved these changes
Oct 7, 2021
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was still a big change, luckily was looking at this before you finished.
jgbos
approved these changes
Oct 7, 2021
Thanks for reviewing all of it! |
Yeah, this is really stuff. But now I have deprecation warnings everywhere :) |
This was referenced Oct 7, 2021
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds a new feature:
builds( .... zen_wrappers=<..>)
.This is an extremely powerful feature that enables one to inject modifications to the instantiation process by including wrappers in a target's configuration.
The Basics
Whereas
calls
f(*args, **kwargs)
, the following config with wrapperswill instantiate as:
The wrapper paradigm enables arbitrary pre-processing, post-processing, and transformation of the target and its inputs/outputs.
Seeing it in Action
Suppose we have a function that takes in a temperature in Farenheit, and converts it to Celcius.
But we discover that we need the temperature to be converted to Kelvin instead. We can modify our config to include the following wrapper:
Another use case
In the next PR, users will be able to add pydantic validation to the instantiation process.
More Advanced Details
Wrappers are configurable
The wrappers themselves can be made configurable:
None
can be used as a placeholder for wrappersNone
can be be interspersed among wrappers; it will be ignored. This means thatNone
can be used as a placeholder for wrappers that are going to be toggled on/off from the CLI, via config groups. See the next subsection for an example.Wrappers can be specified via interpolated fields
One can specify interpolation strings as wrappers. This, in conjunction with
zen_meta
means that wrappers can be controlled via groups and from the CLI:Let's "turn on" our two wrappers (this can be done from CLI with groups, but we'll do it manually)
Bells and Whistles
yaml Representations
zen_processing
handles the process of importing wrapper-functions for us, so we don't need to useJust
everywhere. This leads to tidy yamlsWe will do some nice auto-flattening of wrappers too:
User-Friendly Warning About Mismatched Interpolation Levels
Using interpolated strings with
zen_meta
andzen_wrappers
together is a natural fit. However, it can be tricky to figure out the right level of interpolation when you have things nested in a list. This can lead to pretty hard-to-find runtime errors.Fortunately, we can easily detect the level of relative interpolation, and warn users – recommending the correct interpolation.
E.g.
We make no attempt to predict things about absolute interpolations, only relative.
User-Friendly Annotations
Because
zen_wrappers
is a somewhat-sophisticated feature, it is important that users are given as much guidance as possible so that they catch bugs before they actually run their Hydra job. In addition to aggressive input validation, we provide incisive annotations too: