0

Let's say I have a config like the following:

foo:
  a : 1
  b : 2
  c :
    aa : ???
    bb : 2
bar : ${foo.c}
baz : ${foo.c}

and want to specialise (or override) aa in bar and baz. Is there a clean way to do this? I can't see how to do this with the defaults list without some pain...

It would be nice if there was some syntax like:

...
bar : ${foo.c}
bar.c.aa : 1
baz : ${foo.c}
baz.c.aa : 2

or perhaps using the DSL syntax for command-line overrides...

EDIT: I want the result to be

foo:
  a : 1
  b : 2
  c :
    aa : ???
    bb : 2
bar :
  c : 
    aa : 1
    bb : 2
baz : 
  c : 
    aa : 2
    bb : 2

(ignore the fact that foo.c.aa is missing) I know how to do this programmatically, I am asking it if can be done just using some kind of resolution/interpolation.

It is possible to override values using the command line (with e.g. bar.c.aa=1), I want this functionality but in the .yaml file itself.

BenedictWilkins
  • 1,173
  • 8
  • 25

1 Answers1

1

Hydra does not support this kind of extension. You can achieve it by extending configs as described here.

Something like: You can compose the config node baz.c and bar.c via the defaults list, having a prototype foo/proto.yaml act as a base:

aa: ???
bb: 2

bar/c.yaml:

defaults:
 - /foo/c@c
c:
  aa: 1
  # bb will be "inherited" from /foo/c

baz/c.yaml:

defaults:
 - /foo/c@c
c:
  aa: 2
  # bb will be "inherited" from /foo/c

Note:

  1. I didn't run it so there could be something off here, but in general that's the way to go.
  2. Your example is opaque and it's hard to say what is important and what is not. There could be a cleaner way to achieve what you are actually trying to do.
Omry Yadan
  • 31,280
  • 18
  • 64
  • 87
  • 1
    Thanks for the answer this is what I had in mind using the defaults list bar one key feature. I was not aware that the package could be specified as `/foo/c@c` with `@c` being crucial for my problem. The issue was that I wanted to reuse `c` in a bunch of places under different names and override as above. I think my question did not reflect this... thank you for your time. – BenedictWilkins Jun 06 '22 at 14:29
  • Packages are documented in good details in the website: https://hydra.cc/docs/advanced/overriding_packages/ – Omry Yadan Jun 07 '22 at 15:03