# How to get the value of an NLconstraint in JuMP

**URL:** <https://discourse.julialang.org/t/how-to-get-the-value-of-an-nlconstraint-in-jump/84248>\
**Category:** Optimization (Mathematical)\
**Tags:** question, jump\
**Created:** [July 15, 2022, 12:16am UTC](https://discourse.julialang.org/t/how-to-get-the-value-of-an-nlconstraint-in-jump/84248 "2022-07-15T00:16:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ko56](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ko56/32/2684_2.png) [@ko56](https://discourse.julialang.org/u/ko56)\
**Post date:** [July 15, 2022, 12:16am UTC](https://discourse.julialang.org/t/how-to-get-the-value-of-an-nlconstraint-in-jump/84248/1 "2022-07-15T00:16:00Z")

</div>

The `value(.)` function accepts a `ConstraintRef` argument, so you can use it to print the value of a JuMP `@constraint` after the optimization is done. But if you have a `@NLconstraint`, whose type is e.g. `NonlinearConstraintRef{ScalarShape}`, calling `value()` on it gives an error:

```julia
ERROR: MethodError: no method matching value(::NonlinearConstraintRef{ScalarShape})
Closest candidates are:
  value(::Number) at ~/.julia/packages/JuMP/Y4piv/src/variables.jl:1327
  value(::Function, ::ConstraintRef{<:AbstractModel, <:MathOptInterface.ConstraintIndex}) at ~/.julia/packages/JuMP/Y4piv/src/constraints.jl:913                                                
  value(::Function, ::VariableRef) at ~/.julia/packages/JuMP/Y4piv/src/variables.jl:1040
  ...

```

How can you get this value?

---

<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 15, 2022, 12:21am UTC](https://discourse.julialang.org/t/how-to-get-the-value-of-an-nlconstraint-in-jump/84248/2 "2022-07-15T00:21:08Z")

</div>

At the moment there’s no way to do this, but we’re currently refactoring a lot of the nonlinear interface in JuMP (I’ll talk about this at the upcoming JuMP-dev: [JuMP-dev 2022 | JuMP](https://jump.dev/meetings/juliacon2022/)), so we should be able to make this happen in the near future.

I opened an issue to track: [Add value for nonlinear constraints · Issue #3019 · jump-dev/JuMP.jl · GitHub](https://github.com/jump-dev/JuMP.jl/issues/3019)

---

<div class="post-metadata">

**Author:** ![ko56](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ko56/32/2684_2.png) [@ko56](https://discourse.julialang.org/u/ko56)\
**Post date:** [July 15, 2022, 12:35am UTC](https://discourse.julialang.org/t/how-to-get-the-value-of-an-nlconstraint-in-jump/84248/3 "2022-07-15T00:35:37Z")

</div>

Ah, thank you.

---

<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 15, 2022, 12:52am UTC](https://discourse.julialang.org/t/how-to-get-the-value-of-an-nlconstraint-in-jump/84248/4 "2022-07-15T00:52:53Z")

</div>

Here’s some of the back-story, if you’re interested:

- [Certain base functions on JuMP constraints not implemented for NLconstraints. · Issue #2355 · jump-dev/JuMP.jl · GitHub](https://github.com/jump-dev/JuMP.jl/issues/2355#issuecomment-712429883)
- [NumFOCUS signs agreement with LANL to improve nonlinear support in JuMP | JuMP](https://jump.dev/announcements/2022/02/21/lanl/)
