# JuMP+EAGO+@NLexpressions gives numeric instability

**URL:** https://discourse.julialang.org/t/jump-eago-nlexpressions-gives-numeric-instability/61093
**Category:** Optimization (Mathematical)
**Tags:** jump
**Created:** [May 13, 2021, 3:41pm UTC](https://discourse.julialang.org/t/jump-eago-nlexpressions-gives-numeric-instability/61093 "2021-05-13T15:41:17Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![blob](https://avatars.discourse-cdn.com/v4/letter/b/ebca7d/32.png) [@blob](https://discourse.julialang.org/u/blob)
#### Post date: [May 13, 2021, 3:41pm UTC](https://discourse.julialang.org/t/jump-eago-nlexpressions-gives-numeric-instability/61093/1 "2021-05-13T15:41:17Z")

</div>

I want to use EAGO.jl as an alternative solver to ipopt for nonlinear problems. I ran the example from the website ([GitHub - PSORLab/EAGO.jl: A development environment for robust and global optimization](https://github.com/PSORLab/EAGO.jl)) and it works fine. When I slightly rewrite the problem using `@NLexpressions`, the problem does not work anymore. Running `optimize!()` breaks Julia and gives me:  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/0/c/0c01d979fa65885caf61b531e4e8ee94b68af756.png)  
This keeps going on and on, I have to force quit the editor. Any ideas what can be wrong are welcome.

The rewritten problem:

```julia
using JuMP, EAGO

m = Model(EAGO.Optimizer)

# Define bounded variables
xL = [10.0; 0.0; 0.0; 0.0; 0.0; 85.0; 90.0; 3.0; 1.2; 145.0]
xU = [2000.0; 16000.0; 120.0; 5000.0; 2000.0; 93.0; 95.0; 12.0; 4.0; 162.0]
@variable(m, xL[i] <= x[i=1:10] <= xU[i])

# Define nonlinear constraints
@NLconstraint(m, e1, -x[1]*(1.12+0.13167*x[8]-0.00667* (x[8])^2)+x[4] == 0.0)
@NLconstraint(m, e3, -0.001*x[4]*x[9]*x[6]/(98-x[6])+x[3] == 0.0)

###Original constraints
##@NLconstraint(m, e4, -(1.098*x[8]-0.038* (x[8])^2)-0.325*x[6]+x[7] == 57.425)
##@NLconstraint(m, e5, -(x[2]+x[5])/x[1]+x[8] == 0.0)

###Rewritten constraints
@NLexpressions(m, begin
 ex1, -(x[2]+x[5])/x[1]+x[8]
 ex2, -(1.098*x[8]-0.038* (x[8])^2)-0.325*x[6]+x[7]
end)
@NLconstraint(m, e4, ex2 == 57.425)
@NLconstraint(m, e5, ex1 == 0.0)

# Define linear constraints
@constraint(m, e2, -x[1]+1.22*x[4]-x[5] == 0.0)
@constraint(m, e6, x[9]+0.222*x[10] == 35.82)
@constraint(m, e7, -3*x[7]+x[10] == -133.0)

# Define nonlinear objective
@NLobjective(m, Max, 0.063*x[4]*x[7] - 5.04*x[1] - 0.035*x[2] - 10*x[3] - 3.36*x[5])

# Solve the optimization problem
JuMP.optimize!(m)

```

I should add that if I split the expressions into two separate `@NLexpression`, the problem persists, but if I do only one constraint as `@NLexpression` and the other as `@NLconstraint`, there are no issues.

---

<div class="post-metadata">

### Author: ![joaquimg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joaquimg/32/223_2.png) [@joaquimg](https://discourse.julialang.org/u/joaquimg)
#### Post date: [May 13, 2021, 3:53pm UTC](https://discourse.julialang.org/t/jump-eago-nlexpressions-gives-numeric-instability/61093/2 "2021-05-13T15:53:33Z")

</div>

That is probably an issue with the EAGO solver, you should consider opening an issue in the repo as recommended in the readme [EAGO.jl - bug-reporting-support-and-feature-requests](https://github.com/PSORLab/EAGO.jl#bug-reporting-support-and-feature-requests). Remember to cross-reference this post.

---

<div class="post-metadata">

### Author: ![blob](https://avatars.discourse-cdn.com/v4/letter/b/ebca7d/32.png) [@blob](https://discourse.julialang.org/u/blob)
#### Post date: [May 13, 2021, 4:06pm UTC](https://discourse.julialang.org/t/jump-eago-nlexpressions-gives-numeric-instability/61093/3 "2021-05-13T16:06:13Z")

</div>

Thank you, that’s probably the best approach. I tried other solvers (ipopt and percival) and ipopt works fine, whereas percival has similar issues as EAGO (but at least runs out of time, doesn’t break Julia). I guess it is a question of how solvers handle `@NLexpressions`.

---

<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: [May 13, 2021, 9:29pm UTC](https://discourse.julialang.org/t/jump-eago-nlexpressions-gives-numeric-instability/61093/4 "2021-05-13T21:29:01Z")

</div>

Solvers don’t get to see `@NLexpression`. What was the issue with Percival?

The “numerical instability” issue is coming from GLPK. I’ve seen it frequently in cutting plane type problems.

Try a different solver: [High-Performance Configuration · EAGO.jl: Easy Advanced Global Optimization](https://psorlab.github.io/EAGO.jl/stable/Optimizer/high_performance/#LP-Solver-Selection)

---

<div class="post-metadata">

### Author: ![blob](https://avatars.discourse-cdn.com/v4/letter/b/ebca7d/32.png) [@blob](https://discourse.julialang.org/u/blob)
#### Post date: [May 14, 2021, 7:10am UTC](https://discourse.julialang.org/t/jump-eago-nlexpressions-gives-numeric-instability/61093/5 "2021-05-14T07:10:18Z")

</div>

Switching to CPLEX didn’t help:  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/b/4/b4da3bbeca3e7135e0da5bb3eb63dd44154847aa.png)  
Goes on and on again, until I force quit.

Percival runs out of time (the default is 30s) or iterations (the default is 2000). I increased both: the time to 600s and the iterations to 4000. It didn’t help:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/a/d/ad472ead7374e9f06f479fc2e950f58e3b98559f.png)  
And the final status for the increased parameters was `"Execution stats: maximum iteration"`

---

<div class="post-metadata">

### Author: ![joaquimg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joaquimg/32/223_2.png) [@joaquimg](https://discourse.julialang.org/u/joaquimg)
#### Post date: [June 14, 2021, 10:38pm UTC](https://discourse.julialang.org/t/jump-eago-nlexpressions-gives-numeric-instability/61093/6 "2021-06-14T22:38:04Z")

</div>

x-ref: [JuMP+EAGO+@NLexpressions gives numeric instability · Issue #88 · PSORLab/EAGO.jl · GitHub](https://github.com/PSORLab/EAGO.jl/issues/88)
