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

Parent node's information is lost when performing deepcopy. #388

Merged
merged 5 commits into from Jan 25, 2020
Merged

Parent node's information is lost when performing deepcopy. #388

merged 5 commits into from Jan 25, 2020

Conversation

shagunsodhani
Copy link
Contributor

Motivation

Parent node's information is lost when performing deepcopy.

OmegaConf misbehaves with the deepcopy function and the information about the parent (node) is lost. This leads to errors where a variable's value can not be resolved. The error message looks like this -
KeyError: "str interpolation key 'hydra.ax.experiment' not found". This commit provides a temporary workaround for the problem, by setting the parent of the copied config as that of the original config.
One testcase is also added to check for this bug.

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

Added a testcase.

OmegaConf misbehaves with the deepcopy function and the information
about the parent (node) is lost. This leads to errors where a variable's
value can not be resolved. The error message looks like this -
`KeyError: "str interpolation key 'hydra.ax.experiment' not found"`.
This commit provides a temporary workaround for the problem, by
setting the parent of the copied config as that of the original config.
One testcase is also added to check for this bug.
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jan 22, 2020
hydra/utils.py Outdated Show resolved Hide resolved
) -> None:
# Check if the instantiate method maintains the parent when making a deepcopy
conf = OmegaConf.create(input_conf)
orig = copy.deepcopy(conf)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need to do the deepcopy here.
Instantiate is doing the deepcopy.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are also testing passthrough.
just make your test another case of test_class_instantiate.
(You can add additional parameters set to the list there).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can get rid of the deepcopy part. Regarding adding extra params to test_class_instantiate, I think it will make it a little messy as we need a nested config and need to call instantiate over a specific node in the config. If that is fine, I can merge the two testcases.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As long as the test code is the same (and it can be), you can reduce duplication with parametrize.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merged the test cases

Two new params are added to the method for testing class instantiation.
These are - key_to_get_config (for select which node in the config
should be sent to the instantiation method) and kwargs_to_pass (for the
key-value args to pass to instantiation method). Now we can merge three
of our test cases in a single function.
@omry omry merged commit c887fd0 into facebookresearch:master Jan 25, 2020
@Queuecumber
Copy link
Contributor

@omry I think this may have accidentally been reverted at some point (it looks like there were big changes to instantiate since this PR), I'm getting this error and master doesn't seem to have the set_parent call

@omry
Copy link
Collaborator

omry commented Aug 21, 2020

I think there are tests that should test this.
Please file a new issue with a minimal repro of the problem you have (as well as which version it worked with).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants