# JuMP with Pajarito/Pavito for a simple MINLP fails with solver does not support MathOptInterface.ScalarNonlinearFunction

**URL:** https://discourse.julialang.org/t/jump-with-pajarito-pavito-for-a-simple-minlp-fails-with-solver-does-not-support-mathoptinterface-scalarnonlinearfunction/106314
**Category:** Optimization (Mathematical)
**Created:** [November 16, 2023, 12:06pm UTC](https://discourse.julialang.org/t/jump-with-pajarito-pavito-for-a-simple-minlp-fails-with-solver-does-not-support-mathoptinterface-scalarnonlinearfunction/106314 "2023-11-16T12:06:59Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![stephanmg](https://avatars.discourse-cdn.com/v4/letter/s/f14d63/32.png) [@stephanmg](https://discourse.julialang.org/u/stephanmg)
#### Post date: [November 16, 2023, 12:06pm UTC](https://discourse.julialang.org/t/jump-with-pajarito-pavito-for-a-simple-minlp-fails-with-solver-does-not-support-mathoptinterface-scalarnonlinearfunction/106314/1 "2023-11-16T12:06:59Z")

</div>

Dear all,

trying to set up a simple MINLP somehow fails for me with: MathOptInterface.ScalarNonlinearFunction

Code:

```julia
using JuMP
using HiGHS
using Pavito, Pajarito, Hypatia
using LinearAlgebra
import Ipopt, GLPK

vector_model = Model(
    optimizer_with_attributes(
        Pavito.Optimizer,
        "mip_solver" => optimizer_with_attributes(GLPK.Optimizer),
        "cont_solver" =>
        optimizer_with_attributes(Ipopt.Optimizer),
    ),
)

vector_model = Model(
    optimizer_with_attributes(
        Pajarito.Optimizer,
        "oa_solver" => optimizer_with_attributes(
            HiGHS.Optimizer,
            MOI.Silent() => true,
            "mip_feasibility_tolerance" => 1e-8,
            "mip_rel_gap" => 1e-6,
        ),
        "conic_solver" =>
            optimizer_with_attributes(Hypatia.Optimizer, MOI.Silent() => false),
    )
)

mymatrix = [0 0.8 0.3 0.1;
            0.3 0.1 0.1 0.1;
            0.7 0.7 0.2 0.3]

@variable(vector_model, x[1:3] >= 0, integer = true)
@constraint(vector_model, sum(x) <= 3)
threshold = 1
lambda = 0.1
@objective(vector_model, Max, sum(x'*mymatrix)-threshold + lambda * sum(abs.(x)))

optimize!(vector_model)
println(JuMP.value.(x) / maximum(JuMP.value.(x)))

```

Any help is highly appreciated.  
Kind regards,  
Stephan

---

<div class="post-metadata">

### Author: ![jd-foster](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jd-foster/32/35824_2.png) [@jd-foster](https://discourse.julialang.org/u/jd-foster)
#### Post date: [November 16, 2023, 1:25pm UTC](https://discourse.julialang.org/t/jump-with-pajarito-pavito-for-a-simple-minlp-fails-with-solver-does-not-support-mathoptinterface-scalarnonlinearfunction/106314/2 "2023-11-16T13:25:03Z")

</div>

Pajarito and Hypatia are conic solvers, which means that they handle nonlinear functions, but only specific types of nonlinear functions. Your error is saying that the choice of solver does not support your general nonlinear objective function.

---

<div class="post-metadata">

### Author: ![jd-foster](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jd-foster/32/35824_2.png) [@jd-foster](https://discourse.julialang.org/u/jd-foster)
#### Post date: [November 16, 2023, 1:35pm UTC](https://discourse.julialang.org/t/jump-with-pajarito-pavito-for-a-simple-minlp-fails-with-solver-does-not-support-mathoptinterface-scalarnonlinearfunction/106314/3 "2023-11-16T13:35:37Z")

</div>

The issue is the term `sum(abs.(x)))`

This comes up fairly often, e.g.: [Abs in JuMP - #3 by odow](https://discourse.julialang.org/t/abs-in-jump/90811/3)

You need to reformulate `sum(abs.(x)))` as `sum(t)` where you’ve defined

```julia
@variable(vector_model, t[1:length(x)] >= 0)
@constraint(vector_model, [i=1:length(x)], x[i] <= t[i])
@constraint(vector_model, [i=1:length(x)], -t[i] <= x[i])

```

---

<div class="post-metadata">

### Author: ![jd-foster](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jd-foster/32/35824_2.png) [@jd-foster](https://discourse.julialang.org/u/jd-foster)
#### Post date: [November 16, 2023, 1:42pm UTC](https://discourse.julialang.org/t/jump-with-pajarito-pavito-for-a-simple-minlp-fails-with-solver-does-not-support-mathoptinterface-scalarnonlinearfunction/106314/4 "2023-11-16T13:42:17Z")

</div>

> [@stephanmg](#):
>
> `@objective(vector_model, Max, sum(x'*mymatrix)-threshold + lambda * sum(abs.(x)))`

So this would probably need to be `Min` not `Max` and read

```julia
@objective(vector_model, Min, sum(x'*mymatrix)-threshold + lambda * sum(t))

```

---

<div class="post-metadata">

### Author: ![stephanmg](https://avatars.discourse-cdn.com/v4/letter/s/f14d63/32.png) [@stephanmg](https://discourse.julialang.org/u/stephanmg)
#### Post date: [November 16, 2023, 1:55pm UTC](https://discourse.julialang.org/t/jump-with-pajarito-pavito-for-a-simple-minlp-fails-with-solver-does-not-support-mathoptinterface-scalarnonlinearfunction/106314/5 "2023-11-16T13:55:16Z")

</div>

Thanks @jd-foster, should have checked the forum before hand for that common issue.

Kind regards,  
Stephan

---

<div class="post-metadata">

### Author: ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)
#### Post date: [November 16, 2023, 7:05pm UTC](https://discourse.julialang.org/t/jump-with-pajarito-pavito-for-a-simple-minlp-fails-with-solver-does-not-support-mathoptinterface-scalarnonlinearfunction/106314/6 "2023-11-16T19:05:39Z")

</div>

Hi @stephanmg,

The failure is because you’re trying to use the new nonlinear interface [Nonlinear Modeling · JuMP](https://jump.dev/JuMP.jl/stable/manual/nonlinear/), but I haven’t updated Pavito yet.

You need to use the legacy interface, [Nonlinear Modeling (Legacy) · JuMP](https://jump.dev/JuMP.jl/stable/manual/nlp/), but it requires you to change:

```julia
@objective(vector_model, Minn, sum(x'*mymatrix)-threshold + lambda * sum(abs.(x)))

```

into

```julia
@NLobjective(vector_model, Min, sum(sum(x[i] * mymatrix[i, j] for i in 1:3) for j in 1:3) - threshold + lambda * sum(abs(x[i] for i in 1:3)))

```

(I didn’t test, so I might have made a typo, but that should point you in the right direction.)

Also note that Pajarito is not applicable here. It requires the model in conic form. Pavito is the nonlinear solver.
