# Obtaining Step Norm in KNITRO.jl

**URL:** <https://discourse.julialang.org/t/obtaining-step-norm-in-knitro-jl/107577>\
**Category:** Optimization (Mathematical)\
**Created:** [December 13, 2023, 5:38pm UTC](https://discourse.julialang.org/t/obtaining-step-norm-in-knitro-jl/107577 "2023-12-13T17:38:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![fimiller](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fimiller/32/51226_2.png) [@fimiller](https://discourse.julialang.org/u/fimiller)\
**Post date:** [December 13, 2023, 5:38pm UTC](https://discourse.julialang.org/t/obtaining-step-norm-in-knitro-jl/107577/1 "2023-12-13T17:38:04Z")

</div>

Hello,

From a previous post ([Computing common components in KNITRO callbacks](https://discourse.julialang.org/t/computing-common-components-in-knitro-callbacks/107014/)), 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](https://global.discourse-cdn.com/julialang/original/3X/f/e/feeb6ae7f82e07c081d9275ff52ac76d00fadb8f.png)

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:

```julia

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.

---

<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:** [December 13, 2023, 7:53pm UTC](https://discourse.julialang.org/t/obtaining-step-norm-in-knitro-jl/107577/2 "2023-12-13T19:53:03Z")

</div>

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

The corresponding functions are here:

> <https://github.com/jump-dev/KNITRO.jl/blob/master/src/libknitro.jl>

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

---

<div class="post-metadata">

**Author:** ![frapac](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/frapac/32/6879_2.png) [@frapac](https://discourse.julialang.org/u/frapac)\
**Post date:** [December 14, 2023, 4:30pm UTC](https://discourse.julialang.org/t/obtaining-step-norm-in-knitro-jl/107577/3 "2023-12-14T16:30:29Z")

</div>

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](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)

---

<div class="post-metadata">

**Author:** ![fimiller](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fimiller/32/51226_2.png) [@fimiller](https://discourse.julialang.org/u/fimiller)\
**Post date:** [December 14, 2023, 4:53pm UTC](https://discourse.julialang.org/t/obtaining-step-norm-in-knitro-jl/107577/4 "2023-12-14T16:53:06Z")

</div>

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

```julia
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!
