Provide the user_data to the callbacks #514
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
@odow
When I created the C / Julia interface for
Uno, I checked a few times the interfaces of other nonlinear solvers (Ipopt,KNITRO,GALAHAD) and I noticed that inIpopt.jlwe never provide a way to passuser_data.This means that
model::Optimizeris passed as a closure, and the same applies tomodel::AbstractNLPModelinNLPModelsIpopt.jl.In
UnoSolver.jl, I added an option to passuser_data/user_modelwhen creating the internal solver model (Ipopt.IpoptProblemin this repository).If
user_dataisnothing, we keep the current signature; otherwise, we passuser_data/user_modelas the first argument to all Julia callbacks.This is what we expect in the signatures of the NLP API in
MathOptInterface.jlorNLPModels.jl.I also think it is a clean way to pass a list of parameters to an objective or constraints.
For example, if we have a complex physical problem, we would like to store them in a Julia structure and pass this structure as an argument to the Julia functions.
I find it neater than using closures.
The current PR is non-breaking because, by default,
user_data/user_modelisnothing.I would like to have your point of view (as well as that of other users) before I add unit tests for coverage.
Ipopt.jl: https://github.com/jump-dev/Ipopt.jl/blob/master/ext/IpoptMathOptInterfaceExt/MOI_wrapper.jl#L1242-L1264UnoSolver.jl: https://github.com/cvanaret/Uno/blob/main/interfaces/Julia/ext/UnoSolverMathOptInterfaceExt/MOI_wrapper.jl#L1294-L1301