Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

derivative check with IPOPT #83

Open
junhyeokahn opened this issue Jan 14, 2021 · 1 comment
Open

derivative check with IPOPT #83

junhyeokahn opened this issue Jan 14, 2021 · 1 comment

Comments

@junhyeokahn
Copy link

junhyeokahn commented Jan 14, 2021

Hello,
First of all, thanks for maintaining this nice repo!

In the hopper_example.cc, I have added this line to check derivatives.

solver->SetOption("derivative_test", "first-order")
solver->SetOption("derivative_test_tol", 1e-3);

And I got the results as shown in the attached screenshot.
Screenshot from 2021-01-14 11-54-59

where the constraints and variables are indexed as following:
Screenshot from 2021-01-14 11-53-32

Most of the derivatives are very very close, but there were some jacobian elements that have a relatively bigger error between the analytically computed value and the numerically computed value.
To which degree do you expect this comparison should be similar?
Should they be exactly the same or ~0.01 error is inevitable and should be accepted?

Best,
Junhyeok

@justinberi
Copy link

justinberi commented Feb 3, 2021

Hi, I am not a maintainer and don't have a specific answer but I might be able to give a little more information that might be helpful.

There is more information about what each term in the checker refers to at https://coin-or.github.io/Ipopt/SPECIALS.html. Changing the "derivative_test_perturbation" option will change the size of the errors and "derivative_test_tol" determines the cut-off for reporting the derivative is an error.

I believe the relative size of the error would depend on the non-linearity in the supplied Jacobian. This is because it is comparing to a first order (linear) estimate of the derivative. Thus the derivatives will not be the same. So treat it more as a test to see if you have implemented the analytic derivatives correctly.

With that in mind, I implemented a cart pole trajectory optimisation problem with IFOPT as the interface to IPOPT which is what is used in TOWR. The derivative checker there revealed errors in on the order of 1e-9 for a "derivative_test_perturbation" of 1e-8 and errors on the order of 1e-4 for a "derivative_test_perturbation" of 1e-4. But again, this is a different problem with different forms for the cost and constraints.

A final note: In my experience, using the analytic derivatives instead of a finite-difference method can provide 1 to 2 orders of magnitude reduction in solution time with IPOPT so regardless it is well worth defining the Jacobian analytically.

Thanks @awinkler for the awesome work in TOWR and IFOPT.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants