facebookresearch / hydra

Hydra is a framework for elegantly configuring complex applications
https://hydra.cc
MIT License
8.6k stars 618 forks source link

[Bug] Dicts not merging #2305

Open slerman12 opened 2 years ago

slerman12 commented 2 years ago

Let's say I have two blocks, where one block depends on the other:

block1:
       arg1: 1
       arg2: 2

block2: ${block1}

Now I launch my program as python launch.py +block2.arg3=3

If I print block2, I get: {'arg3': 3}

However, I would like to get: {'arg1': 1, 'arg2': 2, 'arg3': 3}

Jasha10 commented 2 years ago

Hi @slerman12,

I think this touches on the limitations of OmegaConf's ${} interpolation.

Unfortunately I'm not aware of a workaround to achieve what you've indicated.

Edit: I was surprised to find that the same issue does not happen using pure OmegaConf:

>>> cfgA = OmegaConf.create({"block1": {"arg1": 1, "arg2": 2}, "block2": "${block1}"})
>>> cfgB = OmegaConf.create({"block2": {"arg3": 3}})
>>> OmegaConf.merge(cfgA, cfgB)
{'block1': {'arg1': 1, 'arg2': 2}, 'block2': {'arg1': 1, 'arg2': 2, 'arg3': 3}}

My instinct would be to regard this as a Hydra bug (and change Hydra to allow merging into interpolations like you've suggested).