Combine argparse and config files

Is it possible to combine flags from the argparse interface and config files?

Consider this pseudo example:

Project structure:

├── guild.yml
├── model_flags.yml
import argparse

class Model:
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def from_config_file(cfg: Dict):
        return Model(x=cfg["x"], y=cfg["y"])

def main():
    pa = argparse.ArgumentParser("Main arguments for choosing higher order components.")

    config_file = load_config("model_flags.yml")
    mdl = Model.from_config_file(config_file)

    dataframe = load_dataframe(args.csv_path)
    train_model_on_dataframe(mdl, dataframe)

if __name__ == "__main__":

# model_flags.yml
- config: model_flags
  description: Collection of parameters for my model.
      default: 5
      type: int
      default: 10
      type: int

# guild.yml
  main: train
    csv_path: "my_path.csv"

Can I get guild to recognize the flags specified in model_flags.yml? It would be cool if I could do something like:

guild run example x=2 y=10
guild run example # Just use default values in model_flags.yml

The way I do this now is by specifying x and y through argparse and then use $include operator in my guild.yml file for the model_flags.yml flags, but I still have to specify x and y through argparse.

I was wondering if you could do something like:

# guild.yml
  main: train
    - config:model_flags.yml
    - config:model2_flags.yml
    csv_path: "my_path.csv"

I was looking through the hydra examples, but I don’t necessarily want to use hydra for this. I am fine with simple yaml config files or guild files.


How about use the feature of batch files Runs, you can even combine

  1. argparse default value
  2. flag value in the guild.yml file
  3. batch files and batch from command line

note that the overwrite order is 3>2>1.