Closed hongkai-dai closed 1 month ago
@EricCousineau-TRI BTW, I just tested your example. The reason why Drake's IpoptSolver runs slower than Casadi is because Drake was using the default initial guess (the zero vector), as opposed to the initial guess set in the Casadi example.
I changed the code to use the same initial guess. Now Drake actually runs slightly faster than Casadi. Here is the output. Notice that in the first iteration Drake and Casadi evaluates the same objective
Starting test 2
List of user-set options:
Name Value used
acceptable_constr_viol_tol = 0.01 yes
acceptable_tol = 1e-06 yes
constr_viol_tol = 0.0001 yes
hessian_approximation = limited-memory yes
linear_solver = mumps yes
print_level = 5 yes
print_timing_statistics = no yes
print_user_options = yes yes
sb = yes yes
tol = 1e-08 yes
This is Ipopt version drake_vendor, running with linear solver MUMPS 5.4.1.
Number of nonzeros in equality constraint Jacobian...: 603
Number of nonzeros in inequality constraint Jacobian.: 400
Number of nonzeros in Lagrangian Hessian.............: 0
Total number of variables............................: 402
variables with only lower bounds: 1
variables with lower and upper bounds: 201
variables with only upper bounds: 0
Total number of equality constraints.................: 202
Total number of inequality constraints...............: 200
inequality constraints with only lower bounds: 0
inequality constraints with lower and upper bounds: 0
inequality constraints with only upper bounds: 200
iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls
0 1.0001005e+02 1.00e-02 9.98e-01 0.0 0.00e+00 - 0.00e+00 0.00e+00 0
1 1.0003383e+02 4.27e-03 6.77e-01 -4.3 9.29e-01 - 9.70e-01 5.73e-01h 1
2 1.0003591e+02 1.88e-03 8.73e-01 -5.8 4.38e-01 - 9.85e-01 5.61e-01h 1
3 1.0004087e+02 1.69e-02 1.60e-01 -3.5 2.44e-01 - 9.96e-01 8.98e-01h 1
4 1.0001832e+02 1.53e-04 1.89e-03 -4.0 1.41e-01 - 9.85e-01 9.90e-01h 1
5 1.0000105e+02 3.11e-18 2.70e-09 -5.3 6.83e-02 - 9.92e-01 1.00e+00h 1
6 1.0000000e+02 3.33e-19 3.07e-11 -11.0 4.49e-03 - 9.91e-01 9.97e-01f 1
7 9.9999999e+01 3.86e-22 1.44e-13 -11.0 5.41e-05 - 1.00e+00 1.00e+00f 1
Number of Iterations....: 7
(scaled) (unscaled)
Objective...............: 9.9999998952050731e+01 9.9999998952050731e+01
Dual infeasibility......: 1.4359591999896980e-13 1.4359591999896980e-13
Constraint violation....: 3.8624003168684547e-22 3.8624003168684547e-22
Variable bound violation: 9.9975046968107693e-09 9.9975046968107693e-09
Complementarity.........: 1.0178693716247555e-11 1.0178693716247555e-11
Overall NLP error.......: 1.0178693716247555e-11 1.0178693716247555e-11
Number of objective function evaluations = 8
Number of objective gradient evaluations = 8
Number of equality constraint evaluations = 8
Number of inequality constraint evaluations = 8
Number of equality constraint Jacobian evaluations = 8
Number of inequality constraint Jacobian evaluations = 8
Number of Lagrangian Hessian evaluations = 0
Total seconds in IPOPT = 0.030
EXIT: Optimal Solution Found.
-------------------------------------------
-------------------------------------------
-------------------------------------------
Casadi Sol
List of user-set options:
Name Value used
acceptable_constr_viol_tol = 0.01 yes
acceptable_tol = 1e-06 yes
constr_viol_tol = 0.0001 yes
hessian_approximation = limited-memory yes
linear_solver = mumps yes
print_level = 5 yes
print_timing_statistics = no yes
print_user_options = yes yes
sb = yes yes
tol = 1e-08 yes
This is Ipopt version 3.14.11, running with linear solver MUMPS 5.4.1.
Number of nonzeros in equality constraint Jacobian...: 603
Number of nonzeros in inequality constraint Jacobian.: 400
Number of nonzeros in Lagrangian Hessian.............: 0
Total number of variables............................: 402
variables with only lower bounds: 1
variables with lower and upper bounds: 201
variables with only upper bounds: 0
Total number of equality constraints.................: 202
Total number of inequality constraints...............: 200
inequality constraints with only lower bounds: 0
inequality constraints with lower and upper bounds: 0
inequality constraints with only upper bounds: 200
iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls
0 1.0001005e+02 1.00e-02 9.98e-01 0.0 0.00e+00 - 0.00e+00 0.00e+00 0
1 1.0003387e+02 4.26e-03 6.76e-01 -4.2 9.29e-01 - 9.70e-01 5.74e-01h 1
2 1.0003594e+02 1.87e-03 8.71e-01 -5.7 4.38e-01 - 9.86e-01 5.62e-01h 1
3 1.0001198e+02 1.01e-02 9.39e-02 -3.6 2.34e-01 - 9.94e-01 9.34e-01h 1
4 1.0002131e+02 6.04e-04 3.54e-02 -4.0 1.13e-02 - 9.95e-01 9.49e-01h 1
5 1.0001801e+02 2.44e-06 4.07e-03 -5.6 4.07e-03 - 1.00e+00 9.92e-01h 1
6 1.0001347e+02 2.78e-18 4.76e-03 -7.2 4.76e-03 - 1.00e+00 1.00e+00f 1
7 1.0001006e+02 2.41e-18 4.91e-03 -8.1 4.91e-03 - 1.00e+00 7.28e-01f 1
8 1.0000789e+02 2.90e-18 4.28e-08 -5.8 8.62e+00 - 1.00e+00 3.50e-03f 1
9 9.9999999e+01 2.88e-18 4.31e-10 -10.9 1.34e-02 - 9.89e-01 1.00e+00f 1
iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls
10 9.9999999e+01 1.85e-22 2.13e-14 -11.0 4.33e-06 - 1.00e+00 1.00e+00h 1
Number of Iterations....: 10
(scaled) (unscaled)
Objective...............: 9.9999998952050007e+01 9.9999998952050007e+01
Dual infeasibility......: 2.1315227499335333e-14 2.1315227499335333e-14
Constraint violation....: 1.8528845721187820e-22 1.8528845721187820e-22
Variable bound violation: 9.9975031213371835e-09 9.9975031213371835e-09
Complementarity.........: 1.0006376209779095e-11 1.0006376209779095e-11
Overall NLP error.......: 1.0006376209779095e-11 1.0006376209779095e-11
Number of objective function evaluations = 11
Number of objective gradient evaluations = 11
Number of equality constraint evaluations = 11
Number of inequality constraint evaluations = 11
Number of equality constraint Jacobian evaluations = 11
Number of inequality constraint Jacobian evaluations = 11
Number of Lagrangian Hessian evaluations = 0
Total seconds in IPOPT = 0.084
EXIT: Optimal Solution Found.
solver : t_proc (avg) t_wall (avg) n_eval
nlp_f | 208.00us ( 18.91us) 31.16us ( 2.83us) 11
nlp_g | 701.00us ( 63.73us) 106.61us ( 9.69us) 11
nlp_grad_f | 391.00us ( 32.58us) 53.57us ( 4.46us) 12
nlp_jac_g | 824.00us ( 68.67us) 124.28us ( 10.36us) 12
total | 543.93ms (543.93ms) 87.33ms ( 87.33ms) 1
Solve time: 2.076539993286133
Solve time 2 : 0.030740976333618164
Casadi Solve Time: 0.08748602867126465
Controls norm: 1.358751404045516e-07
Integral norm: 4.4793890387626446e-08
Max norm: 6.991740519879386e-12
Controls norm casadi: 1.3579234259034422e-07
Integral norm casadi: 4.4805843778744453e-08
Max norm casadi: 7.005951374594588e-12
The difference in the computation is probably due to different ordering of the constraints.
awesome, thanks! and ftr, it was not my example, but just taking @jorgenin's example and putting it into Drake for quick testing.
Resolves #21485
cc @jorgenin
This change is![Reviewable](https://reviewable.io/review_button.svg)