question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug] interpolation to hydra.job.override_dirname containing another interpolation is not possible

See original GitHub issue

🐛 Bug

Now that #725 is fixed, I post an issue for the behavior I described in (https://github.com/facebookresearch/hydra/issues/725#issuecomment-653442315) In the following example an interpolation to hydra.job.override_dirname containing another interpolation results in a crash:

To reproduce

test.py:

import hydra
from omegaconf import DictConfig


@hydra.main(config_path="conf", config_name="config")
def run(config: DictConfig):
    print("c", config.c)


if __name__ == "__main__":
    run()

conf/config.yaml:

a: 10
b: 20

c: override_${hydra:job.override_dirname}

call: python test.py b=\${a} (I have to escape $)

** Stack trace/error message **

Traceback (most recent call last):
  File "/home/mtadmin/miniconda3/envs/debug_hydra/lib/python3.8/site-packages/hydra/_internal/utils.py", line 197, in run_and_report
    return func()
  File "/home/mtadmin/miniconda3/envs/debug_hydra/lib/python3.8/site-packages/hydra/_internal/utils.py", line 271, in <lambda>
    lambda: hydra.run(
  File "/home/mtadmin/miniconda3/envs/debug_hydra/lib/python3.8/site-packages/hydra/_internal/hydra.py", line 105, in run
    return run_job(
  File "/home/mtadmin/miniconda3/envs/debug_hydra/lib/python3.8/site-packages/hydra/core/utils.py", line 122, in run_job
    ret.return_value = task_function(task_cfg)
  File "/home/mtadmin/projects/debug_hydra/interpolation_jobdir/test.py", line 16, in run
    print("c", config.c)
  File "/home/mtadmin/miniconda3/envs/debug_hydra/lib/python3.8/site-packages/omegaconf/dictconfig.py", line 315, in __getattr__
    self._format_and_raise(key=key, value=None, cause=e)
  File "/home/mtadmin/miniconda3/envs/debug_hydra/lib/python3.8/site-packages/omegaconf/base.py", line 95, in _format_and_raise
    format_and_raise(
  File "/home/mtadmin/miniconda3/envs/debug_hydra/lib/python3.8/site-packages/omegaconf/_utils.py", line 555, in format_and_raise
    raise_(ex, cause)
  File "/home/mtadmin/miniconda3/envs/debug_hydra/lib/python3.8/site-packages/omegaconf/_utils.py", line 548, in raise_
    raise ex
  File "/home/mtadmin/miniconda3/envs/debug_hydra/lib/python3.8/site-packages/omegaconf/dictconfig.py", line 313, in __getattr__
    return self._get_impl(key=key, default_value=DEFAULT_VALUE_MARKER)
  File "/home/mtadmin/miniconda3/envs/debug_hydra/lib/python3.8/site-packages/omegaconf/dictconfig.py", line 377, in _get_impl
    return self._resolve_with_default(
  File "/home/mtadmin/miniconda3/envs/debug_hydra/lib/python3.8/site-packages/omegaconf/basecontainer.py", line 56, in _resolve_with_default
    resolved = self._resolve_interpolation(
  File "/home/mtadmin/miniconda3/envs/debug_hydra/lib/python3.8/site-packages/omegaconf/base.py", line 370, in _resolve_interpolation
    return self._resolve_simple_interpolation(
  File "/home/mtadmin/miniconda3/envs/debug_hydra/lib/python3.8/site-packages/omegaconf/base.py", line 344, in _resolve_simple_interpolation
    self._format_and_raise(key=inter_key, value=None, cause=e)
  File "/home/mtadmin/miniconda3/envs/debug_hydra/lib/python3.8/site-packages/omegaconf/base.py", line 95, in _format_and_raise
    format_and_raise(
  File "/home/mtadmin/miniconda3/envs/debug_hydra/lib/python3.8/site-packages/omegaconf/_utils.py", line 555, in format_and_raise
    raise_(ex, cause)
  File "/home/mtadmin/miniconda3/envs/debug_hydra/lib/python3.8/site-packages/omegaconf/_utils.py", line 548, in raise_
    raise ex
  File "/home/mtadmin/miniconda3/envs/debug_hydra/lib/python3.8/site-packages/omegaconf/base.py", line 335, in _resolve_simple_interpolation
    value = resolver(root_node, inter_key)
  File "/home/mtadmin/miniconda3/envs/debug_hydra/lib/python3.8/site-packages/omegaconf/omegaconf.py", line 335, in caching
    cache[key] if key in cache else resolver(*OmegaConf._tokenize_args(key))
  File "/home/mtadmin/miniconda3/envs/debug_hydra/lib/python3.8/site-packages/hydra/core/utils.py", line 150, in <lambda>
    lambda path: OmegaConf.select(cast(DictConfig, HydraConfig.get()), path),
  File "/home/mtadmin/miniconda3/envs/debug_hydra/lib/python3.8/site-packages/omegaconf/omegaconf.py", line 531, in select
    format_and_raise(node=cfg, key=key, value=None, cause=e, msg=str(e))
  File "/home/mtadmin/miniconda3/envs/debug_hydra/lib/python3.8/site-packages/omegaconf/_utils.py", line 623, in format_and_raise
    raise_(ex, cause)
  File "/home/mtadmin/miniconda3/envs/debug_hydra/lib/python3.8/site-packages/omegaconf/_utils.py", line 548, in raise_
    raise ex
omegaconf.errors.ConfigKeyError: str interpolation key 'a' not found
        full_key: hydra.job.override_dirname
        reference_type=Optional[HydraConf]
        object_type=HydraConf

Expected Behavior

the hydra.job.override_dirname should be able to interpolate a via b

System information

  • Hydra Version : master/1.0.0rc2
  • Python version : 3.8.3
  • Virtual environment type and version : miniconda
  • Operating system : ubuntu 18.04

Additional context

This can be worked arround with something like this:

hdr = HydraConfig.get()
override_dirname= hdr.job.override_dirname

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
immanuelwebercommented, Jul 27, 2020

even though that you fixed it already a while ago, I just wanted to say thank you for the fix!

0reactions
omrycommented, Jul 15, 2020

Yes, this is good.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Tutorial: Learning Hydra for configuring ML experiments
I overview a number of topics, including how to instantiate classes, run sweeps over parameters, and validate the configuration at run-time. The ...
Read more >
Complete tutorial on how to use Hydra in Machine Learning ...
Configuration can be specified or overridden from the command line; Dynamic command line tab completion; Run your application locally or launch ...
Read more >
How to override hydra working dir from within a script?
P.S. I use structured configs and had to change the code so it may not actually work but I hope you got the...
Read more >
Job Configuration | Hydra
You can override it via the command line, or your config file. hydra.job.chdir​. Decides whether Hydra changes the current working directory to the...
Read more >
TPSys 2.9 - IslandSMT
MYDATA and its suppliers shall not be liable for any damages related to this software or hardware, or for any other damages whatsoever ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found