# How to access the exit of MadNLP solver directly

**URL:** <https://discourse.julialang.org/t/how-to-access-the-exit-of-madnlp-solver-directly/93685>\
**Category:** Optimization (Mathematical)\
**Created:** [January 28, 2023, 12:09pm UTC](https://discourse.julialang.org/t/how-to-access-the-exit-of-madnlp-solver-directly/93685 "2023-01-28T12:09:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![VPBML](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vpbml/32/212617_2.png) [@VPBML](https://discourse.julialang.org/u/VPBML)\
**Post date:** [January 28, 2023, 12:09pm UTC](https://discourse.julialang.org/t/how-to-access-the-exit-of-madnlp-solver-directly/93685/1 "2023-01-28T12:09:55Z")

</div>

Hi all,

I wonder if it is possible to access the exit of a solver directly from JuMP0, i.e. the exit we get when not setting the JuMP model in silent as shown in the screenshot below. I would really appreciate it if you could provide me some hints on this.  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/d/8/d8cb8e43e1796840c665df1e8ec142b237e2e9c0.png)

Regards.

---

<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:** [January 29, 2023, 6:49pm UTC](https://discourse.julialang.org/t/how-to-access-the-exit-of-madnlp-solver-directly/93685/2 "2023-01-29T18:49:04Z")

</div>

You can do this in a solver-independent fashion using:

```julia
termination_status(model)

```

In this case, the return should be `INVALID_MODEL`, and it likely means you have something like `log(x)` where `x <= 0` in your model.

I don’t know if there is an easy way to access the exact string. After solving, you can access the `MadNLP.Optimizer` object with `mad = unsafe_backend(model)`. You’d have to explore. Perhaps `mad.result.status`.

---

<div class="post-metadata">

**Author:** ![VPBML](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vpbml/32/212617_2.png) [@VPBML](https://discourse.julialang.org/u/VPBML)\
**Post date:** [January 29, 2023, 7:26pm UTC](https://discourse.julialang.org/t/how-to-access-the-exit-of-madnlp-solver-directly/93685/3 "2023-01-29T19:26:19Z")

</div>

Hi,  
The reason I asked is because sometimes `termination_status(model)` does not work, in a sense that it does not give `INVALID_MODEL` but instead `MethodError: Cannot 'convert' an object of type MathOptInterface.ResultStatusCode to an object of type MathOptInterface.TerminationStatusCode`. That was what happened when I tried this example:

```julia
using JuMP, MadNLP
m = Model(MadNLP.Optimizer)
@variable(m, x)
@variable(m, y)
@NLobjective(m, Min, (x-5)^2 + (y-8)^2)
@NLconstraint(m, x*y==5)
optimize!(m)
println(termination_status(model))

```

The fact that MadNLP returns an error in this case is a known issue (as mentioned in [Invalid number in NLP Hessian Lagrangian detrected / error in MadNLP · Issue #239 · MadNLP/MadNLP.jl · GitHub](https://github.com/MadNLP/MadNLP.jl/issues/239)), but I do not understand why I cannot use `termination_status(model)` in this case.

---

<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:** [January 29, 2023, 8:22pm UTC](https://discourse.julialang.org/t/how-to-access-the-exit-of-madnlp-solver-directly/93685/4 "2023-01-29T20:22:44Z")

</div>

The convert error looks like a bug. I’ll take a look

---

<div class="post-metadata">

**Author:** ![VPBML](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vpbml/32/212617_2.png) [@VPBML](https://discourse.julialang.org/u/VPBML)\
**Post date:** [January 29, 2023, 8:26pm UTC](https://discourse.julialang.org/t/how-to-access-the-exit-of-madnlp-solver-directly/93685/5 "2023-01-29T20:26:53Z")

</div>

That would be great. Thanks. 😀

---

<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:** [January 29, 2023, 8:39pm UTC](https://discourse.julialang.org/t/how-to-access-the-exit-of-madnlp-solver-directly/93685/6 "2023-01-29T20:39:52Z")

</div>

It was a bug: [Fix invalid return code in MOI.TerminationStatus by odow · Pull Request #241 · MadNLP/MadNLP.jl · GitHub](https://github.com/MadNLP/MadNLP.jl/pull/241). Thanks for finding and reporting it!
