Nonlinear objective with both splatted variable and vector parameters

If the parameters are used exclusively in the registered function, you have the option of hiding them from JuMP via a closure:

using JuMP, Ipopt
function myfunc()
    model = Model(Ipopt.Optimizer)
    nvar = 3
    @variable(model, x[1:nvar])
    a = zeros(nvar)
    f(x...) = sum((x .- a).^2)
    register(model, :f, nvar, f; autodiff = true)
    @NLobjective(model, Min, f(x...))
    optimize!(model)
    @show value.(x)

	a[1] = 10.0
    optimize!(model)
    @show value.(x)

end
myfunc()

In this case it’s on you to be aware of the subtleties around how to update the parameter outside the closure.

3 Likes