omegaconf

Extend list in omegaconf from command line


I have a configuration similar to this from a yaml file

training_variables:
   - var1
   - var2

I want to extend the list using an additional variable, and I want to do it from the command line. How to do it? It seems not possible but I think it can be very useful if you want to experiment a new setup without changing the configuration file every time. I was wondering something like this:

train.py training_variables=$training_variables+['var3']

Solution

  • This is not supported, and is not planned to be supported in the form you are requesting.

    A practical solution is to split your list into two variables and concatenate them in the code.

    base_list:
     - a
     - b
    extra_list: []
    

    train.py:

      ...
      combined_list = cfg.base_list + cfg.extra_list
      ...
    
    $ python train.py 'extra_list=[c,d,e]'
    

    I am not 100% sure the above command line would work with an app using OmegaConf directly but it should work with Hydra 1.0 or newer.