Issue with node_count() - type of return

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.

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])

This should yield the following error :

ERROR: TypeError: in typeassert, expected Int64, got a value of type Float64
 [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 !

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?

1 Like

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.

1 Like

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)

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 !