RobotLocomotion / drake

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

MosekSolver Does not Parse Repeated Variables in PositiveSemidefiniteConstraints correctly #22158

Closed AlexandreAmice closed 3 days ago

AlexandreAmice commented 1 week ago

What happened?

PositiveSemidefiniteConstraint in principle allows a user to have repeated variables in the binding, e.g. a Hankel matrix:

[x₀, x₁, x₂]
[x₁, x₂, x₃]
[x₂ ,x₃, x₄]

This does not get parsed correctly by our MosekSolver. A Python reproduction is below:

from scipy.linalg import  hankel
from pydrake.all import (
    MathematicalProgram,
    ClarabelSolver,
    MosekSolver,
    SolverOptions
)

prog = MathematicalProgram()
n = 3
num_hankel = 2*n-1
x = prog.NewContinuousVariables(num_hankel, "x")
X = hankel(x[:n], x[n-1:])
prog.AddPositiveSemidefiniteConstraint(X)
prog.AddLinearConstraint(x[1] >= 1)
prog.AddLinearCost(np.trace(X))
options = SolverOptions()

mosek = MosekSolver()
clarabel = ClarabelSolver()
result_mosek = mosek.Solve(prog, solver_options=options)
result_clarabel = clarabel.Solve(prog, solver_options=options)
print(f"{result_mosek.GetSolution(X)=}")
print(f"{result_clarabel.GetSolution(X)=}")

print(f"{result_mosek.get_optimal_cost()=}")
print(f"{result_clarabel.get_optimal_cost()=}")

If one increases the size of the hankel matrix, mosek gets a unknown solver status.

cc @rhjiang for finding this.

Version

No response

What operating system are you using?

No response

What installation option are you using?

No response

Relevant log output

No response