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

dvc exp run --set-param does not change parameter values from a Python dict #6974

Closed
a-rostek opened this issue Nov 12, 2021 · 8 comments
Closed
Labels
A: experiments Related to dvc exp enhancement Enhances DVC ui user interface / interaction

Comments

@a-rostek
Copy link

Bug Report

dvc exp run --set-param does not change parameter values from a Python dict

Description

When trying to do dvc exp run --set-param my_params.py:my_dict.my_key=3 the parameter value is not changed to 3, it remains the same as previously. The output is:

Stage 'my_stage' didn't change, skipping                                                             

Reproduce

  1. git init
  2. dvc init
  3. dvc.yaml
stages:
  my_stage:
    cmd: cat a.txt > b.txt
    deps:
    - a.txt
    outs:
    - b.txt
    params:
    - my_params.py:
      - my_dict
  1. my_params.py
my_dict = {
    'my_key': 2
}
  1. echo dummyString > a.txt
  2. dvc exp run --set-param my_params.py:my_dict.my_key=3

Expected

I would expect this output (which can be achieved by changing the value of my_key manually in my_params.py and then running dvc exp run):

Running stage 'my_stage':                                                                            
> cat a.txt > b.txt
Updating lock file 'dvc.lock'                                                                        

To track the changes with git, run:

	git add dvc.yaml a.txt dvc.lock my_params.py
                                                                      
Reproduced experiment(s): exp-e60e4
Experiment results have been applied to your workspace.

To promote an experiment to a Git branch run:

	dvc exp branch <exp> <branch>


Environment information

Output of dvc doctor:

$ dvc doctor
DVC version: 2.8.3 (pip)
---------------------------------
Platform: Python 3.8.10 on Linux-5.11.0-40-generic-x86_64-with-glibc2.29
Supports:
	webhdfs (fsspec = 2021.10.1),
	http (aiohttp = 3.7.4.post0, aiohttp-retry = 2.4.5),
	https (aiohttp = 3.7.4.post0, aiohttp-retry = 2.4.5),
	s3 (s3fs = 2021.8.1, boto3 = 1.17.106)
Cache types: reflink, hardlink, symlink
Cache directory: xfs on /dev/sdb
Caches: local
Remotes: None
Workspace directory: xfs on /dev/sdb
Repo: dvc, git
@daavoo daavoo added A: experiments Related to dvc exp bug Did we break something? labels Nov 12, 2021
@daavoo
Copy link
Contributor

daavoo commented Nov 12, 2021

I can reproduce

@daavoo
Copy link
Contributor

daavoo commented Nov 12, 2021

There is an issue with how we update the python values:

lines[lineno] = lines[lineno].replace(
f" = {old_dct[key]['value']}", f" = {value}"
)

Wich only match assignments following that string pattern (" = foo")

@skshetry
Copy link
Member

We can only have basic write support for now (see #5777). Proper write support will require us to track segments of the source code, which gets complicated to support for dict/list inner items, but can be done. I attempted this on #5778, see #5778 (comment).

Unless we change anything internally, we have to live with these bugs.
Currently, Python as params is only meant to be used for simple things. Using other types of parameters files is recommended.

@daavoo
Copy link
Contributor

daavoo commented Nov 15, 2021

We can only have basic write support for now (see #5777). Proper write support will require us to track segments of the source code, which gets complicated to support for dict/list inner items, but can be done. I attempted this on #5778, see #5778 (comment).

Unless we change anything internally, we have to live with these bugs. Currently, Python as params is only meant to be used for simple things. Using other types of parameters files is recommended.

Makes sense. However, we could improve some UX interactions and/or remark this on the docs side.

We are currently just ignoring the errors from params that we can't parse, which can cause some crashes afterward and/or unexpected behavior (like this issue).

Perhaps we could just raise errors on unparsed params. Alternatively, we could try to collect the params that we failed to parse and check if they are actually dependencies or args to --set-params and fail only in that cases.

@dberenbaum
Copy link
Collaborator

I would expect from #5477 that if the parameter cannot be replaced, then dvc should fail, stating that the parameter cannot be found.

@daavoo
Copy link
Contributor

daavoo commented Nov 16, 2021

I would expect from #5477 that if the parameter cannot be replaced, then dvc should fail, stating that the parameter cannot be found.

That issue / P.R. was more about missing / incorrectly parsed params. The validation happens before the replacement.

We should probably validate after replacement (although afaik this is only an issue with Python format where the replacement is very hacky, as the snippet linked above).

@dberenbaum
Copy link
Collaborator

So dvc validates that my_params.py:my_dict.my_key exists but can't replace it? In that case, I agree that we should probably raise an error to say something like Unable to parse {file} to set parameter {key}. Please update {file} instead of using --set-param.

@daavoo daavoo reopened this Nov 16, 2021
@daavoo daavoo added enhancement Enhances DVC ui user interface / interaction and removed bug Did we break something? labels Nov 16, 2021
@dberenbaum
Copy link
Collaborator

Ultimately, it seems like other methods for logging parameters, like those discussed in #6506, may be a more useful approach than parsing/replacing parameters from Python files.

@mattseddon mattseddon closed this as not planned Won't fix, can't repro, duplicate, stale Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A: experiments Related to dvc exp enhancement Enhances DVC ui user interface / interaction
Projects
None yet
Development

No branches or pull requests

5 participants