Hello,
First of all, I would like to thank you for developing and sharing the Casadi tool, I find it very useful.
I have a question on the execution time in Matlab and Python environments. I recently found out that the same function is executed approximately 5 times faster in Matlab. Below is more detail.
My approach is to design a function using 'opti.to_function' method in Matlab, save it to '.casadi' file, and load it in python with 'Function.load'.
When I am comparing the execution times in Matlab and Python I get the following results (for exactly the same inputs to the function):
Matalb:
Number of Iterations....: 17
(scaled) (unscaled)
Objective...............: -8.0435061648940198e-001 -8.0435061648940198e-001
Dual infeasibility......: 2.5063284780912909e-014 2.5063284780912909e-014
Constraint violation....: 1.7763568394002505e-015 1.7763568394002505e-015
Complementarity.........: 3.9098818541072077e-009 3.9098818541072077e-009
Overall NLP error.......: 3.9098818541072077e-009 3.9098818541072077e-009
Number of objective function evaluations = 18
Number of objective gradient evaluations = 18
Number of equality constraint evaluations = 18
Number of inequality constraint evaluations = 18
Number of equality constraint Jacobian evaluations = 18
Number of inequality constraint Jacobian evaluations = 18
Number of Lagrangian Hessian evaluations = 17
Total CPU secs in IPOPT (w/o function evaluations) = 0.049
Total CPU secs in NLP function evaluations = 0.013
EXIT: Optimal Solution Found.
solver : t_proc (avg) t_wall (avg) n_eval
nlp_f | 1.00ms ( 55.56us) 998.00us ( 55.44us) 18
nlp_g | 3.00ms (166.67us) 3.00ms (166.50us) 18
nlp_grad | 1.00ms ( 1.00ms) 997.00us (997.00us) 1
nlp_grad_f | 3.00ms (157.89us) 3.00ms (158.16us) 19
nlp_hess_l | 0 ( 0) 0 ( 0) 17
nlp_jac_g | 5.00ms (263.16us) 4.98ms (262.00us) 19
total | 64.00ms ( 64.00ms) 63.80ms ( 63.80ms) 1
Python:
Number of Iterations....: 17
(scaled) (unscaled)
Objective...............: -8.0434318804924654e-001 -8.0434318804924654e-001
Dual infeasibility......: 9.1038288019262836e-015 9.1038288019262836e-015
Constraint violation....: 1.7763568394002505e-015 1.7763568394002505e-015
Complementarity.........: 1.3489581364330974e-009 1.3489581364330974e-009
Overall NLP error.......: 1.3489581364330974e-009 1.3489581364330974e-009
Number of objective function evaluations = 18
Number of objective gradient evaluations = 18
Number of equality constraint evaluations = 18
Number of inequality constraint evaluations = 18
Number of equality constraint Jacobian evaluations = 18
Number of inequality constraint Jacobian evaluations = 18
Number of Lagrangian Hessian evaluations = 17
Total CPU secs in IPOPT (w/o function evaluations) = 0.214
Total CPU secs in NLP function evaluations = 0.012
EXIT: Optimal Solution Found.
solver : t_proc (avg) t_wall (avg) n_eval
nlp_f | 3.00ms (166.67us) 2.96ms (164.44us) 18
nlp_g | 3.00ms (166.67us) 2.99ms (166.33us) 18
nlp_grad | 1.00ms ( 1.00ms) 995.00us (995.00us) 1
nlp_grad_f | 4.00ms (210.53us) 3.94ms (207.63us) 19
nlp_hess_l | 0 ( 0) 0 ( 0) 17
nlp_jac_g | 2.00ms (105.26us) 1.99ms (104.95us) 19
total | 291.00ms (291.00ms) 290.90ms (290.90ms) 1
The total time is noticeably higher in Python environment (I run it a number of time and also tried different input combinations - the difference seems to be consistent: app. factor of 5).
Is it expected?
From the solver results it is visible that the major difference is in
CPU secs in IPOPT (I also tried 'sqpmethod' and the different is even bigger).
Aren't casadi-Python and casadi-Matlab using the same IPOPT libraries?
Would it make any difference if the function was developed in Python environment?
Thank you in advance!
-Nikita