coin-or / Ipopt

COIN-OR Interior Point Optimizer IPOPT
https://coin-or.github.io/Ipopt
Other
1.36k stars 272 forks source link

about derivative checker of ipopt #737

Closed liuxiaoyiyixiaoliu closed 5 months ago

liuxiaoyiyixiaoliu commented 6 months ago

I utilized Ipopt's derivative checker and obtained the following results: Starting derivative checker for first derivatives.

Derivative checker detected 450 error(s). In fact, the first column should represent the user-provided derivative values. However, the derivatives I obtained from the eval_grad_f function appear as follows. While the differences with the finite difference calculations are not significant, the displayed values above do not seem to be the Jacobian matrix obtained from eval_grad_f. They rather resemble the values of the independent variable when solving for the Jacobian. The computed values from eval_grad_f are as follows:(first few lines) -0.144876 -0.225822 -0.00124875 -0.14175 -0.221863 -0.00126049 -0.138661 -0.217921 -0.00120935 -0.135572 -0.214071 -0.00119629 -0.132521 -0.210228 -0.00116109 ......

The values ​​of the independent variables are as follows: -9.16739 -0.910151 6.69634 -3.28028 1.30979 -9.96466 -6.24821 9.80868 5.00994 -2.67453 -2.97582 1.4669 -7.34892 -8.71667 9.01707 ...... Thanks for every suggestion, I'm wondering if it's a problem with the program or with ipopt itself

svigerske commented 6 months ago

In the line

grad_f[ 0] = -9.1673931045624357e+00 ~ -1.4487373807435969e-01 [ 9.023e+00]

the -9.1673931045624357e+00 is the value that Ipopt got from your implementation of TNLP::eval_grad_f. The -1.4487373807435969e-01 is the value that Ipopt calculated via a finite-difference approximation from calls to eval_f.

So you may want to check your implementation of TNLP::eval_grad_f and whether you may copy x into grad_f there.

liuxiaoyiyixiaoliu commented 5 months ago

Thank you for your answer. I found the cause of the error. It is due to an error in passing the programming pointer and has nothing to do with ipopt.