# JuMP.all\_constraints not listing GenericQuadExpr constraints

**URL:** <https://discourse.julialang.org/t/jump-all-constraints-not-listing-genericquadexpr-constraints/43103>\
**Category:** Optimization (Mathematical)\
**Tags:** jump\
**Created:** [July 15, 2020, 5:00am UTC](https://discourse.julialang.org/t/jump-all-constraints-not-listing-genericquadexpr-constraints/43103 "2020-07-15T05:00:09Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![adow031](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adow031/32/16403_2.png) [@adow031](https://discourse.julialang.org/u/adow031)\
**Post date:** [July 15, 2020, 5:00am UTC](https://discourse.julialang.org/t/jump-all-constraints-not-listing-genericquadexpr-constraints/43103/1 "2020-07-15T05:00:09Z")

</div>

I have a quadratic program, and was trying to list all the constraints. However, all\_constraints, wouldn’t list any of the constraints of type GenericQuadExpr. Below is a small example exhibiting the problem.

```julia
m = Model(optimizer_with_attributes(Gurobi.Optimizer, "OutputFlag" => 1))
@variable(m, x[1:2]>=0)
@objective(m, Min, x[1]+x[2])
@constraint(m, x[1]>=x[2]^2)
@constraint(m, x[2]>=3)
println(all_constraints(m))

```

The output is `Any[x[2] >= 3.0, x[1] >= 0.0, x[2] >= 0.0]`

However, if I run:

```julia
println(list_of_constraint_types(m))

```

The output is `[(GenericAffExpr{Float64,VariableRef}, MathOptInterface.GreaterThan{Float64}), (GenericQuadExpr{Float64,VariableRef}, MathOptInterface.GreaterThan{Float64}), (VariableRef, MathOptInterface.GreaterThan{Float64})]`

So I can run:

```julia
println(all_constraints(m,list_of_constraint_types(m)[2][1],list_of_constraint_types(m)[2][2])[1])

```

in order to get the quadratic constraint: `-x[2]² + x[1] >= 0.0`

Is this the intended method to extract these constraints?

Thanks,  
Tony.

---

<div class="post-metadata">

**Author:** ![tomerarnon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomerarnon/32/3170_2.png) [@tomerarnon](https://discourse.julialang.org/u/tomerarnon)\
**Post date:** [July 15, 2020, 8:53am UTC](https://discourse.julialang.org/t/jump-all-constraints-not-listing-genericquadexpr-constraints/43103/2 "2020-07-15T08:53:38Z")

</div>

What version of JuMP are you on? The signature `all_constraints(m)` does not exist in the reference (I can’t find it anyway…).  
To your point, though, yes I think that is the intended use of the `all_constraints` + `list_of_constraint_types` functions. If you want to print all of the constraints, you can do something like:

```julia
for T in list_of_constraint_types(m)
    cs = all_constraints(m, T...)
    println(T)
    println.("\t", cs)
end

```

---

<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, 2020, 1:31pm UTC](https://discourse.julialang.org/t/jump-all-constraints-not-listing-genericquadexpr-constraints/43103/3 "2020-07-15T13:31:53Z")

</div>

Tony, here’s the documentation: [Constraints · JuMP](https://jump.dev/JuMP.jl/v0.21.1/constraints/#Accessing-constraints-from-a-model-1)

---

<div class="post-metadata">

**Author:** ![adow031](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adow031/32/16403_2.png) [@adow031](https://discourse.julialang.org/u/adow031)\
**Post date:** [July 15, 2020, 9:14pm UTC](https://discourse.julialang.org/t/jump-all-constraints-not-listing-genericquadexpr-constraints/43103/4 "2020-07-15T21:14:57Z")

</div>

Thanks.

I had found that documentation, which is how I am now am using all\_constraints. However, I must have inferred the single argument usage from the way all\_variables(m) works.

I guess my concern is that all\_constraints(m) works without any warning or error (I’ve looked at the code, and I’m not sure how that is the case, since the other two arguments aren’t optional).

I think that either all\_variables(m) shouldn’t work at all (throwing an error), or it should enumerate all constraint types.

Thanks,  
Tony.

---

<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, 2020, 9:22pm UTC](https://discourse.julialang.org/t/jump-all-constraints-not-listing-genericquadexpr-constraints/43103/5 "2020-07-15T21:22:13Z")

</div>

`all_constraints(model)` doesn’t work…

```nohighlight
julia> all_constraints(model)
ERROR: MethodError: no method matching all_constraints(::Model)
Closest candidates are:
  all_constraints(::Model, ::Type{#s94} where #s94<:Union{AbstractJuMPScalar, Array{#s93,1} where #s93<:AbstractJuMPScalar}, ::Type{#s92} where #s92<:MathOptInterface.AbstractSet) at /Users/oscar/.julia/packages/JuMP/YXK4e/src/constraints.jl:852
Stacktrace:
 [1] top-level scope at REPL[230]:100

```

What does it return if it doesn’t throw an error? Do you have a reproducible example? What is the output of `] status`?

---

<div class="post-metadata">

**Author:** ![adow031](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adow031/32/16403_2.png) [@adow031](https://discourse.julialang.org/u/adow031)\
**Post date:** [July 15, 2020, 9:36pm UTC](https://discourse.julialang.org/t/jump-all-constraints-not-listing-genericquadexpr-constraints/43103/6 "2020-07-15T21:36:54Z")

</div>

The example I put in my question is what I get: an Any array of all the linear constraints.

My version of JuMP was v0.21.2, but I just updated to JuMP v0.21.3, and it’s doing the same thing. (I am using Julia 1.3, however.)

---

<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, 2020, 9:42pm UTC](https://discourse.julialang.org/t/jump-all-constraints-not-listing-genericquadexpr-constraints/43103/7 "2020-07-15T21:42:10Z")

</div>

What is `@which all_constraints(m)`?

I’ll send you an email.

---

<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, 2020, 10:26pm UTC](https://discourse.julialang.org/t/jump-all-constraints-not-listing-genericquadexpr-constraints/43103/8 "2020-07-15T22:26:26Z")

</div>

Tony was using a package which defined `JuMP.all_constraints(::Model)`, thus breaking the rule: [Style Guide · The Julia Language](https://docs.julialang.org/en/v1/manual/style-guide/index.html#Avoid-type-piracy-1)

---

<div class="post-metadata">

**Author:** ![adow031](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adow031/32/16403_2.png) [@adow031](https://discourse.julialang.org/u/adow031)\
**Post date:** [July 15, 2020, 11:16pm UTC](https://discourse.julialang.org/t/jump-all-constraints-not-listing-genericquadexpr-constraints/43103/9 "2020-07-15T23:16:35Z")

</div>

Apologies all.

I had imported a package that clearly violated all the Julia rules.

Tony.
