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

[MOI] Add support for nonlinear problems without Hessian #322

Merged
merged 1 commit into from
Apr 27, 2024

Conversation

frapac
Copy link
Collaborator

@frapac frapac commented Apr 10, 2024

Solve #318

This PR adds support for MOI nonlinear problems without Hessian. This is needed to support problems with user-defined functions (whose support has been improved in the latest MOI releases). Now MadNLP switches automatically to the LBFGS algorithm if the Hessian is not available, as it is done in Ipopt.jl.

Currently, we specify to NLPModels that the problem does not have Hessian by setting nnzh=0 in NLPModelMeta, so the following code works if the Hessian callback is not defined:
https://github.com/MadNLP/MadNLP.jl/blob/fp/moi_nohessian/src/nlpmodels.jl#L360-L362
I am not sure this is the correct approach.

@franckgaga
Copy link

franckgaga commented Apr 10, 2024

Thanks for this PR!
This a good compromise (clearly better than an error!) but according to JuMP stable documentation, both for the NLP Legacy syntax and the new NLP syntax, the Hessian is also automatically computed by AD with registered function/operators (with ForwardDiff.jl I think). LBFGS approximation should not required here.
Am I right @odow ?

@odow
Copy link
Contributor

odow commented Apr 10, 2024

the Hessian is also automatically computed by AD with registered function

Only for univariate functions. We don't compute it for multivariate user-defined operators.

@franckgaga
Copy link

Oops, my bad. My interpretation of the doc was incorrect. This is indeed the best solution in this case.

@odow
Copy link
Contributor

odow commented Apr 10, 2024

I think we kept the docs intentionally ambiguous, because it's a level of detail that shouldn't concern most people. The issue here is just a straight-up bug. You should check whether the AD backend supports :Hess before attempting to call it.

@franckgaga
Copy link

@odow I'm curious, why JuMP chose to skip the Hessian for multivariate registered functions ? For the user using the legacy syntax, would you recommend to call register with a ∇²fargument, and calling ForwardDiff.hessian! in the ∇²f method?

Copy link
Member

@sshin23 sshin23 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. This reminds me of the possibility of piggybacking on Ipopt.jl/Knitro.jl...

ext/MadNLPMOI/utils.jl Show resolved Hide resolved
@odow
Copy link
Contributor

odow commented Apr 11, 2024

why JuMP chose to skip the Hessian for multivariate registered functions

Mainly because they can have many arguments, and computing the Hessian with ForwardDiff is expensive (because we'd need to compute the dense Hessian).

It would be breaking to enable this argument now.

The documentation has a tutorial on adding it manually if you're interested though:
https://jump.dev/JuMP.jl/stable/tutorials/nonlinear/operator_ad/#Hessian-2

@sshin23 sshin23 merged commit 5916b54 into master Apr 27, 2024
7 checks passed
@sshin23 sshin23 deleted the fp/moi_nohessian branch April 27, 2024 01:48
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

Successfully merging this pull request may close these issues.

None yet

4 participants