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

[Bug] Not able to Access Parent Fields in instantiate Interpolation #904

Closed
2 tasks done
Queuecumber opened this issue Aug 21, 2020 · 2 comments · Fixed by #911
Closed
2 tasks done

[Bug] Not able to Access Parent Fields in instantiate Interpolation #904

Queuecumber opened this issue Aug 21, 2020 · 2 comments · Fixed by #911
Labels
bug Something isn't working
Milestone

Comments

@Queuecumber
Copy link
Contributor

🐛 Bug

Description

Followup on #388 the parent fields seem to be getting lost again. If I have a field that is an interpolation of a field higher up in the hierarchy, I can print out the value fine but I can't use it within instiantiate.

Checklist

  • I checked on the latest version of Hydra
  • I created a minimal repro

To reproduce

** Minimal Code/Config snippet to reproduce **

Minimal code snippet which should print three times the same integer value.

The first print is the parent field
The second print accesses the child field, which is an interpolation of the parent field
The third print uses instantiate to create an object which takes the child field as a parameter and prints from that object

Before the third print happens the exception is thrown

import time
import hydra
import submitit

class GetsTheInteger:
    def __init__(self, same_integer):
        self.intval = intval
        

@hydra.main(config_name="test2.yaml")
def main(cfg) -> None:
    print(cfg.data.integer)
    print(cfg.data.test.same_integer)

    g = hydra.utils.instantiate(cfg.data.test)
    print(g.intval)    


if __name__ == "__main__":
    main()

** Stack trace/error message **

Traceback (most recent call last):
  File "/private/home/mehrlich/.conda/envs/qgac/lib/python3.7/site-packages/hydra/_internal/utils.py", line 203, in run_and_report
    return func()
  File "/private/home/mehrlich/.conda/envs/qgac/lib/python3.7/site-packages/hydra/_internal/utils.py", line 355, in <lambda>
    overrides=args.overrides,
  File "/private/home/mehrlich/.conda/envs/qgac/lib/python3.7/site-packages/hydra/_internal/hydra.py", line 110, in run
    job_subdir_key=None,
  File "/private/home/mehrlich/.conda/envs/qgac/lib/python3.7/site-packages/hydra/core/utils.py", line 123, in run_job
    ret.return_value = task_function(task_cfg)
  File "test2.py", line 15, in main
    g = hydra.utils.instantiate(cfg.data.test)
  File "/private/home/mehrlich/.conda/envs/qgac/lib/python3.7/site-packages/hydra/utils.py", line 68, in call
    raise HydraException(f"Error calling '{cls}' : {e}") from e
hydra.errors.HydraException: Error calling 'test2.GetsTheInteger' : str interpolation key 'data.integer' not found
        full_key: same_integer
        reference_type=Any
        object_type=dict

Expected Behavior

No crash, can instantiate objects whose parameters depend on interpolations of parent fields

System information

  • Hydra Version : git master
  • Python version : 3.7
  • Virtual environment type and version : Conda
  • Operating system : Ubuntu 18.04 (fair cluster)
@Queuecumber Queuecumber added the bug Something isn't working label Aug 21, 2020
@omry
Copy link
Collaborator

omry commented Aug 21, 2020

Your example is incomplete, where is the config file?

@omry omry added this to the 1.0.0 milestone Aug 21, 2020
@Queuecumber
Copy link
Contributor Author

Oops completely forgot to add it

data:
  integer: 10
  test:
    _target_: test2.GetsTheInteger
    same_integer: ${data.integer}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants