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

[solvers] Reformulate SolverOptions.SetOption to use our variant #22282

Merged

Conversation

jwnimmer-tri
Copy link
Collaborator

@jwnimmer-tri jwnimmer-tri commented Dec 9, 2024

This simplifies our API surface for users, and makes the implementation of #22078 easier.

Towards #22078.


This change is Reviewable

@jwnimmer-tri jwnimmer-tri added priority: low release notes: newly deprecated This pull request contains new deprecations labels Dec 9, 2024
@jwnimmer-tri
Copy link
Collaborator Author

+@hongkai-dai would you like to feature-review this?

Copy link
Contributor

@hongkai-dai hongkai-dai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 4 of 5 files at r1.
Reviewable status: 1 unresolved discussion, LGTM missing from assignee hongkai-dai, needs platform reviewer assigned, needs at least two assigned reviewers


solvers/solver_options.cc line 28 at r1 (raw file):

  std::visit(
      overloaded{
          [&](double& unboxed_value) {

Curious why we use a reference double& instead of const reference here? And why we use std:move(key) instead of const std::string_view& key?

This means we need to deprecate the old kwarg names in pydrake (while
also back-filling its missing test cases).
@jwnimmer-tri jwnimmer-tri force-pushed the solver-options-kwarg-names branch from 1bede16 to 5faa1fe Compare December 9, 2024 21:06
Copy link
Collaborator Author

@jwnimmer-tri jwnimmer-tri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 1 unresolved discussion, LGTM missing from assignee hongkai-dai, needs platform reviewer assigned, needs at least two assigned reviewers


solvers/solver_options.cc line 28 at r1 (raw file):

Previously, hongkai-dai (Hongkai Dai) wrote…

Curious why we use a reference double& instead of const reference here? And why we use std:move(key) instead of const std::string_view& key?

The goal is to avoid move the value into place when it's a string. I've respelled the code a bit to hopefully make that more clear?

Copy link
Contributor

@hongkai-dai hongkai-dai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 5 files at r1.
Reviewable status: 1 unresolved discussion, LGTM missing from assignee hongkai-dai, needs platform reviewer assigned, needs at least two assigned reviewers


solvers/solver_options.cc line 28 at r1 (raw file):

Previously, jwnimmer-tri (Jeremy Nimmer) wrote…

The goal is to avoid move the value into place when it's a string. I've respelled the code a bit to hopefully make that more clear?

I see. Thanks! Let me rephrase it to make sure I understand

Since we just move value into solver_options_str_, we want to make sure that everything is rvalue, hence we use rvalue reference here.

Copy link
Collaborator Author

@jwnimmer-tri jwnimmer-tri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 1 unresolved discussion, LGTM missing from assignee hongkai-dai, needs platform reviewer assigned, needs at least two assigned reviewers


solvers/solver_options.cc line 28 at r1 (raw file):

Previously, hongkai-dai (Hongkai Dai) wrote…

I see. Thanks! Let me rephrase it to make sure I understand

Since we just move value into solver_options_str_, we want to make sure that everything is rvalue, hence we use rvalue reference here.

Yes, exactly.

(I believe using the lvalue reference and moving from it (as I did in r1) would also still avoid the copying, but is less clear to a person reading the code. Writing out the && in the signature here most clearly communicate the intention.)

Copy link
Contributor

@hongkai-dai hongkai-dai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm: +@ggould-tri for platform review please, thanks!

Reviewable status: LGTM missing from assignee ggould-tri(platform)


solvers/solver_options.cc line 28 at r1 (raw file):

Previously, jwnimmer-tri (Jeremy Nimmer) wrote…

Yes, exactly.

(I believe using the lvalue reference and moving from it (as I did in r1) would also still avoid the copying, but is less clear to a person reading the code. Writing out the && in the signature here most clearly communicate the intention.)

Got it, thanks for the explanation!

Copy link
Contributor

@ggould-tri ggould-tri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 4 of 5 files at r1, 1 of 1 files at r2, all commit messages.
Reviewable status: :shipit: complete! all discussions resolved, LGTM from assignees ggould-tri(platform),hongkai-dai

@jwnimmer-tri jwnimmer-tri merged commit a69a9ab into RobotLocomotion:master Dec 10, 2024
10 checks passed
@jwnimmer-tri jwnimmer-tri deleted the solver-options-kwarg-names branch December 10, 2024 16:57
RussTedrake pushed a commit to RussTedrake/drake that referenced this pull request Dec 15, 2024
…otLocomotion#22282)

This means we need to deprecate the old kwarg names in pydrake (while
also back-filling its missing test cases).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: low release notes: newly deprecated This pull request contains new deprecations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants