# Issue with node\_count() - type of return

**URL:** <https://discourse.julialang.org/t/issue-with-node-count-type-of-return/74872>\
**Category:** Optimization (Mathematical)\
**Tags:** question, jump\
**Created:** [January 19, 2022, 3:56pm UTC](https://discourse.julialang.org/t/issue-with-node-count-type-of-return/74872 "2022-01-19T15:56:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![arkanver](https://avatars.discourse-cdn.com/v4/letter/a/dfb087/32.png) [@arkanver](https://discourse.julialang.org/u/arkanver)\
**Post date:** [January 19, 2022, 3:56pm UTC](https://discourse.julialang.org/t/issue-with-node-count-type-of-return/74872/1 "2022-01-19T15:56:36Z")

</div>

Hello all,  
I’ve run into an issue with JuMP function node\_count(). This function seems to check the type of value returned by the solver and expects it to be Int64, however with some solvers this isn’t the case. For example Gurobi gives it as a Float64, and Cbc as an Int32. I give below a small example of a simple knapsack problem which should reproduce the error.

```julia
using JuMP
using Gurobi
m = Model(Gurobi.Optimizer)
@variable(m, x[1:4], Bin)
@constraint(m, 3*x[1] + 4*x[2] + 6*x[3] + 5*x[4] <= 8)
@objective(m, Max, 2*x[1] + 3*x[2] + x[3] + 4*x[4])
optimize!(m)
node_count(m)

```

This should yield the following error :

```julia
ERROR: TypeError: in typeassert, expected Int64, got a value of type Float64
Stacktrace:
 [1] get(model::MathOptInterface.Utilities.CachingOptimizer{MathOptInterface.Bridges.LazyBridgeOptimizer{Gurobi.Optimizer}, MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}}, attr::MathOptInterface.NodeCount)
   @ MathOptInterface.Utilities C:\Users\Verchere\.julia\packages\MathOptInterface\QxT5e\src\Utilities\cachingoptimizer.jl:803
 [2] _moi_get_result(model::MathOptInterface.Utilities.CachingOptimizer{MathOptInterface.Bridges.LazyBridgeOptimizer{Gurobi.Optimizer}, MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}}, args::MathOptInterface.NodeCount)
   @ JuMP C:\Users\Verchere\.julia\packages\JuMP\lnUbA\src\JuMP.jl:1226
 [3] get(model::Model, attr::MathOptInterface.NodeCount)
   @ JuMP C:\Users\Verchere\.julia\packages\JuMP\lnUbA\src\JuMP.jl:1251
 [4] node_count(model::Model)
   @ JuMP C:\Users\Verchere\.julia\packages\JuMP\lnUbA\src\JuMP.jl:1071
 [5] top-level scope
   @ none:1

```

As far as I know I am up to date in terms of versions - Julia 1.7.1, JuMP 0.22.2, Gurobi.jl 0.10.1.  
I am not very familiar with the architecture and implementation of JuMP and MOI, but if it helps please know that using MOI.get(m,MOI.NodeCount()) yields the same error.

Thank you for reading !

---

<div class="post-metadata">

**Author:** ![goerch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerch/32/29122_2.png) [@goerch](https://discourse.julialang.org/u/goerch)\
**Post date:** [January 20, 2022, 6:02am UTC](https://discourse.julialang.org/t/issue-with-node-count-type-of-return/74872/2 "2022-01-20T06:02:10Z")

</div>

I see two questions here:

- why should the node count be a floating number?
- does the type assertion also fire for ‘Int32’ or other ‘Integer’ types?

Both seem to be issues with ‘Gurobi’ and ‘MathOptInterface’ respectively?

---

<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:** [January 20, 2022, 6:08am UTC](https://discourse.julialang.org/t/issue-with-node-count-type-of-return/74872/3 "2022-01-20T06:08:28Z")

</div>

I think this is a bug in Gurobi.jl. MOI v0.10 introduced a breaking change by making the return types explicit. Looks like we didn’t update Gurobi.jl appropriately.

---

<div class="post-metadata">

**Author:** ![arkanver](https://avatars.discourse-cdn.com/v4/letter/a/dfb087/32.png) [@arkanver](https://discourse.julialang.org/u/arkanver)\
**Post date:** [January 21, 2022, 2:31pm UTC](https://discourse.julialang.org/t/issue-with-node-count-type-of-return/74872/4 "2022-01-21T14:31:17Z")

</div>

There’s no reason it should be a float, or at least none that come to mind, but that seems to be what is returned by Gurobi.  
The type assertion also happens for other Int types, as I had the exact same mistake using Cbc instead (Cbc returns an Int32)

---

<div class="post-metadata">

**Author:** ![arkanver](https://avatars.discourse-cdn.com/v4/letter/a/dfb087/32.png) [@arkanver](https://discourse.julialang.org/u/arkanver)\
**Post date:** [January 24, 2022, 2:09pm UTC](https://discourse.julialang.org/t/issue-with-node-count-type-of-return/74872/5 "2022-01-24T14:09:36Z")

</div>

As a bit of an update, this is indeed due to MOI v0.9 → v0.10. For now, I suppose I’ll work with JuMP v0.21.10 and MOI v0.9.22. Looking forward to solving this little issue at some point !
