# @NLconstraint not working with splatting syntax

**URL:** <https://discourse.julialang.org/t/nlconstraint-not-working-with-splatting-syntax/13796>\
**Category:** Optimization (Mathematical)\
**Tags:** jump\
**Created:** [August 21, 2018, 12:25am UTC](https://discourse.julialang.org/t/nlconstraint-not-working-with-splatting-syntax/13796 "2018-08-21T00:25:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arrigo\_Benedetti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/arrigo_benedetti/32/25545_2.png) [@Arrigo\_Benedetti](https://discourse.julialang.org/u/Arrigo_Benedetti)\
**Post date:** [August 21, 2018, 12:25am UTC](https://discourse.julialang.org/t/nlconstraint-not-working-with-splatting-syntax/13796/1 "2018-08-21T00:25:07Z")

</div>

I am trying to solve a constrained non linear optimization problem with JuMP/Ipopt and since the cost function and the constraint are functions of vector variables, I am using the splatting syntax as suggested in the JuMP documentation. Here is the minimal reproducible example of the problem:

```julia
using JuMP
using Ipopt

function Cost(args...)
    x = [args[i] for i=1:8]
    y = [args[i] for i=9:16]
    u = [sum(x), sum(y)]
    
    return - cos((u[1]-0.1)*u[2])^2 - u[1]*(sin(3u[1]+u[2]))
end

function Constr(args...)
    x = [args[i] for i=1:8]
    y = [args[i] for i=9:16]
    t = atan2(sum(y), sum(x))
    
    return (2cos(t) - cos(2t) / 2 - cos(3t) / 4 - cos(4t) / 8)^2 + (2sin(t))^2 
end

m = Model(solver=IpoptSolver(print_level=1))

JuMP.register(m, :Cost, 16, Cost, autodiff=true)
JuMP.register(m, :Constr, 16, Constr, autodiff=true)

@variable(m, -2.25 <= x[1:8] <= 2.5, start=1)
@variable(m, -2.5 <= y[1:8] <= 1.75, start=1)

@NLconstraint(m, c1, sum(x[i]^2 for i in 1:8) + sum(y[i]^2 for i in 1:8) <= Constr(x...,y...))
@NLobjective(m, Min, Cost(x...,y...))

solve(m)

```

and the error is:

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

Stacktrace:
 [1] macro expansion at C:\Users\arbenede\.julia\v0.6\JuMP\src\parsenlp.jl:88 [inlined]
 [2] macro expansion at C:\Users\arbenede\.julia\v0.6\JuMP\src\macros.jl:1201 [inlined]
 [3] anonymous at .\<missing>:?

```

Any ideas about what is going on?

Thank,

-Arrigo

---

<div class="post-metadata">

**Author:** ![miles.lubin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/miles.lubin/32/279_2.png) [@miles.lubin](https://discourse.julialang.org/u/miles.lubin)\
**Post date:** [August 22, 2018, 2:12am UTC](https://discourse.julialang.org/t/nlconstraint-not-working-with-splatting-syntax/13796/2 "2018-08-22T02:12:34Z")

</div>

> [@Arrigo\_Benedetti](#):
>
> Any ideas about what is going on?

Yes, this nasty error message means that the splatting syntax is not supported. I just fixed the error message ([syntax error on splatting in NLexpression by mlubin · Pull Request #1434 · jump-dev/JuMP.jl · GitHub](https://github.com/JuliaOpt/JuMP.jl/pull/1434)). See previous discussions for workarounds:

> [@Solvers, nonlinear constraints and user defined functions](https://discourse.julialang.org/t/solvers-nonlinear-constraints-and-user-defined-functions/4690):
>
> I apologize if someone had raised questions like this. And I understand the topic sounded similar to some previous topics. I did do a search. But didn’t found specific answers to all the questions I have. I understand that Gurobi is not a nonlinear programming solver. But it’s one of the lead solvers these days. Is it worth to go through all the trouble trying to reformulate the problem somehow into a convex quadratic problem approximately or a nonlinear solver such as Ipopt works as well? …

> [@Optimizing an array of variables using JuMP (NLP)](https://discourse.julialang.org/t/optimizing-an-array-of-variables-using-jump-nlp/12104):
>
> Hi all, I’m trying to formulate a nonlinear optimization problem with JuMP. Specifically, I’m looking to minimize the sum of the products of certain values in a matrix where one matrix is variable, and two additional matrices are constants. My question is how should I be handling an optimization problem where my variables are a 2D or 3D matrix of floats. The objective function can be expressed as: min \sum\_{i=1}^n \alpha\_i \prod\_{s=1}^S exp(-w\_{i,s}\*x\_{i,s}) I’ve run in to a number of probl…

---

<div class="post-metadata">

**Author:** ![Arrigo\_Benedetti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/arrigo_benedetti/32/25545_2.png) [@Arrigo\_Benedetti](https://discourse.julialang.org/u/Arrigo_Benedetti)\
**Post date:** [August 22, 2018, 7:02am UTC](https://discourse.julialang.org/t/nlconstraint-not-working-with-splatting-syntax/13796/3 "2018-08-22T07:02:01Z")

</div>

Thanks, Miles. I’ll try the suggestions.
