-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Simpler param updates with python-benedict #4780
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
Simpler param updates with python-benedict #4780
Conversation
eca373a
to
8fe0b17
Compare
@@ -31,7 +30,7 @@ def _parse_params(path_params: Iterable): | |||
) | |||
if not path: | |||
path = ParamsDependency.DEFAULT_PARAMS_FILE | |||
ret[path] = unflatten(params) | |||
ret[path] = params |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be clear, this now returns a dict like:
{'path.to.key': yamlValue1, 'path[2]key': yamlValue2}
@@ -311,31 +310,18 @@ def _unpack_args(self, tree=None): | |||
|
|||
def _update_params(self, params: dict): | |||
"""Update experiment params files with the specified values.""" | |||
from benedict import benedict |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if you prefer local or global imports. Since this is only needed for the beta experiments feature, I figured local was appropriate.
[["foo=baz"], "{foo: baz, goo: {bag: 3}}"], | ||
[["foo=baz,goo=bar"], "{foo: baz, goo: bar}"], | ||
[["goo.bag=4"], "{foo: [bar: 1, baz: 2], goo: {bag: 4}}"], | ||
[["foo[0]=bar"], "{foo: [bar, baz: 2], goo: {bag: 3}}"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note the change in syntax, which I think is more in line with your future plans.
8fe0b17
to
31db81e
Compare
This is very cool, thanks for the PR! Since this will add a dependency I want to discuss this internally with the rest of the DVC team first before merging it, but everything looks good to me for now. |
"{foo: [bar: 1, baz: 3], goo: {bag: 3}, lorem: false}", | ||
], | ||
[ | ||
["foo[1]=- baz\n- goo"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This syntax is not easy to understand/use. At a first glance, I associated those =-
together and assumed it was removing items from the list.
Ideally, I'd like to have the following syntax:
$ dvc exp run --params 'foo[1]=[baz, goo]' 'bar={a:2, b: 3}'
I understand that we split it up by comma, so we cannot achieve that. We should consider using a different delimiter, maybe even space or semicolon and make it look JSON-like.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems a natural progression to support appending and removing similar to Hydra's syntax (they use ~foo
to remove and +foo=value
to append).
Or, maybe even use Hydra later directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that I didn't change anything regarding the syntax. This is the syntax already accepted by the yaml parser being used, which is separate from this change. I'm simply documenting what currently works.
That said, I agree that it it would be nice to be able to specify arguments that include commas, and I think that your suggestion of simply changing --params to read a list instead of a single string would be the most straight-forward way of doing it.
31db81e
to
39847ba
Compare
Rebased this PR and created #4883 for future consideration regarding hydra |
Thanks for the PR @sjawhar! |
β¦limit * 'master' of github.com:iterative/dvc: dag: add --outs option (iterative#4739) Add test server and tests for webdav (iterative#4827) Simpler param updates with python-benedict (iterative#4780) checkpoints: set DVC_ROOT environment variable (iterative#4877) api: add support for simple wildcards (iterative#4864) tests: mark azure test as flaky (iterative#4881) setup.py: limit responses version for moto (iterative#4879) remote: avoid chunking on webdav. Fixes iterative#4796 (iterative#4828) checkpoints: `exp run` and `exp res[ume]` refactor (iterative#4855)
@pmrowla Since hydra would change the syntax for this, I guess we better to do the switch before 2.0 if we indeed decide to go with it? Your call here. Could revert, or could submit benedict to conda-forge if we want (will be happy to help with sending one, we've sent a few already). |
β I have followed the Contributing to DVC checklist.
π If this PR requires documentation updates, I have created a separate PR (or issue, at least) in dvc.org and linked it here.
Thank you for the contribution - we'll try to review it as soon as possible. π
Description of Changes
Following up on my last comment on #4769
So I did some testing and my idea to use benedict to simplify the code actually works great...
almost. (Update: figured it out) As you can see in the changes here, you can replace a lot of code with a single built-in function call. This also has the benefit of using more standard[0]
syntax for list accessing.I added more tests to make sure that everything was working, then I ran into this strange behavior on a single test case:The params are being correctly updated and written, but for some reason the experiment doesn't seem to actually run the copy step. It's strange, and I would appreciate any help chasing this down...I just needed to add
goo
to the list of stage params π€¦Linting is failing on changes I didn't make.
TODO