Error in JuMP @NLexpression


#1

I am running the following code with Julia 0.6.4:

using JuMP
using NLopt
using FastGaussQuadrature
using SpecialFunctions

function FisherInf(args...)
    N = 32
    
    t = [x[i] for i=1:N]
    lambda = [args[i] for i=N+1:2N]
    w      = x[2N+1]
    Phi    = x[2N+2]
    A      = x[2N+3]
    
    e = 0.0
    N = length(t)
    g = zeros(2)
    H = zeros(2,2)
    for j=1:N
        xj = w*t[j] - Phi
        e += lambda[j]*t[j]^2*sin(xj)^2
        g[1] += lambda[j]*t[j]*sin(w*t[j])^2
        g[2] += lambda[j]*t[j]*sin(w*t[j])*cos(w*t[j])
        H[1,1] += lambda[j]*sin(xj)^2
        H[1,2] += lambda[j]*sin(xj)*cos(xj)
        H[2,2] += lambda[j]*cos(xj)^2
    end
    e = A^2*e
    g[1] = - A^2*g[1]
    g[2] = - A*g[2]
    H[1,1] = A^2*H[1,1]
    H[1,2] = A*H[1,2]
    H[2,1] = H[1,2]
    
    return e - g' * (H \ g)
end

function m2(args...)
    N = 32
    
    t = [args[i] for i=1:N]
    lambda = [args[i] for i=N+1:2N]
    w1   = args[2N+1]
    Phi1 = args[2N+2]
    A1   = args[2N+3]
    w2   = args[2N+4]
    Phi2 = args[2N+5]
    A2   = args[2N+6]
    
    s_1cos = sqrt.(lambda) .* cos.(w1*t)
    s_1sin = sqrt.(lambda) .* sin.(w1*t)
    s_2cos = sqrt.(lambda) .* cos.(w2*t)
    s_2sin = sqrt.(lambda) .* sin.(w2*t)
    
    ds_1cos = dot(s_1cos, s_1cos)
    ds_2cos = dot(s_2cos, s_2cos)
    ds_12cos = dot(s_1cos, s_2cos)
    
    ds_1sin = dot(s_1sin, s_1sin)
    ds_2sin = dot(s_2sin, s_2sin)
    ds_12sin = dot(s_1sin, s_2sin)
    
    bmin_cos_m = (ds_1cos + ds_2cos - sqrt((ds_1cos - ds_2cos)^2 + 4*ds_12cos^2)) / 2
    bmin_cos_p = (ds_1cos + ds_2cos + sqrt((ds_1cos - ds_2cos)^2 + 4*ds_12cos^2)) / 2
    bmin_sin_m = (ds_1sin + ds_2sin - sqrt((ds_1sin - ds_2sin)^2 + 4*ds_12sin^2)) / 2
    bmin_sin_p = (ds_1sin + ds_2sin + sqrt((ds_1sin - ds_2sin)^2 + 4*ds_12sin^2)) / 2
    
    lambda_min = min([min([bmin_cos_m, bmin_cos_p]), min([bmin_sin_m, bmin_sin_p])])
    
    return A1^2 * lambda_min
end

N = 32
nw = 64
nphi = 32
A = 31.6228

STFE = Model()

p = -1
Pfalse = 0.01
Eps = pi/100

t = [i/N for i=-(N-1):2:(N+1)]

(nodes_w, weights_w) = gausshermite(nw)
(nodes_phi, weights_phi) = gausshermite(nphi)

JuMP.register(STFE, :FI, 2N+3, FisherInf, autodiff=true)
JuMP.register(STFE, :M2, 2N+6, m2, autodiff=true)

@variable(STFE, lambda[1:N])
@variable(STFE, 0 <= w1 <= pi)
@variable(STFE, 0 <= w2 <= pi)
@variable(STFE, -pi/2 <= Phi1 <= pi/2)
@variable(STFE, -pi/2 <= Phi2 <= pi/2)
@variable(STFE, 0 <= A1 <= 1000)
@variable(STFE, 0 <= A2 <= 1000)

@NLexpression(STFE, integrand2[i=1:64, j=1:32], abs(p) / p * FI(t...,lambda...,nodes_w[i],nodes_phi[j],A)^p)
@NLexpression(STFE, integrand1[i=1:nw], sum(integrand2[i,k] * weights_phi[k] for k in 1:nphi))

@NLconstraint(STFE, amb_constr, M2(t...,lambda...,w1,Phi1,A1,w2,Phi2,A2) > 8*erfinv(sqrt(1-2Pfalse))^2/A^2)
@constraint(STFE, diag_constr, -Eps <= w1-w2 <= Eps)
@objective(STFE, Max, dot(integrand1[:], weights_w))

solve(STFE)
println("lambda_opt = ", getvalue(lambda))

I am getting this error:

MethodError: no method matching parseNLExpr_runtime(::JuMP.Model, ::Float64, ::Float64, ::Float64, ::Float64, ::Float64, ::Float64, ::Float64, ::Float64, ::Float64, ::Float64, ::Float64, ::Float64, ::Float64, ::Float64, ::Float64, ::Float64, ::Float64, ::Float64, ::Float64, ::Float64, ::Float64, ::Float64, ::Float64, ::Float64, ::Float64, ::Float64, ::Float64, ::Float64, ::Float64, ::Float64, ::Float64, ::Float64, ::Float64, ::Array{ReverseDiffSparse.NodeData,1}, ::Int64, ::Array{Float64,1})
Closest candidates are:
  parseNLExpr_runtime(::JuMP.Model, ::Number, ::Any, ::Any, ::Any) at C:\Users\arbenede\.julia\v0.6\JuMP\src\parsenlp.jl:196
  parseNLExpr_runtime(::JuMP.Model, ::JuMP.Variable, ::Any, ::Any, ::Any) at C:\Users\arbenede\.julia\v0.6\JuMP\src\parsenlp.jl:202
  parseNLExpr_runtime(::JuMP.Model, ::JuMP.NonlinearExpression, ::Any, ::Any, ::Any) at C:\Users\arbenede\.julia\v0.6\JuMP\src\parsenlp.jl:208

I believe that that I have followed all the guidelines in the documentation…

Any ideas?

Thanks much

-Arrigo


JuMP/Ipopt failing on simple problem