# Tools

## Functions evaluations

After calling one the API functions to get a function value, the number of times that function was called is stored inside the `NLPModel`

. For instance

```
using ADNLPModels, LinearAlgebra, NLPModels
nlp = ADNLPModel(x -> dot(x, x), zeros(2))
for i = 1:100
obj(nlp, rand(2))
end
neval_obj(nlp)
```

`100`

Some counters are available for all models, some are specific. In particular, there are additional specific counters for the nonlinear least squares models.

Counter | Description |
---|---|

`neval_obj` | Objective |

`neval_grad` | Gradient |

`neval_cons` | Constraints |

`neval_cons_lin` | Linear constraints |

`neval_cons_nln` | Nonlinear constraints |

`neval_jcon` | One constraint - unused |

`neval_jgrad` | Gradient of one constraints - unused |

`neval_jac` | Jacobian |

`neval_jac_lin` | Linear constraints Jacobian |

`neval_jac_nln` | Nonlinear constraints Jacobian |

`neval_jprod` | Product of Jacobian and vector |

`neval_jprod_lin` | Product of linear constraints Jacobian and vector |

`neval_jprod_nln` | Product of nonlinear constraints Jacobian and vector |

`neval_jtprod` | Product of transposed Jacobian and vector |

`neval_jtprod_lin` | Product of transposed linear constraints Jacobian and vector |

`neval_jtprod_nln` | Product of transposed nonlinear constraints Jacobian and vector |

`neval_hess` | Hessian |

`neval_hprod` | Product of Hessian and vector |

`neval_jhess` | Individual Lagrangian Hessian evaluations |

`neval_jhprod` | Product of Hessian of j-th function and vector |

`neval_residual` | Residual function of nonlinear least squares model |

`neval_jac_residual` | Jacobian of the residual |

`neval_jprod_residual` | Product of Jacobian of residual and vector |

`neval_jtprod_residual` | Product of transposed Jacobian of residual and vector |

`neval_hess_residual` | Sum of Hessians of residuals |

`neval_jhess_residual` | Hessian of a residual component |

`neval_hprod_residual` | Product of Hessian of a residual component and vector |

To get the sum of all counters except `cons`

, `jac`

, `jprod`

and `jtprod`

called for a problem, use `sum_counters`

.

```
using ADNLPModels, LinearAlgebra, NLPModels
nlp = ADNLPModel(x -> dot(x, x), zeros(2))
obj(nlp, rand(2))
grad(nlp, rand(2))
sum_counters(nlp)
```

`2`

## Querying problem type

There are some variable for querying the problem type:

`has_bounds`

: True when not all variables are free.`bound_constrained`

: True for problems with bounded variables and no other constraints.`equality_constrained`

: True when problem is constrained only by equalities.`has_equalities`

: True when problem has at least one equality constraint.`inequality_constrained`

: True when problem is constrained by inequalities.`has_inequalities`

: True when problem has at least one inequality constraint that isn't a bound.`linearly_constrained`

: True when problem is constrained by equalities or inequalities known to be linear.`unconstrained`

: True when problem is not constrained.

## Docs

Missing docstring for `Counters`

. Check Documenter's build log for details.

`NLPModels.neval_obj`

— Function`neval_obj(nlp)`

Get the number of `obj`

evaluations.

`NLPModels.neval_grad`

— Function`neval_grad(nlp)`

Get the number of `grad`

evaluations.

`NLPModels.neval_cons`

— Function`neval_cons(nlp)`

Get the number of `cons`

evaluations.

`NLPModels.neval_cons_lin`

— Function`neval_cons_lin(nlp)`

Get the number of `cons`

evaluations.

`NLPModels.neval_cons_nln`

— Function`neval_cons_nln(nlp)`

Get the number of `cons`

evaluations.

`NLPModels.neval_jcon`

— Function`neval_jcon(nlp)`

Get the number of `jcon`

evaluations.

`NLPModels.neval_jgrad`

— Function`neval_jgrad(nlp)`

Get the number of `jgrad`

evaluations.

`NLPModels.neval_jac`

— Function`neval_jac(nlp)`

Get the number of `jac`

evaluations.

`NLPModels.neval_jac_lin`

— Function`neval_jac_lin(nlp)`

Get the number of `jac`

evaluations.

`NLPModels.neval_jac_nln`

— Function`neval_jac_nln(nlp)`

Get the number of `jac`

evaluations.

`NLPModels.neval_jprod`

— Function`neval_jprod(nlp)`

Get the number of `jprod`

evaluations.

`NLPModels.neval_jprod_lin`

— Function`neval_jprod_lin(nlp)`

Get the number of `jprod`

evaluations.

`NLPModels.neval_jprod_nln`

— Function`neval_jprod_nln(nlp)`

Get the number of `jprod`

evaluations.

`NLPModels.neval_jtprod`

— Function`neval_jtprod(nlp)`

Get the number of `jtprod`

evaluations.

`NLPModels.neval_jtprod_lin`

— Function`neval_jtprod_lin(nlp)`

Get the number of `jtprod`

evaluations.

`NLPModels.neval_jtprod_nln`

— Function`neval_jtprod_nln(nlp)`

Get the number of `jtprod`

evaluations.

`NLPModels.neval_hess`

— Function`neval_hess(nlp)`

Get the number of `hess`

evaluations.

`NLPModels.neval_hprod`

— Function`neval_hprod(nlp)`

Get the number of `hprod`

evaluations.

`NLPModels.neval_jhess`

— Function`neval_jhess(nlp)`

Get the number of `jhess`

evaluations.

`NLPModels.neval_jhprod`

— Function`neval_jhprod(nlp)`

Get the number of `jhprod`

evaluations.

`NLPModels.neval_residual`

— Functionneval_residual(nlp)

Get the number of `residual`

evaluations.

`NLPModels.neval_jac_residual`

— Functionneval*jac*residual(nlp)

Get the number of `jac`

evaluations.

`NLPModels.neval_jprod_residual`

— Functionneval*jprod*residual(nlp)

Get the number of `jprod`

evaluations.

`NLPModels.neval_jtprod_residual`

— Functionneval*jtprod*residual(nlp)

Get the number of `jtprod`

evaluations.

`NLPModels.neval_hess_residual`

— Functionneval*hess*residual(nlp)

Get the number of `hess`

evaluations.

`NLPModels.neval_jhess_residual`

— Functionneval*jhess*residual(nlp)

Get the number of `jhess`

evaluations.

`NLPModels.neval_hprod_residual`

— Functionneval*hprod*residual(nlp)

Get the number of `hprod`

evaluations.

`NLPModels.sum_counters`

— Function`sum_counters(counters)`

Sum all counters of `counters`

except `cons`

, `jac`

, `jprod`

and `jtprod`

.

`sum_counters(nlp)`

Sum all counters of problem `nlp`

except `cons`

, `jac`

, `jprod`

and `jtprod`

.

`NLPModels.bound_constrained`

— Function```
bound_constrained(nlp)
bound_constrained(meta)
```

Returns whether the problem has bounds on the variables and no other constraints.

`NLPModels.equality_constrained`

— Function```
equality_constrained(nlp)
equality_constrained(meta)
```

Returns whether the problem's constraints are all equalities. Unconstrained problems return false.

`NLPModels.has_equalities`

— Function`has_equalities(nlp)`

Returns whether the problem has constraints and at least one of them is an equality. Unconstrained problems return false.

`NLPModels.has_bounds`

— Function```
has_bounds(nlp)
has_bounds(meta)
```

Returns whether the problem has bounds on the variables.

`NLPModels.inequality_constrained`

— Function```
inequality_constrained(nlp)
inequality_constrained(meta)
```

Returns whether the problem's constraints are all inequalities. Unconstrained problems return true.

`NLPModels.has_inequalities`

— Function`has_inequalities(nlp)`

Returns whether the problem has constraints and at least one of them is an inequality. Unconstrained problems return false.

`NLPModels.linearly_constrained`

— Function```
linearly_constrained(nlp)
linearly_constrained(meta)
```

Returns whether the problem's constraints are known to be all linear.

`NLPModels.unconstrained`

— Function```
unconstrained(nlp)
unconstrained(meta)
```

Returns whether the problem in unconstrained.