Add reference tag to allow getting a varaible by reference#3025
Closed
vladoovtcharov wants to merge 1 commit into
Closed
Add reference tag to allow getting a varaible by reference#3025vladoovtcharov wants to merge 1 commit into
vladoovtcharov wants to merge 1 commit into
Conversation
This was referenced Feb 7, 2025
Closed
Collaborator
|
Thank you for the PR. This is an interesting idea, and the I am going to close this PR for now because this API has not had maintainer feedback or buy-in yet. Beyond the missing tests and news fragment, there are also fundamental design questions still open, including initialization order, how references interact with normal OmegaConf interpolation, and cycle detection / error semantics. Please continue the design discussion on #1393 before opening a new implementation PR. This will not make it into the upcoming 1.4 release. |
This file contains hidden or 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
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.
Motivation
Adds the ability to reference a variable without making a copy, similar to that proposed in #1393
Instead of singleton: true being added to the object, instead anywhere that wants to be instantiated as a reference to that variable can use the syntax:
foo: bar: _target_: "myclass" x: 4.0 reference_variable: _reference_: "foo.bar"Then reference variable and foo.bar will refer to the same object after instantiate.
By registering a custom resolver the syntax ends up looking even nicer:
foo: bar: _target_: "myclass" x: 4.0 reference_variable: ${ref:foo.bar}Have you read the Contributing Guidelines on pull requests?
Yes
Test Plan
Add test cases, especially for almost circular cases, e.g.
`
foo:
a: ${ref:bar.y}
b:
target: "ClassA"
bar:
x: ${ref:foo.b}
y:
target: "ClassB"
`
Also a bit worried about performance/memory usage with the proposed implementation but not sure about the best way to test that.
Related Issues and PRs
A different approach to PR#3103 but solves similar problem