astamm / nloptr

nloptr provides an R interface to NLopt, a free/open-source library for nonlinear optimization providing a common interface to a number of different optimization routines which can handle nonlinear constraints and lower and upper bounds for the controls.
https://astamm.github.io/nloptr/
Other
103 stars 36 forks source link

NLOPT_LN_SLSQP Enabling slsqp without gradients #147

Closed RaulGDiaz closed 4 days ago

RaulGDiaz commented 8 months ago

I tried to get slsqp to work with the nloptr wrapper when no gradient is provided as this functionality is available in the native slsqp function. I created a separate algorithm label called "NLOPT_LN_SLSQP" to stick with the convention already used and prepared other areas of the codebase to also account for this change.

Sadly, I did not manage to fully enable this functionality as this commit produces the following exception: Error in nloptr(x0 = initialization, eval_f = cost_function, lb = lower_bound, : STRING_ELT() can only be applied to a 'character vector', not a 'NULL'

I believe this error is originating around the status objects in nloptr.c, but I have not managed to identify exactly what the issue is or how to solve it.

Apologies in advance should I have made any mistakes with these commits or when creating this pull request, this is my first time trying to do this. Please feel free to leave any advise for the future.

aadler commented 3 weeks ago

According to the NLOPT website, there is no NLOPT_LN_SLSQP algorithm. That could be why you are getting a NULL; there is no such algorithm in the library. I would recommend closing this as unaccepted as this is outside the scope of NLOPTr. You would need to ask the NLOPT team to add the algorithm to the library.

astamm commented 2 weeks ago

Indeed, I do not understand this PR. The documentation of nlopt on SLSQP explicitly says it is a gradient-based method specified as NLOPT_LD_SLSQP.

@RaulGDiaz : before closing this PR, would you like to explain more?

astamm commented 4 days ago

No news from @RaulGDiaz. I am closing this. Feel free to reopen if you still have unresolved issues.