NLopt.jl icon indicating copy to clipboard operation
NLopt.jl copied to clipboard

NLopt returns BoundsError even though model is properly defined as MathProgBase model

Open jomi2801 opened this issue 7 years ago • 2 comments

I have run the code

using NLopt

include(joinpath(Pkg.dir("MathProgBase"),"test","nlp.jl"))
convexnlptest(NLoptSolver(algorithm=:LD_SLSQP))

resulting in the output

ERROR: BoundsError
Stacktrace:
 [1] optimize!(::NLopt.Opt, ::Array{Float64,1}) at /home/jomi/.julia/v0.6/NLopt/src/NLopt.jl:523
 [2] optimize!(::NLopt.NLoptMathProgModel) at /home/jomi/.julia/v0.6/NLopt/src/NLoptSolverInterface.jl:203
 [3] convexnlptest(::NLopt.NLoptSolver) at /home/jomi/.julia/v0.6/MathProgBase/test/nlp.jl:245

The code

using NLopt

include(joinpath(Pkg.dir("MathProgBase"),"test","nlp.jl"))
nlptest(NLoptSolver(algorithm=:LD_SLSQP))

The test set called by convexnlptest is in MathProgBase syntax and part of the test set of MathProgBase.

jomi2801 avatar Feb 03 '18 14:02 jomi2801

I have compared the functions convexnlptest and nlptest and have observed that nlptest runs MathProgBase.setwarmstart! whereas convexnlptest does not. If the optimization variable say x is initialized by an array of the proper length before calling optimize!, the error does not occur.

jomi2801 avatar Feb 03 '18 14:02 jomi2801

I believe you must provide a starting point to NLopt, but I agree the error message could be more helpful.

mlubin avatar Feb 04 '18 03:02 mlubin

Closing as won't fix. The MathProgBase interface is deprecated and will be removed in a future release.

odow avatar Jan 25 '23 00:01 odow