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

**URL:** <https://discourse.julialang.org/t/unable-to-use-types-from-graphs-jl-and-gridgraphs-jl-in-jupyter-notebook/88913>\
**Category:** Graphs\
**Tags:** package, type, graphs\
**Created:** [October 18, 2022, 1:36pm UTC](https://discourse.julialang.org/t/unable-to-use-types-from-graphs-jl-and-gridgraphs-jl-in-jupyter-notebook/88913 "2022-10-18T13:36:57Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![MarawanEmara](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marawanemara/32/43665_2.png) [@MarawanEmara](https://discourse.julialang.org/u/MarawanEmara)\
**Post date:** [October 18, 2022, 1:36pm UTC](https://discourse.julialang.org/t/unable-to-use-types-from-graphs-jl-and-gridgraphs-jl-in-jupyter-notebook/88913/1 "2022-10-18T13:36:57Z")

</div>

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](https://axelparmentier.github.io/InferOpt.jl/dev/tutorial/)).

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,

```julia
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:

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

```

```julia
using Flux
using Graphs
using InferOpt
using LinearAlgebra
using ProgressMeter
using Random
using Statistics
using Test
using UnicodePlots
using GridGraphs

Random.seed!(63);

```

```julia
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:

```julia
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!

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [October 18, 2022, 1:58pm UTC](https://discourse.julialang.org/t/unable-to-use-types-from-graphs-jl-and-gridgraphs-jl-in-jupyter-notebook/88913/2 "2022-10-18T13:58:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![MarawanEmara](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marawanemara/32/43665_2.png) [@MarawanEmara](https://discourse.julialang.org/u/MarawanEmara)\
**Post date:** [October 18, 2022, 2:09pm UTC](https://discourse.julialang.org/t/unable-to-use-types-from-graphs-jl-and-gridgraphs-jl-in-jupyter-notebook/88913/3 "2022-10-18T14:09:51Z")

</div>

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:

```julia
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.

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [October 18, 2022, 2:15pm UTC](https://discourse.julialang.org/t/unable-to-use-types-from-graphs-jl-and-gridgraphs-jl-in-jupyter-notebook/88913/4 "2022-10-18T14:15:23Z")

</div>

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:

```julia
h = 12
w = 15
T = Int32
R = Float32
weights_matrix = rand(R, h, w)
g = GridGraph{T}(weights_matrix)

```

```julia
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](https://github.com/gdalle/GridGraphs.jl). I’m not sure how much bandwidth the author currently has, though.

---

<div class="post-metadata">

**Author:** ![MarawanEmara](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marawanemara/32/43665_2.png) [@MarawanEmara](https://discourse.julialang.org/u/MarawanEmara)\
**Post date:** [October 18, 2022, 2:23pm UTC](https://discourse.julialang.org/t/unable-to-use-types-from-graphs-jl-and-gridgraphs-jl-in-jupyter-notebook/88913/5 "2022-10-18T14:23:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [October 18, 2022, 2:28pm UTC](https://discourse.julialang.org/t/unable-to-use-types-from-graphs-jl-and-gridgraphs-jl-in-jupyter-notebook/88913/6 "2022-10-18T14:28:15Z")

</div>

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:

```nohighlight
  [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

```

---

<div class="post-metadata">

**Author:** ![digital\_carver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/digital_carver/32/33818_2.png) [@digital\_carver](https://discourse.julialang.org/u/digital_carver)\
**Post date:** [October 18, 2022, 2:29pm UTC](https://discourse.julialang.org/t/unable-to-use-types-from-graphs-jl-and-gridgraphs-jl-in-jupyter-notebook/88913/7 "2022-10-18T14:29:48Z")

</div>

> [@MarawanEmara](#):
>
> ```julia
> h, w = 50, 100
> g = AbstractGridGraph(rand(h, w));
> 
> ```

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

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

```

i.e. `AcyclicGridGraph` not `AbstractGridGraph`.

---

<div class="post-metadata">

**Author:** ![MarawanEmara](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marawanemara/32/43665_2.png) [@MarawanEmara](https://discourse.julialang.org/u/MarawanEmara)\
**Post date:** [October 18, 2022, 2:31pm UTC](https://discourse.julialang.org/t/unable-to-use-types-from-graphs-jl-and-gridgraphs-jl-in-jupyter-notebook/88913/8 "2022-10-18T14:31:19Z")

</div>

It seems like all packages have loaded properly:

```julia
  [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.

---

<div class="post-metadata">

**Author:** ![MarawanEmara](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marawanemara/32/43665_2.png) [@MarawanEmara](https://discourse.julialang.org/u/MarawanEmara)\
**Post date:** [October 18, 2022, 2:32pm UTC](https://discourse.julialang.org/t/unable-to-use-types-from-graphs-jl-and-gridgraphs-jl-in-jupyter-notebook/88913/9 "2022-10-18T14:32:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![digital\_carver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/digital_carver/32/33818_2.png) [@digital\_carver](https://discourse.julialang.org/u/digital_carver)\
**Post date:** [October 18, 2022, 2:59pm UTC](https://discourse.julialang.org/t/unable-to-use-types-from-graphs-jl-and-gridgraphs-jl-in-jupyter-notebook/88913/10 "2022-10-18T14:59:28Z")

</div>

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 `AcyclicGridGraph`s are either `FullAcyclicGridGraph`s or `SparseAcyclicGridGraph`s. For this tutorial, at a glance, it seems like a `FullAcyclicGridGraph` is what’s needed, so

```julia
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.

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

```

should be the future equivalent of this.

---

<div class="post-metadata">

**Author:** ![MarawanEmara](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marawanemara/32/43665_2.png) [@MarawanEmara](https://discourse.julialang.org/u/MarawanEmara)\
**Post date:** [October 18, 2022, 3:31pm UTC](https://discourse.julialang.org/t/unable-to-use-types-from-graphs-jl-and-gridgraphs-jl-in-jupyter-notebook/88913/11 "2022-10-18T15:31:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [October 19, 2022, 11:21am UTC](https://discourse.julialang.org/t/unable-to-use-types-from-graphs-jl-and-gridgraphs-jl-in-jupyter-notebook/88913/12 "2022-10-19T11:21:07Z")

</div>

Sorry about that, I will update the documentation soon!

---

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [November 19, 2022, 5:47pm UTC](https://discourse.julialang.org/t/unable-to-use-types-from-graphs-jl-and-gridgraphs-jl-in-jupyter-notebook/88913/13 "2022-11-19T17:47:03Z")

</div>

Fixed!

[https://gdalle.github.io/GridGraphs.jl/v0.9/](https://gdalle.github.io/GridGraphs.jl/v0.9/)
