fb-hydrahydra-core

Why does the value interpolation not work when using python hydra library?


I modify the config.yaml form the tutorials in the hydra repository as follows:

defaults:
  - db: mysql
  - ui: full
  - schema: school

test_key: ${db.user}

However, the test_key is still ${db.user} in the output without being replaced by the actual value omry. I type the command python my_app.py in the folder.


Solution

  • OmegaConf interpolations are resolved when you access the field. To see the resolved value, add resolve=True to the call OmegaConf.to_yaml():

    print(OmegaConf.to_yaml(cfg, resolve=True))
    

    Or just access the field (cfg.test_key).

    As a side note, I recommend that you go over the documentation of OmegaConf.