JuMP register polynomial with its gradient

Dear all,

I am using jump and I want to register a polynomial function with its gradient, with

register(model2, :poly, num_var, poly, gradient)

I build the polynomial with AbstractAlgebra.jl and the gradient with the function

function gradient(x...)
    point = Float64[]
    for i in 1:length(x)
        append!(point,x[i])
    end
    gradient = Float64[]
    for i in 1:length(x)
        deriv = evaluate(derivative(f,i),point)
        append!(gradient,convert(Float64,deriv))
    end
    return gradient
end

If I call the gradient on a point with

gradient(zeros(100))

there is no error. However, when I solve my problem with Ipopt as follows

num_var = 100
model = Model(Ipopt.Optimizer)
register(model, :poly, num_var, poly, gradient)
@variable(model, 0.0 <= z[1:num_var] <= 1.0)
@NLobjective(model, Min, poly(z...))
optimize!(model)

JuMP return me the following error message referring to the evaluation step in the gradient of the function.

ERROR: LoadError: Incorrect number of values in evaluation

I would ask you if you have any insight or suggestion to solve this error. Thanks very much

Your gradient function need to accept the gradient as the first argument and modify it in place.

https://jump.dev/JuMP.jl/stable/manual/nlp/#Multivariate-functions