Skip to content

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

Merged
merged 1 commit into from
Nov 12, 2020

Conversation

sjawhar
Copy link
Contributor

@sjawhar sjawhar commented Oct 23, 2020

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:
image

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

  • What's up with that weird behavior?!
  • Run the full test suite to make sure I didn't break anything elsewhere πŸ˜„

@sjawhar sjawhar force-pushed the feature/exp-simpler-param-updates branch from eca373a to 8fe0b17 Compare October 23, 2020 15:41
@@ -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
Copy link
Contributor Author

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
Copy link
Contributor Author

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}}"],
Copy link
Contributor Author

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.

@sjawhar sjawhar force-pushed the feature/exp-simpler-param-updates branch from 8fe0b17 to 31db81e Compare October 24, 2020 16:34
@pmrowla pmrowla added enhancement Enhances DVC A: experiments Related to dvc exp labels Oct 26, 2020
@pmrowla
Copy link
Contributor

pmrowla commented Oct 26, 2020

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.

@efiop efiop requested a review from skshetry November 3, 2020 15:28
"{foo: [bar: 1, baz: 3], goo: {bag: 3}, lorem: false}",
],
[
["foo[1]=- baz\n- goo"],
Copy link
Collaborator

@skshetry skshetry Nov 11, 2020

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.

Copy link
Collaborator

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.

Copy link
Contributor Author

@sjawhar sjawhar Nov 11, 2020

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.

@pmrowla
Copy link
Contributor

pmrowla commented Nov 12, 2020

Rebased this PR and created #4883 for future consideration regarding hydra

@pmrowla pmrowla merged commit 72ec2a8 into iterative:master Nov 12, 2020
@pmrowla
Copy link
Contributor

pmrowla commented Nov 12, 2020

Thanks for the PR @sjawhar!

I159 added a commit to I159/dvc that referenced this pull request Nov 12, 2020
…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)
@efiop
Copy link
Contributor

efiop commented Nov 18, 2020

@sjawhar @pmrowla Unfortunately there is no such package in conda, which means we can't use benedict as is (this exp feature won't work in conda's dvc 1.10 package πŸ™ ). Is there an alternative lib that has conda package?

@efiop efiop mentioned this pull request Nov 18, 2020
3 tasks
@pmrowla
Copy link
Contributor

pmrowla commented Nov 19, 2020

Hydra does have a conda package (#4883). This can probably just be reverted until we get to that issue.

@efiop

@efiop
Copy link
Contributor

efiop commented Nov 19, 2020

@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).

@sjawhar sjawhar deleted the feature/exp-simpler-param-updates branch November 20, 2020 01:18
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants