Unable to use Types from Graphs.jl and GridGraphs.jl in Jupyter Notebook

Hello.
I am pretty new to Julia and attempting to replicate a tutorial for InferOpt.jl (Tutorial in question is linked here: Tutorial · InferOpt.jl).

I have already installed the appropriate packages for using Julia in a Jupyter Notebook and began testing it out, everything seems to have gone well, but then I encountered a problem: using Types from Graphs.jl and GridGraphs.jl always gives me an error,

UndefVarError: AbstractGridGraph not defined

Stacktrace:
 [1] getproperty(x::Module, f::Symbol)
   @ Base .\Base.jl:31
 [2] top-level scope
   @ In[26]:4
 [3] eval
   @ .\boot.jl:368 [inlined]
 [4] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
   @ Base .\loading.jl:1428

These are the cells I have ran, in order:

using Pkg; Pkg.add(["Flux", "Graphs", "GridGraphs", "InferOpt", "LinearAlgebra",
        "ProgressMeter", "Random", "Statistics", "Test", "UnicodePlots"])
using Flux
using Graphs
using InferOpt
using LinearAlgebra
using ProgressMeter
using Random
using Statistics
using Test
using UnicodePlots
using GridGraphs

Random.seed!(63);
h, w = 50, 100
g = AbstractGridGraph(rand(h, w));

The error shows up after the third cell is ran. I have also attempted to run the code above in VS Code and received the same error. Nonetheless, when I run something like the following code:

nb_features = 5

true_encoder = Chain(Dense(nb_features, 1), z -> dropdims(z; dims=1));

I receive absolutely no errors. What could be going wrong there?

Thank you for any help!

Is AbstractGridGraphs exported by GridGraphs.jl? Perhaps try without Abstract…?

I’ve tried three separate versions to attempt and probe into the problem:
These two give similar errors:
g = AbstractGridGraph(rand(h, w));
g = GridGraphs.AbstractGridGraph();

And then I tried
g = Graphs.SimpleGraphs.AbstractSimpleGraph();
which give me the error:

MethodError: no method matching Graphs.SimpleGraphs.AbstractSimpleGraph()

Stacktrace:
 [1] top-level scope
   @ In[28]:3
 [2] eval
   @ .\boot.jl:368 [inlined]
 [3] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
   @ Base .\loading.jl:1428

I have also attempted to do it without Abstract but ended up with a similar error to the third attempt provided above.

I think there are some teething problems with this area of Julia, since GridGraphs.jl is new and still in pre-1.0 state.

This works here:

h = 12
w = 15
T = Int32
R = Float32
weights_matrix = rand(R, h, w)
g = GridGraph{T}(weights_matrix)
Weights matrix: Matrix{Float32}
Active matrix: FillArrays.Trues{2, Tuple{Base.OneTo{Int64},
Base.OneTo{Int64}}}
Directions: GridDirection[NW, W, SW, N, C, S, NE, E, SE]
Diagonal through corner: false

I think you’d be better off opening an issue at GridGraphs.jl. I’m not sure how much bandwidth the author currently has, though.

1 Like

Thanks for the help. Unfortunately that doesn’t seem to work for me either… but I will take by your advice and open an issue on the GitHub repository.

Don’t forget to report the current output of Pkg.status() / ] status for your current project.

For example, I’m using the following packages in my Julia 1.8 Graphs project:

  [86223c79] Graphs v1.7.4
  [dd2b58c7] GridGraphs v0.8.0
  [cd156443] Karnak v0.3.0
  [46757867] NetworkLayout v0.4.4
  [47aef6b3] SimpleWeightedGraphs v1.2.1
1 Like

I may be missing something here, but that part of the tutorial says

g = AcyclicGridGraph(rand(h, w));

i.e. AcyclicGridGraph not AbstractGridGraph.

It seems like all packages have loaded properly:

  [86223c79] Graphs v1.7.4
  [dd2b58c7] GridGraphs v0.8.0
  [7073ff75] IJulia v1.23.3
  [4846b161] InferOpt v0.3.1
  [92933f4c] ProgressMeter v1.7.2
  [b8865327] UnicodePlots v3.1.3
  [37e2e46d] LinearAlgebra
  [9a3f8284] Random
  [10745b16] Statistics
  [8dfed614] Test

I added it to the issue as well.

1 Like

That’s correct. Nonetheless, both of them are Types from GridGraphs.jl and I have tried both, obtaining similar results.

Ah, it seems like both of them were types in GridGraphs.jl, but not anymore. AbstractGridGraph and AcyclicGridGraph were both removed before the current stable version v0.8 that you have installed.

In v0.8, AbstractGridGraph became just GridGraph, while AcyclicGridGraphs are either FullAcyclicGridGraphs or SparseAcyclicGridGraphs. For this tutorial, at a glance, it seems like a FullAcyclicGridGraph is what’s needed, so

g = FullAcyclicGridGraph(rand(h, w));

should be the equivalent.

Note that the interface is changing again in the future (v0.9 and above), instead being specified via a directions argument to GridGraph itself.

g = GridGraph(rand(h, w), directions = QUEEN_ACYCLIC_DIRECTIONS);

should be the future equivalent of this.

2 Likes

Thank you! That worked. I will keep the changes for v0.9 in mind as well.

Sorry about that, I will update the documentation soon!

1 Like

Fixed!

https://gdalle.github.io/GridGraphs.jl/v0.9/

1 Like