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

Segfault with NLopt #344

Closed
baggepinnen opened this issue Aug 17, 2022 · 2 comments
Closed

Segfault with NLopt #344

baggepinnen opened this issue Aug 17, 2022 · 2 comments
Labels

Comments

@baggepinnen
Copy link
Contributor

Looks like there's something fishy in nlopt_set_xtol_abs

using Optimization, Symbolics, OptimizationNLopt, SparseArrays
using OptimizationNLopt.NLopt

N = 10
x0 = randn(N)
x = Symbolics.variables(:x, 1:N)
p = Symbolics.variable(:p)

cost = sum(abs2, x)
hess = Symbolics.hessian(cost, x)
hessfun = build_function(hess, x, p)[2]
hessfun = eval(hessfun)

costfun = (x,p)->sum(abs2, x)
grad = (g, x, p) -> g .= 2x
optfun = OptimizationFunction{false}(costfun; hess = hessfun, grad);
prob = OptimizationProblem(optfun, x0);
sol = solve(prob, NLopt.LD_AUGLAG_EQ());
julia> sol = solve(prob, NLopt.LD_AUGLAG_EQ());

signal (11): Segmentation fault
in expression starting at REPL[15]:1
memcpy at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
nlopt_set_xtol_abs at /home/fredrikb/.julia/artifacts/332af19a7ea5911ea41bb72ba5e3badcf5dd4ba1/lib/libnlopt.so (unknown line)
nlopt_optimize at /home/fredrikb/.julia/artifacts/332af19a7ea5911ea41bb72ba5e3badcf5dd4ba1/lib/libnlopt.so (unknown line)
optimize! at /home/fredrikb/.julia/packages/NLopt/OIUOZ/src/NLopt.jl:617
optimize at /home/fredrikb/.julia/packages/NLopt/OIUOZ/src/NLopt.jl:624 [inlined]
@baggepinnen
Copy link
Contributor Author

A reduced example

using Optimization, OptimizationNLopt
using OptimizationNLopt.NLopt

N = 10
x0 = randn(N)
hessfun = (H,x,p) -> H[diaginds(H)] .= 2
costfun = (x,p)->sum(abs2, x)
grad = (g, x, p) -> g .= 2x
optfun = OptimizationFunction{false}(costfun; hess = hessfun, grad);
prob = OptimizationProblem(optfun, x0);
sol = solve(prob, NLopt.LD_AUGLAG());

@Vaibhavdixit02
Copy link
Member

Can't reproduce, maybe the issue was not specifying the subsidiary solver here, this works

julia> sol = solve(prob, NLopt.LD_AUGLAG(), local_method = NLopt.LD_TNEWTON());
┌ Warning: NLopt failed to converge: FTOL_REACHED
└ @ OptimizationNLopt ~/Optimization.jl/lib/OptimizationNLopt/src/OptimizationNLopt.jl:239

julia> sol.objective
1.6639444629660956e-18

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants