RobotLocomotion / drake

Model-based design and verification for robotics.
https://drake.mit.edu
Other
3.22k stars 1.25k forks source link

Unable to convert to function return value to a Python type for `GcsTrajectoryOptimization.SolvePath()` #19987

Closed rcywongaa closed 1 year ago

rcywongaa commented 1 year ago

What happened?

I get the following error when trying to extract the results from GcsTrajectoryOptimization.SolvePath()

TypeError: Unable to convert function return value to a Python type! The signature was
    (self: pydrake.planning.GcsTrajectoryOptimization, source: pydrake.planning.GcsTrajectoryOptimization.Subgraph, target: pydrake.planning.GcsTrajectoryOptimization.Subgraph, options: pydrake.geometry.optimization.GraphOfConvexSetsOptions = GraphOfConvexSetsOptions(convex_relaxation=None, preprocessing=None, max_rounded_paths=None, max_rounding_trials=100, flow_tolerance=1e-05, rounding_seed=0, solver=None, solver_options=<SolverOptions>, rounding_solver_options=None, )) -> Tuple[drake::trajectories::CompositeTrajectory<double>, pydrake.solvers.MathematicalProgramResult]

I tried adding

  py::module::import("pydrake.trajectories");

to https://github.com/RobotLocomotion/drake/blob/master/bindings/pydrake/planning/planning_py_trajectory_optimization.cc and that solved the problem.

It seems the current unit test https://github.com/RobotLocomotion/drake/blob/master/bindings/pydrake/planning/test/trajectory_optimization_test.py does not catch this issue because it already imports pydrake.trajectories.CompositeTrajectory

Version

57e044df411635a63703cb5e88314dc7be307418

What operating system are you using?

Ubuntu 20.04

What installation option are you using?

compiled from source code using CMake, compiled from source code using Bazel

Relevant log output

No response

jwnimmer-tri commented 1 year ago

I created #19994 with a simpler unit test that doesn't require MOSEK.

No matter what I tried, I wasn't able to get it to fail. I tried removing all of the imports except the minimal set like HPolyhedron and GCS. Everything still passed.

We'll need a better recipe for reproducing your problem, before we can try to debug it. Could you share some steps I could try, to see this problem in action? Maybe some sample code?

The PR #19988 doesn't make any sense, because (as mentioned there) the module is already imported, prior to that change. Something else must be going on.

jwnimmer-tri commented 1 year ago

Is there any chance that when you saw the error, you were running with a version of Drake prior to #19938? Maybe due to some PYTHONPATH snafu?

rcywongaa commented 1 year ago

You're right, I must've mixed up the PYTHONPATH in different terminals. Also explains why the issue exists in the notebook since it's using an earlier snapshot.

Sorry for the false alarm.

jwnimmer-tri commented 1 year ago

No problem at all, glad it's working!