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

Update an NLPModelMeta #469

Closed
MaxenceGollier opened this issue Jul 23, 2024 · 3 comments · Fixed by #471
Closed

Update an NLPModelMeta #469

MaxenceGollier opened this issue Jul 23, 2024 · 3 comments · Fixed by #471

Comments

@MaxenceGollier
Copy link
Contributor

Hello, I am trying to work on Quasi-Newton approximations of NLPModels.
Given some nlp::NLPModel, I would like to construct a SpectralGradientModel(nlp) i.e an NLPModel where I approximate the hessian $\mathcal{H}_f \approx \sigma I$. For this, I want to update the NLPModelMeta so that nlp.meta.nnzh = nlp.meta.nvar, so I want to create a copy of nlp.meta but with just one field modified. Since NLPModelMeta is an immutable struct, I can't just set nlp.meta.nnzh = nlp.meta.nvar. Since there are quite a lot of keyword arguments and since only one field is modified, I don't want to write each time

new_meta = NLPModelMeta( nnzh = nlp.meta.nvar, field1 = nlp.meta.field1, field2 = nlp.meta.field2, field3 = nlp.meta.field3, ...)

Also, I tried using Setfields.jl but this does not seem to work.

I am quite new to Julia so I was wondering if you had an idea on how to do this.

@tmigot
Copy link
Member

tmigot commented Jul 23, 2024

Unfortunately, I don't think there is a very clean solution here. We could add a new constructor for NLPModelMeta that simplifies this task though. Something like

NLPModelMeta(meta::AbstractNLPModelMeta; kwargs...) = NLPModelMeta(meta.nvar; x0 = meta.x0, etc...., name = meta.name, kwargs...)

@MaxenceGollier
Copy link
Contributor Author

That's what I was thinking but I wondered, if meta is AbstractNLPModelMeta but not NLPModelMeta for some reason, then your solution could be wrong ? I don't know if something else than NLPModelMeta has ever been implemented ?

@tmigot
Copy link
Member

tmigot commented Jul 24, 2024

What do you mean by it would be "wrong"?
There could be potential errors if the meta is missing some fields that are in the given keyword arguments, but anyway this would break several functions in the API.
In JSO, I am not aware of any other specialization of AbstractNLPModelMeta.

@tmigot tmigot linked a pull request Jul 29, 2024 that will close this issue
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 a pull request may close this issue.

2 participants