Julia Vscode new version issue with JuMP

I’m having a problem with SparsesAxisArray JuMP on Julia for Vscode.
When I use @variable with this condition below, it reproduces an error

using Gurobi, JuMP

model = Model(Gurobi.Optimizer) 

n = 5
V = 1:n
V0= 1:n+1

@variable(model, x[i in V0, j in V; i != j], Bin) #this not work

Defines: JuMP.Containers.SparseAxisArray{VariableRef,2,Tuple{Int64,Int64}} with 25 entries:
but in the end, reproduces:

Internal Error: ERROR: MethodError: no method matching size(::JuMP.Containers.SparseAxisArray{VariableRef,2,Tuple{Int64,Int64}})
Closest candidates are:
  size(::AbstractArray{T,N}, ::Any) where {T, N} at abstractarray.jl:38
  size(::BitArray{1}) at bitarray.jl:99
  size(::BitArray{1}, ::Integer) at bitarray.jl:103

I figured out that if i return to previous version 0.15.40 of Julia package on Vscode, this code works perfectly. Any suggestions?

Thanks in advance!

I’d argue this is a bug in JuMP, because

julia> @variable(model, x[i in V0, j in V; i != j], Bin) isa AbstractArray

and size is part of the AbstractArray interface.

That said, showing those internal errors makes the REPL kinda unusable, so we’ll stop doing that in the extension.

1 Like

There is an open issue for size: https://github.com/jump-dev/JuMP.jl/issues/2117

We need to spend some time re-thinking the functionality of the SparseAxisArray, because it is partially an array, and partially a dictionary.

1 Like

I don’t understand where the error comes from. Why do you need to call size in your example ?

@pfitzseb We could implement size and axis for SparseAxisArray but that would require a little bit of bookkeeping and we have no convincing use case yet. Accessing it with the axis would not be a good idea anyway since it is sparse hence one should not go through the cartesian product of the axis.

The error comes from VSCode trying to display that object as an AbstractArray by showing its contents in a tree view like this:

Also see https://github.com/julia-vscode/julia-vscode/issues/1491.