Error message using JuMP and NLopt


#1

Dear Julia experts,

I have been using JuMP and NLopt for an optimization problem about a year ago and in trying to rerun the code which worked, I am getting an error message. I have three non-linear constraints (I am only showing one here) and I am trying to register my function(the actual function is not shown) using JuMP.register and find maximum of the function.
Please see my code below along with the error message.

CODE :
p = 10
m1 = Model(solver=NLoptSolver(algorithm=:LN_COBYLA))

#- define variables
@variable(m1, a[i=1:p])
@variable(m1, b[i=1:p])

function myf1(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10)
##-- my own function --##
end

JuMP.register(m1, :myf1, 2*p, myf1)

@NLobjective(m1, Max, myf1(a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8],a[9],a[10],b[1],b[2],b[3],b[4],b[5],b[6],b[7],b[8],b[9],b[10]))
@constraint(m1, a’*a .== 1)

ERROR MESSAGE :
julia> JuMP.register(m1, :myf1, 2*p, myf1)
ERROR: MethodError: register has no method matching register(::JuMP.Model, ::Symbol, ::Int64, ::Function)
Closest candidates are:
register(::Symbol, ::Integer, ::Function, ::Function)
register(::Symbol, ::Integer, ::Function, ::Function, ::Function)

I tried to change the order to the candidates but cannot find the syntax that works.
Can someone please help me to fix the error?
Thank you.


#2

What JuMP version are you using? On 0.16.2 I have a method matching that signature:

julia> methods(JuMP.register)
# 6 methods for generic function "register":
register(m::JuMP.Model, s::Symbol, dimension::Integer, f::Function; autodiff) at C:\Users\Evan\.julia\v0.5\JuMP\src\nlp.jl:1364

If I recall correctly, you also have to specify autodiff = true if you don’t provide a gradient function.


#3

Thank you very much. I updated my JuMP package and the problem is solved.