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

NLPModels computes gradient with elements out of order #316

Closed
MaiconMares opened this issue Oct 31, 2023 · 9 comments
Closed

NLPModels computes gradient with elements out of order #316

MaiconMares opened this issue Oct 31, 2023 · 9 comments

Comments

@MaiconMares
Copy link

MaiconMares commented Oct 31, 2023

In some non linear problems the grad() function is computing gradient correctly but returning partial derivatives out of order. For example in the HS27 problem the correct result should be [16.02,-4.0,0.0], but it is returning [0.0,-4.0,16.02]. I don't understand why this behaviour is happening.

@dpo
Copy link
Member

dpo commented Oct 31, 2023

Is that with the JuMP model, or the ADNLPModel? Could you please give a snippet that reproduces the issue?

@MaiconMares
Copy link
Author

Is that with the JuMP model, or the ADNLPModel? Could you please give a snippet that reproduces the issue?

@dpo I don't know what NLPModels uses under the hood to compute gradient, but to reproduce do it:

using NLPModels, CUTEst

nlp = CUTEstModel("HS27")
grad(nlp,nlp.meta.x0)

One screenshot with the result:
Screenshot from 2023-10-31 11-28-32

The initial values are [2.0,2.0,2.0].

@MaiconMares
Copy link
Author

@dpo this behaviour is strange because in some NLP problems the gradient is computed in the correct order, I mean:
image

@dpo
Copy link
Member

dpo commented Nov 1, 2023

Ok, you're in the wrong repository. You're talking about CUTEst.jl models.

@dpo dpo transferred this issue from JuliaSmoothOptimizers/OptimizationProblems.jl Nov 1, 2023
@abelsiqueira
Copy link
Member

Hi @MaiconMares, what order were you expecting? The paper's or wrt other packages? Maybe it is related to the setup options that we use to read the cutest file.

@MaiconMares
Copy link
Author

Hi @MaiconMares, what order were you expecting? The paper's or wrt other packages? Maybe it is related to the setup options that we use to read the cutest file.

Hi @abelsiqueira the correct order should be [16.02,-4.0,0.0]. How can I change the way CUTEst Julia package reads .SIF files?

@abelsiqueira
Copy link
Member

function CUTEstModel(

See above and check the docs of the function.

@tmigot
Copy link
Member

tmigot commented Nov 1, 2023

Hey @MaiconMares , what is reference you use to state what is the ''correct'' formulation?
Or is an error on the derivative computation in cutest?

@MaiconMares
Copy link
Author

Hi @MaiconMares, what order were you expecting? The paper's or wrt other packages? Maybe it is related to the setup options that we use to read the cutest file.

Thank you @abelsiqueira, it was the problem. lfirst and lvfirst args passed to CUTEstModel function was leading CUTEst to compute gradients and constraints doing partial derivatives over non-linear variables first! The solution:

CUTEstModel("HS8",lfirst=false,lvfirst=false)

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

4 participants