Abhishek Bhatia
05/27/2024, 9:50 AMvariants:
1:
- f1
- f2
5:
- f7
- 78
global: ${variants.1}
Referencing it as ${variants.1}
fails with the following error:
InterpolationKeyError: Interpolation key 'variants.1' not found
full_key: global
object_type=dict
Changing 1 and 5 to strings solves it but explicitly want the keys to be integer. Note that specifying it as integer works fine, it's just when I reference the key somewhere, it errors out
variants:
"1":
- f1
- f2
"5":
- f7
- 78
global: ${variants.1}
Does anybody have solution? 🙂Jitendra Gundaniya
05/27/2024, 12:41 PMAnkita Katiyar
05/28/2024, 11:37 AMomegaconf
yet - https://github.com/omry/omegaconf/issues/864
The workaround is just what you mentioned, convert the keys to string!Jitendra Gundaniya
05/28/2024, 1:25 PMfrom omegaconf import OmegaConf
# <https://github.com/omry/omegaconf/blob/master/omegaconf/_impl.py#L62>
def select2(key: str, secondary_key, default=None, *, _parent_):
return OmegaConf.to_container(_parent_[key], resolve=True)[secondary_key]
OmegaConf.register_new_resolver("select2", select2, replace=True)
Then, use this resolver in your YAML:
variants:
1:
- f1
- f2
5:
- f7
- 78
global: ${select2:variants, 1}
Note: it's using _parent_
which is a special OmegaConf internal that allow you to access the config tree within the resolver.Abhishek Bhatia
05/29/2024, 6:29 AM_parent_
and for referencing the issue ✌️