pythonfb-hydra

Hydra access config filename from group


I want to access in my python code the name of the Hydra config file that I have choosen from the command line.

Let's consider this basic project architecture from the Hydra documentation:

├── conf
│   ├── config.yaml
│   ├── db
│   │   ├── mysql.yaml
│   │   └── postgresql.yaml
└── my_app.py

Then, let's say I run python my_app.py db=postgresql to choose postgresql from the group db. Then, in my python code, I will be able to access what is inside config.db, but how to access the db name itself? In other words, how to get postgresql from config?

I don't want to parse the command line arguments (even though this is very easy), but I am looking for a clean and easy way to do it with the Hydra config directly.


Solution

  • Based on this answer, this is possible since Hydra 1.1 with: ${hydra:runtime.choices.db}.