Search code examples
pythonfb-hydraomegaconf

Hydra / OmegaConf: interpolation of config groups


Is it possible to interpolate a config group? My intention is to interpolate a group's key from other keys, in this example: selecting a dataset's config group based on the dataset name and the dataset version (e.g, if the dataset comes from a competition, this might be one of the tasks of the competition). Using hydra's structured configs, my idea is something like this:

@dataclass
class MainConfig(DictConfig):
   dataset_name: str
   dataset_version: str
   dataset_group: ${.dataset_name}_${.dataset_version}

@dataclass
cass MyDatasetPart1Config(DictConfig):
   paths: dict[str, str]

cs = ConfigStore.instance()
cs.store(name="config", node=MainConfig)
cs.store(group="dataset", name="mydataset_part1", node=MyDatasetPart1Config)

def main() ...
if __name__ == "__main__" ...

then be able to call the group like

>>> python myapp.py dataset_name=mydataset version=part1

hoping to be achieve the same as if I used

>>> python myapp.py dataset_group=mydataset_part1

Solution

  • No. Config group interpolation is a special implementation that is different than normal interpolation and can only access other config groups. The reason is that the config groups determine how the config is constructed and therefore cannot use values from the constructed config.

    See this documentation section for more info. You should be able to achieve something similar to what you are after using the pattern described there.