# Count the number of evauations of the objective function

**URL:** <https://discourse.julialang.org/t/count-the-number-of-evauations-of-the-objective-function/43251>\
**Category:** Optimization (Mathematical)\
**Tags:** jump\
**Created:** [July 17, 2020, 5:41pm UTC](https://discourse.julialang.org/t/count-the-number-of-evauations-of-the-objective-function/43251 "2020-07-17T17:41:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ariel\_Cruz\_Cruz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ariel_cruz_cruz/32/10377_2.png) [@Ariel\_Cruz\_Cruz](https://discourse.julialang.org/u/Ariel_Cruz_Cruz)\
**Post date:** [July 17, 2020, 5:41pm UTC](https://discourse.julialang.org/t/count-the-number-of-evauations-of-the-objective-function/43251/1 "2020-07-17T17:41:06Z")

</div>

Hello, I am using JuMP with the Ipopt solver to optimize certain optimization problem. And I need to get the number of evaluations of the objective function. When I run my program I get some information such as:

```julia
Number of objective function evaluations = 16
Number of objective gradient evaluations = 9
Number of equality constraint evaluations = 0
Number of inequality constraint evaluations = 16
Number of equality constraint Jacobian evaluations = 0
Number of inequality constraint Jacobian evaluations = 1
Number of Lagrangian Hessian evaluations = 2
Total CPU secs in IPOPT (w/o function evaluations) = 10.678
Total CPU secs in NLP function evaluations = 3.843

```

But this information is given just as a text. I want to know if there is a way to ask for the **Number of objective function evaluations**

Thanks

---

<div class="post-metadata">

**Author:** ![Ariel\_Cruz\_Cruz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ariel_cruz_cruz/32/10377_2.png) [@Ariel\_Cruz\_Cruz](https://discourse.julialang.org/u/Ariel_Cruz_Cruz)\
**Post date:** [July 23, 2020, 8:03am UTC](https://discourse.julialang.org/t/count-the-number-of-evauations-of-the-objective-function/43251/2 "2020-07-23T08:03:42Z")

</div>

No one knows anything about this???

---

<div class="post-metadata">

**Author:** ![abelsiqueira](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abelsiqueira/32/47269_2.png) [@abelsiqueira](https://discourse.julialang.org/u/abelsiqueira)\
**Post date:** [July 23, 2020, 10:48am UTC](https://discourse.julialang.org/t/count-the-number-of-evauations-of-the-objective-function/43251/3 "2020-07-23T10:48:19Z")

</div>

Hi Ariel,

you can transform the problem into an NLPModel and then run Ipopt through NLPModelsIpopt.  
The number of function evaluations is obtainable through `neval_obj(nlp)`.  
Short example:

```julia
using NLPModels, NLPModelsIpopt, NLPModelsJuMP

# Define your jump_model
nlp = MathOptNLPModel(jump_model)
output = ipopt(nlp)
neval_obj(nlp)

```

For more information, [here are the docs of NLPModels](https://juliasmoothoptimizers.github.io/NLPModels.jl/stable/), and in [this video](https://www.youtube.com/watch?v=DW9UAXDh77g&list=PLOOY0eChA1uxmm8G2caFpdX7X9NjgpDUY&index=2) and the ones after, I create a solver and compare it against Ipopt, so some parts are useful.

---

<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 23, 2020, 1:06pm UTC](https://discourse.julialang.org/t/count-the-number-of-evauations-of-the-objective-function/43251/4 "2020-07-23T13:06:23Z")

</div>

I don’t think there is an easy way to get this from Ipopt and JuMP.
