-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Add python binding for branch_and_bound #13002
Add python binding for branch_and_bound #13002
Conversation
a07e36f
to
d0b72aa
Compare
d0b72aa
to
4c48282
Compare
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.
+@EricCousineau-TRI for feature review please, thanks!
Reviewable status: LGTM missing from assignee EricCousineau-TRI(platform), needs at least two assigned reviewers (waiting on @EricCousineau-TRI)
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.
First pass done, PTAL.
Reviewed 5 of 5 files at r1.
Reviewable status: 5 unresolved discussions, LGTM missing from assignee EricCousineau-TRI(platform), needs at least two assigned reviewers (waiting on @hongkai-dai)
a discussion (no related file):
Can you add this important into pydrake.solvers.all
?
https://github.com/RobotLocomotion/drake/blob/92a2bea5f7c116608f9217da2de72135b305f860/bindings/pydrake/solvers/all.py
And then can you test it here?
drake/bindings/pydrake/test/all_test.py
Line 140 in 92a2bea
# solvers |
bindings/pydrake/solvers/branch_and_bound_py.cc, line 20 at r1 (raw file):
py::module::import("pydrake.solvers.mathematicalprogram"); py::class_<MixedIntegerBranchAndBound>(
nit Consider using the using Class = ...; constexpr auto cls_doc = ...
convention mentioned here:
drake/bindings/pydrake/pydrake_doxygen.h
Lines 202 to 213 in 92a2bea
@note Consider using scoped aliases to abbreviate both the usage of bound types | |
and the docstring structures. Borrowing from above: | |
~~~{.cc} | |
{ | |
using Class = RigidTransform<T>; | |
constexpr auto& cls_doc = doc.RigidTransform; | |
py::class_<Class>(m, "RigidTransform", cls_doc.doc) | |
.def(py::init(), cls_doc.ctor.doc_0args) | |
... | |
} | |
~~~ |
bindings/pydrake/solvers/branch_and_bound_py.cc, line 22 at r1 (raw file):
py::class_<MixedIntegerBranchAndBound>( m, "MixedIntegerBranchAndBound", doc.MixedIntegerBranchAndBound.doc) .def(py::init(
nit Can I ask why py::init<const MathematicalProgram&, const SolverId&>()
does not work here?
bindings/pydrake/solvers/branch_and_bound_py.cc, line 52 at r1 (raw file):
return self.GetSolution(mip_vars, nth_best_solution); }, py::arg("mip_var"), py::arg("nth_best_solution") = 0,
nit Should this be mip_vars
? (mip_var
is used for the arg, which seems inconsistent?)
bindings/pydrake/solvers/branch_and_bound_py.cc, line 60 at r1 (raw file):
return self.GetSolution(mip_vars, nth_best_solution); }, py::arg("mip_var"), py::arg("nth_best_solution") = 0,
nit Should this be mip_vars
? (mip_var
is used for the arg, which seems inconsistent?)
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.
Reviewable status: 1 unresolved discussion, LGTM missing from assignee EricCousineau-TRI(platform), needs at least two assigned reviewers (waiting on @EricCousineau-TRI)
a discussion (no related file):
Previously, EricCousineau-TRI (Eric Cousineau) wrote…
Can you add this important into
pydrake.solvers.all
?
https://github.com/RobotLocomotion/drake/blob/92a2bea5f7c116608f9217da2de72135b305f860/bindings/pydrake/solvers/all.pyAnd then can you test it here?
drake/bindings/pydrake/test/all_test.py
Line 140 in 92a2bea
# solvers
Done.
bindings/pydrake/solvers/branch_and_bound_py.cc, line 22 at r1 (raw file):
Previously, EricCousineau-TRI (Eric Cousineau) wrote…
nit Can I ask why
py::init<const MathematicalProgram&, const SolverId&>()
does not work here?
Done. I didn't know we can add python binding for constructor in this way. Thanks!
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.
Reviewable status: 1 unresolved discussion, LGTM missing from assignee EricCousineau-TRI(platform), needs at least two assigned reviewers, commits need curation (https://drake.mit.edu/reviewable.html#curated-commits) (waiting on @EricCousineau-TRI)
a discussion (no related file):
Previously, hongkai-dai (Hongkai Dai) wrote…
Done.
BTW, do I need to add a unit test for all.py
? I could do
import pydrake.solvers.all
x = pydrake.solvers.all.MixedIntegerBranchAndBound
on my python console.
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.
Reviewed 2 of 2 files at r2.
Reviewable status: 1 unresolved discussion, LGTM missing from assignee EricCousineau-TRI(platform), needs at least two assigned reviewers, commits need curation (https://drake.mit.edu/reviewable.html#curated-commits) (waiting on @EricCousineau-TRI)
a discussion (no related file):
Previously, hongkai-dai (Hongkai Dai) wrote…
Done.
Can you also have it be tested in all_test.py
, linked in prior comment?
bindings/pydrake/solvers/branch_and_bound_py.cc, line 22 at r1 (raw file):
Previously, hongkai-dai (Hongkai Dai) wrote…
Done. I didn't know we can add python binding for constructor in this way. Thanks!
OK Welcome! It's actually shown this way in the dev docs, and on pybind's website too ;)
https://drake.mit.edu/doxygen_cxx/group__python__bindings.html
https://pybind11.readthedocs.io/en/stable/classes.html#creating-bindings-for-a-custom-type
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.
Reviewable status: 1 unresolved discussion, LGTM missing from assignee EricCousineau-TRI(platform), needs at least two assigned reviewers, commits need curation (https://drake.mit.edu/reviewable.html#curated-commits) (waiting on @hongkai-dai)
a discussion (no related file):
Previously, EricCousineau-TRI (Eric Cousineau) wrote…
Can you also have it be tested in
all_test.py
, linked in prior comment?
Ah, seems like we posted at around the same time - yeah, see the all_test.py
code.
80f89d4
to
b9047ac
Compare
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.
Reviewable status: 1 unresolved discussion, LGTM missing from assignee EricCousineau-TRI(platform), needs at least two assigned reviewers, commits need curation (https://drake.mit.edu/reviewable.html#curated-commits) (waiting on @EricCousineau-TRI)
a discussion (no related file):
Previously, EricCousineau-TRI (Eric Cousineau) wrote…
Ah, seems like we posted at around the same time - yeah, see the
all_test.py
code.
Got it, just added the test.
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.
Reviewed 1 of 1 files at r3.
Reviewable status: LGTM missing from assignee EricCousineau-TRI(platform), needs at least two assigned reviewers, commits need curation (https://drake.mit.edu/reviewable.html#curated-commits)
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.
Reviewable status: LGTM missing from assignee sammy-tri(platform), commits need curation (https://drake.mit.edu/reviewable.html#curated-commits) (waiting on @sammy-tri)
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.
Reviewable status: LGTM missing from assignee sammy-tri(platform), commits need curation (https://drake.mit.edu/reviewable.html#curated-commits) (waiting on @sammy-tri)
bindings/pydrake/test/all_test.py, line 147 at r3 (raw file):
# - ipopt "IpoptSolver", # - branch_and_bound
BTW This isn't alphabetical, but it's not particularly a huge deal.
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.
Reviewed 4 of 5 files at r1, 2 of 2 files at r2, 1 of 1 files at r3.
Reviewable status: commits need curation (https://drake.mit.edu/reviewable.html#curated-commits)
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.
+(status: squashing now)
Reviewable status: complete! all discussions resolved, LGTM from assignees sammy-tri(platform),EricCousineau-TRI(platform)
Resolves #12997 cc @TobiaMarcucci
This change is