Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested Interpolation / Expansions #9196

Closed
m-gris opened this issue Mar 16, 2023 · 5 comments · Fixed by #9212
Closed

Nested Interpolation / Expansions #9196

m-gris opened this issue Mar 16, 2023 · 5 comments · Fixed by #9212
Assignees
Labels
A: hydra Related to hydra integration bug Did we break something?

Comments

@m-gris
Copy link

m-gris commented Mar 16, 2023

It would be really nice to have the possibility to nest string interpolations / variables expansions, ex. interpolating in dvc.yaml a field of params.yaml that is itself an interpolation of another field...

For example:

In params.yaml

paths: 
  data: 
    root: path/to/data/dir
    raw: ${paths.data.root}/raw/
  scripts: 
    root: path/to/stages/dir
    load: ${paths.scripts.root}

and then dvc.yaml

stages:
  load:
    cmd: python ${paths.scripts.load}
    outs: 
      - ${paths.raw}/filename.extension

This would really help in avoiding cumbersome & "error prone" hardcoding.

Many thanks in advance
Regards
M

@d-walkama
Copy link

+1

@pmrowla pmrowla added feature request Requesting a new feature p3-nice-to-have It should be done this or next sprint A: templating Related to the templating feature labels Mar 17, 2023
@dberenbaum
Copy link
Collaborator

@m-gris You are using the hydra integration, right? Does it not solve your use case, or you just want to simplify by not needing hydra?

@m-gris
Copy link
Author

m-gris commented Mar 19, 2023

@dberenbaum
Yes I do use the hydra integration indeed, but, afaik, it does not allow to do what I'm trying to do, i.e reduce hardcoding to the bare minimum by composing expanded variables as much as possible.

Here is a silly toy example that should suffice in illustrating what I have in mind:

Let's say that in config.yaml I have the following:

hydra_test:
    dir: 'raw'
    file: 'items.csv'
    path: ${hydra-test.dir}/${hydra_test.file}

The path key will indeed be properly parsed & evaluated if using OmegaConf in a python script.

But if, in dvc.yaml, I try to do the following:

stages:
    hydra_test:
        cmd: echo ${hydra_test.path}

It results in the following error:

/bin/bash: line 1: ${hydra_test.repo}/${hydra_test.file}: bad substitution

It would actually be really nice if dvc could interpret / evaluate those. :)

@daavoo
Copy link
Contributor

daavoo commented Mar 19, 2023

The path key will indeed be properly parsed & evaluated if using OmegaConf in a python script.

This should be also working and the params.yaml should contain the interpolated value.
I will take a look to find out why it is not working

@daavoo daavoo added bug Did we break something? A: hydra Related to hydra integration and removed feature request Requesting a new feature p3-nice-to-have It should be done this or next sprint A: templating Related to the templating feature labels Mar 19, 2023
@daavoo daavoo self-assigned this Mar 20, 2023
daavoo added a commit that referenced this issue Mar 20, 2023
@daavoo daavoo linked a pull request Mar 20, 2023 that will close this issue
@skshetry skshetry changed the title NESTED INTERPOLATION / EXPANSIONS Nested Interpolation / Expansions Mar 20, 2023
daavoo added a commit that referenced this issue Mar 20, 2023
skshetry pushed a commit that referenced this issue Mar 20, 2023
@m-gris
Copy link
Author

m-gris commented Mar 21, 2023

It now works like a charm with Hydra!
Thx.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A: hydra Related to hydra integration bug Did we break something?
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants