ksil / LFPSQP.jl

Julia implementation of Locally Feasibly Projected Sequential Quadratic Programming
MIT License
24 stars 2 forks source link

Segfault when running README example #1

Closed lassepe closed 2 years ago

lassepe commented 3 years ago

The equality constraint example from the README:

using LFPSQP

n = 50     # number of variables
m = 1      # number of constraints

f = x -> dot(x, x)

function c!(cval, x)
    cval[1] = x[1] - 0.75
end

x0 = ones(n)

x, obj_values, λ_kkt, term_info = optimize(f, c!, x0, m)

Reliably segfaults my Julia installation. Both on Julia 1.6.2 and 1.7.0-beta3.

ksil commented 3 years ago

Hi Lasse,

Thanks for trying out LFPSQP and for notifying me of the issue. How peculiar! I'm on version 1.6.1 and did not face any issues...

I just installed version 1.7.0-beta3 and can indeed reproduce the segfault that you observe. After playing around with it a bit, the issue seems to be with the gradient, jacobian, and hessian-vector functions generated via automatic differentiation in autodiff_generators.jl and called by the convenience optimize function. Specifically, calling

cfg_f = ReverseDiff.GradientConfig(x0)

in the generate_gradient function causes a segfault, so this appears to be a bug with ReverseDiff!

For now, you can regress to julia 1.6.1 like me, you can specify gradients, jacobians, and hessian-vector functions with another automatic differentiation package in the style of the functions I wrote in autodiff_generators.jl, or you can write the functions manually, such as in the following simple example without constraints:

f = x -> dot(x, x)/2

function grad!(g, x)
    g .= x
end

function hess_lag_vec!(dest, src, x, λ)
    dest .= src
end

optimize(f, grad!, nothing, nothing, hess_lag_vec!, ones(5), nothing, nothing, 0, LFPSQP.LFPSQPParams())

I may open an issue with ReverseDiff or potentially migrate away from default usage of ReverseDiff in LFPSQP if the problem persists.

lassepe commented 3 years ago

Thank you for the swift response! Maybe as a quick fix here you can set the julia compat to 1.6.1 until the problem is fixed upstream.

Thank you for sharing this package and your talk at JuliaCon; I really enjoyed it!

ksil commented 3 years ago

I'll definitely look into adjusting the compat attribute. I also logged the issue in the ReverseDiff repo, so we'll see what happens.

Thanks so much; that's great to hear 🙂! As I continue to write the documentation (and finish the manuscript), please feel free to send me any other feedback you may have!

ksil commented 2 years ago

ReverseDiff seems to be fine in Julia v1.7.1 now

lassepe commented 2 years ago

@ksil thank you for the follow up. It may be a good idea to add a compat entry to the Project.toml to reflect the fact that this packages requires Julia 1.7.