-
Notifications
You must be signed in to change notification settings - Fork 15
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 prototype of hydra_zen.like #219
Conversation
This sounds intriguing, but I think I need a bit more time to wrap my head around exactly what's going on (it probably doesn't help that I haven't played around with
I'm understanding that the combination of
So in a way, it's like the recursive instantiation added in Hydra 1.1 except instead of recursing into the init parameters of the target object, we're recursing into the target object's methods and attributes once it's already instantiated. Is that the advantage you're looking to demonstrate, or am I missing something? Could you elaborate on how this fulfills the role of Thanks in advance for the clarification! I'll be interested to understand better |
That is correct. Without In general, given conf = hydra_zen.like(obj)
conf = conf("hello")
conf = conf.a
conf = conf.b
out = instantiate(conf) # performs: `obj("hello").a.b` So the advantage that I am demonstrating is that
I'm glad you asked this; the way you posed the question helped me realize that there is indeed a significant discrepancy between the proposed I see now how |
Closing this for now. I think it is a neat idea, but if the main application of |
@addisonklinke see #256 for a new discussion of |
Potentially addresses: #205
#219 prototypes a potential solution to the above, that is much more powerful than what I had initially proposed. This is inspired by @jgbos ' out of left field idea 😄
Let's see
hydra_zen.like
in action:what is going on here?
hydra_zen.like(<target>)
returns a_Tracker
instance that records all subsequent interactions with<target>
. Right now, "interactions" are restricted to accessing attributes and calling the target.hydra_zen.just
then knows how to convert a_Tracker
instance into a valid Hydra config.Let's use this to make a config that actually returns the
manual_seed
method of our Generator-instance:Here is a silly example, just to help give more of a feel for this:
Current thoughts on this prototype
One nice thing about
like
is that looks like a simple pass-through to IDEs, so you get auto-completes, static type checks, etc. as you build your "like expression" prior to creating the config.Some obvious to-dos would include:
GenLike().manual_seedling(42)
should raise a runtime error becausemanual_seedling
is not an attribute ofGenerator
.just(like(<...>).<...>)
expression as clean as possiblejust(like(<target>)(*args, **kwargs))
should reduce down tobuilds(<target>, *args, **kwargs)
like
'd objects in their configs without them needing to calljust
first.I would definitely like to get feedback on this. I only just thought of it, and will have to think carefully about potential pitfalls as well as about possible use cases that I haven't anticipated yet.
Additional functionality
like
could also fulfill the role of the proposedhydra_zen.hydrate