# NLopt return flag: is there a simple way to check for success?

**URL:** https://discourse.julialang.org/t/nlopt-return-flag-is-there-a-simple-way-to-check-for-success/84637
**Category:** Optimization (Mathematical)
**Tags:** nlopt
**Created:** [July 22, 2022, 3:41pm UTC](https://discourse.julialang.org/t/nlopt-return-flag-is-there-a-simple-way-to-check-for-success/84637 "2022-07-22T15:41:24Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![mcreel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mcreel/32/30088_2.png) [@mcreel](https://discourse.julialang.org/u/mcreel)
#### Post date: [July 22, 2022, 3:41pm UTC](https://discourse.julialang.org/t/nlopt-return-flag-is-there-a-simple-way-to-check-for-success/84637/1 "2022-07-22T15:41:24Z")

</div>

NLopt.optimize returns a tuple `(objvalue, xopt, flag)`, and flag is a symbol that can hold strings such as FTOL\_REACHED or SUCCESS. The C API mentions that positive return values indicate success. Is there a similar way to test for success or failure with the Julia package? I can’t figure out how to get beyond a string, which I obtain using `println("$flag")`. I don’t see how to find an associated numerical value.

---

<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: [July 22, 2022, 9:59pm UTC](https://discourse.julialang.org/t/nlopt-return-flag-is-there-a-simple-way-to-check-for-success/84637/2 "2022-07-22T21:59:39Z")

</div>

You can see the return codes here:  
[https://github.com/JuliaOpt/NLopt.jl/blob/c93b84844e7e372d03658a90b7f1cf108969bc2a/src/NLopt.jl#L66-L78](https://github.com/JuliaOpt/NLopt.jl/blob/c93b84844e7e372d03658a90b7f1cf108969bc2a/src/NLopt.jl#L66-L78)  
but unfortunately NLopt returns a `Symbol` instead of the enum:  
[https://github.com/JuliaOpt/NLopt.jl/blob/c93b84844e7e372d03658a90b7f1cf108969bc2a/src/NLopt.jl#L622](https://github.com/JuliaOpt/NLopt.jl/blob/c93b84844e7e372d03658a90b7f1cf108969bc2a/src/NLopt.jl#L622)  
So you probably just need to deal with each of the possible return values.

Or something like

```nohighlight
is_success(ret::Symbol) = ret == :SUCCESS || endswith("$ret", "_REACHED")

```

---

<div class="post-metadata">

### Author: ![mcreel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mcreel/32/30088_2.png) [@mcreel](https://discourse.julialang.org/u/mcreel)
#### Post date: [July 23, 2022, 4:35am UTC](https://discourse.julialang.org/t/nlopt-return-flag-is-there-a-simple-way-to-check-for-success/84637/3 "2022-07-23T04:35:50Z")

</div>

Thanks, I will use this option.
