Obtaining Step Norm in KNITRO.jl

Hello,

From a previous post (Computing common components in KNITRO callbacks), I am working on a creating an algorithm that uses the KNITRO.jl solver. I am in the process of trying to report data as I run experiments on several datasets.

As seen in the screenshot below, when calling KNITRO, I see this below:
image

I am wondering if it is possible to get the ||step|| from a call to KNITRO. Something like KNITRO.KN_get_step_norm(kc). Looking around the documentation, I was not able to find an immediate way to do this. Any pointers would be appreciated. Thanks!

In particular, I have a function:


function callbackNewPoint(kc, x, lambda_, userParams)
     # Get the number of variables in the model
        n = KNITRO.KN_get_number_vars(kc)

        # Query information about the current problem.
        dFeasError = KNITRO.KN_get_abs_feas_error(kc)

        if verbose
            println(">> New point computed by Knitro:(", x, ")")
            println("Number FC evals= ", KNITRO.KN_get_number_FC_evals(kc))
            println("Current feasError= ", dFeasError)
           # println("step norm: ," KNITRO.KN_...)
        end

     return 0

end

If I can print it out in this funciton, then I could store in my data table.

1 Like

KNITRO.jl supports everything in the callable library:
https://www.artelys.com/app/docs/knitro/3_referenceManual/callableLibraryAPI.html

The corresponding functions are here:

I, too, could not see a way to get this. But @frapac may have an idea.

I am not aware of any obvious solution to query the norm of the current step.

A workaround would to query the current primal-dual solution (x_k, \lambda_k) with KN_get_solution:
https://www.artelys.com/app/docs/knitro/3_referenceManual/callableLibraryAPI.html#KN_get_solution

and to evaluate yourself the increment between two iterations :

{\tt step}_k = (x_{k+1}, \lambda_{k+1}) - (x_k , \lambda_k)

From the Julia example nlp2.jl, there an example callback

function callbackNewPoint(kc, x, lambda_, userParams)

        # Get the number of variables in the model
        n = KNITRO.KN_get_number_vars(kc)

        # Query information about the current problem.
        dFeasError = KNITRO.KN_get_abs_feas_error(kc)

        if verbose
            println(">> New point computed by Knitro:(", x, ")")
            println("Number FC evals= ", KNITRO.KN_get_number_FC_evals(kc))
            println("Current feasError= ", dFeasError)
        end

        # Demonstrate user-defined termination
        #(Uncomment to activate)
        if KNITRO.KN_get_obj_value(kc) > 0.2 && dFeasError <= 1.0e-4
            return KNITRO.KN_RC_USER_TERMINATION
        end

        return 0
    end

Does x refer to x_{k+1} and lambda_ refer to \lambda_{k+1}, and KN_get_solution refer to (x_k, \lambda_k)?
Thanks!

1 Like