How to print solver status and reason for termination for NLopt and Optimization.jl

I am searching for a minimum using NLopt.LN_SBPLX. The optimizer stops prematurely after ~100 iterations without throwing any errors or printing any messages. display(sol) simply returns the last parameter vector that was used by the solver. I know the termination is premature because the value of the objective function was decreasing immediately before the termination (I can tell because the function moment_for_optimizer prints the value of the objective function).

How can I display the solver status and reason for termination? Usually solvers give you messages such as xtol was reached etc. I am looking for something like that so I know which tolerance to increase if I want the solver to continue running.

Below is how I call the optimizer

#  moment_for_optimizer(x) = somefunction(x)

g(p_vec, pp)             = moment_for_optimizer(p_vec)
f                        = OptimizationFunction(g)
prob                     = Optimization.OptimizationProblem(f, param_vec_guess, 1)
sol                      = solve(prob, NLopt.LN_SBPLX())


Here’s a code snippet that shows how you can do this.

    (objvalue, xopt, flag) = NLopt.optimize(opt, startval)
    return xopt, objvalue, flag

function fmincon(silent=false)
    if !silent
        println("with no arguments, fmincon() runs a simple example")
        println("type edit(fmincon, ()) to see the example code")
    # return of objective should be real valued, thus the [1] to pull value out of 1-dim array
    obj = x -> x'x
    x = [2.0, 2.0]
    # sum of params should be 1
    R = [1.0 1.0]
    r = 1.0
    results = fmincon(obj, x, R, r)
    # check convergence
    results[3] == :FTOL_REACHED

NLopt.optimize returns a triplet, the last item of which is the convergence message. The complete function checks for convergence to the function tolerance, at the end. The NLopt documentation contains information on the other possible values of the flag.

fmincon is just a wrapper to NLopt’s LNCOBYLA, for student’s who are used to MATLAB.