Skip to content

Commit ffae56a

Browse files
fix some doctest
1 parent 77bc14a commit ffae56a

File tree

10 files changed

+54
-71
lines changed

10 files changed

+54
-71
lines changed

GNNGraphs/docs/make.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ mathengine = MathJax3(Dict(:loader => Dict("load" => ["[tex]/require", "[tex]/ma
1919

2020
makedocs(;
2121
modules = [GNNGraphs],
22-
doctest = false, # TODO enable doctest
22+
doctest = true, # TODO enable doctest
2323
format = Documenter.HTML(; mathengine,
2424
prettyurls = get(ENV, "CI", nothing) == "true",
2525
assets = [],
@@ -30,9 +30,9 @@ makedocs(;
3030

3131
"Guides" => [
3232
"Graphs" => [
33-
"guides/gnngraph.md",
34-
"guides/heterograph.md",
35-
"guides/temporalgraph.md"
33+
"guides/gnngraph.md",
34+
"guides/heterograph.md",
35+
"guides/temporalgraph.md"
3636
],
3737
"Datasets" => "guides/datasets.md",
3838
],

GNNGraphs/docs/src/guides/gnngraph.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,10 @@ that contains the total number of the original nodes
155155
and where the original graphs are disjoint subgraphs.
156156

157157
```julia
158-
using Flux
159-
using Flux: DataLoader
158+
using MLUtils
160159

161160
data = [rand_graph(10, 30, ndata=rand(Float32, 3, 10)) for _ in 1:160]
162-
gall = Flux.batch(data)
161+
gall = MLUtils.batch(data)
163162

164163
# gall is a GNNGraph containing many graphs
165164
@assert gall.num_graphs == 160
@@ -172,7 +171,7 @@ g23 = getgraph(gall, 2:3)
172171
@assert g23.num_nodes == 20 # 10 nodes x 2 graphs
173172
@assert g23.num_edges == 60 # 30 undirected edges X 2 graphs
174173

175-
# We can pass a GNNGraph to Flux's DataLoader
174+
# We can pass a GNNGraph to MLUtils' DataLoader
176175
train_loader = DataLoader(gall, batchsize=16, shuffle=true)
177176

178177
for g in train_loader
@@ -193,7 +192,7 @@ an option for mini-batch iteration, the recommended way for better performance i
193192
to pass an array of graphs directly and set the `collate` option to `true`:
194193

195194
```julia
196-
using Flux: DataLoader
195+
using MLUtils: DataLoader
197196

198197
data = [rand_graph(10, 30, ndata=rand(Float32, 3, 10)) for _ in 1:320]
199198

@@ -220,7 +219,7 @@ g′ = add_edges(g, [1, 2], [2, 3]) # add edges 1->2 and 2->3
220219
Move a `GNNGraph` to a CUDA device using `Flux.gpu` method.
221220

222221
```julia
223-
using CUDA, Flux
222+
using Flux, CUDA # or using Metal or using AMDGPU
224223

225224
g_gpu = g |> Flux.gpu
226225
```

GNNGraphs/docs/src/guides/heterograph.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ the type [`GNNHeteroGraph`](@ref).
1313
## Creating a Heterograph
1414

1515
A heterograph can be created empty or by passing pairs `edge_type => data` to the constructor.
16-
```jldoctest
16+
```jldoctest hetero
17+
julia> using GNNGraphs
18+
1719
julia> g = GNNHeteroGraph()
1820
GNNHeteroGraph:
1921
num_nodes: Dict()
@@ -31,7 +33,7 @@ GNNHeteroGraph:
3133
num_edges: Dict((:user, :rate, :movie) => 4)
3234
```
3335
New relations, possibly with new node types, can be added with the function [`add_edges`](@ref).
34-
```jldoctest
36+
```jldoctest hetero
3537
julia> g = add_edges(g, (:user, :like, :actor) => ([1,2,3,3,3], [3,5,1,9,4]))
3638
GNNHeteroGraph:
3739
num_nodes: Dict(:actor => 9, :movie => 13, :user => 3)
@@ -40,7 +42,7 @@ GNNHeteroGraph:
4042
See [`rand_heterograph`](@ref), [`rand_bipartite_heterograph`](@ref)
4143
for generating random heterographs.
4244

43-
```jldoctest
45+
```jldoctest hetero
4446
julia> g = rand_bipartite_heterograph((10, 15), 20)
4547
GNNHeteroGraph:
4648
num_nodes: Dict(:A => 10, :B => 15)
@@ -50,7 +52,7 @@ GNNHeteroGraph:
5052
## Basic Queries
5153

5254
Basic queries are similar to those for homogeneous graphs:
53-
```jldoctest
55+
```jldoctest hetero
5456
julia> g = GNNHeteroGraph((:user, :rate, :movie) => ([1,1,2,3], [7,13,5,7]))
5557
GNNHeteroGraph:
5658
num_nodes: Dict(:movie => 13, :user => 3)
@@ -84,7 +86,7 @@ julia> g.etypes
8486
## Data Features
8587

8688
Node, edge, and graph features can be added at construction time or later using:
87-
```jldoctest
89+
```jldoctest hetero
8890
# equivalent to g.ndata[:user][:x] = ...
8991
julia> g[:user].x = rand(Float32, 64, 3);
9092
@@ -106,10 +108,10 @@ GNNHeteroGraph:
106108

107109
## Batching
108110
Similarly to graphs, also heterographs can be batched together.
109-
```jldoctest
111+
```jldoctest hetero
110112
julia> gs = [rand_bipartite_heterograph((5, 10), 20) for _ in 1:32];
111113
112-
julia> Flux.batch(gs)
114+
julia> MLUtils.batch(gs)
113115
GNNHeteroGraph:
114116
num_nodes: Dict(:A => 160, :B => 320)
115117
num_edges: Dict((:A, :to, :B) => 640, (:B, :to, :A) => 640)
@@ -118,7 +120,7 @@ GNNHeteroGraph:
118120
Batching is automatically performed by the [`DataLoader`](https://fluxml.ai/Flux.jl/stable/data/mlutils/#MLUtils.DataLoader) iterator
119121
when the `collate` option is set to `true`.
120122

121-
```jldoctest
123+
```jldoctest hetero
122124
using Flux: DataLoader
123125
124126
data = [rand_bipartite_heterograph((5, 10), 20,

GNNGraphs/docs/src/guides/temporalgraph.md

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ Temporal Graphs are graphs with time varying topologies and features. In GNNGra
66

77
A temporal graph can be created by passing a list of snapshots to the constructor. Each snapshot is a [`GNNGraph`](@ref).
88

9-
```jldoctest
9+
```jldoctest temporal
10+
julia> using GNNGraphs
11+
1012
julia> snapshots = [rand_graph(10,20) for i in 1:5];
1113
1214
julia> tg = TemporalSnapshotsGNNGraph(snapshots)
@@ -18,14 +20,14 @@ TemporalSnapshotsGNNGraph:
1820

1921
A new temporal graph can be created by adding or removing snapshots to an existing temporal graph.
2022

21-
```jldoctest
23+
```jldoctest temporal
2224
julia> new_tg = add_snapshot(tg, 3, rand_graph(10, 16)) # add a new snapshot at time 3
2325
TemporalSnapshotsGNNGraph:
2426
num_nodes: [10, 10, 10, 10, 10, 10]
2527
num_edges: [20, 20, 16, 20, 20, 20]
2628
num_snapshots: 6
2729
```
28-
```jldoctest
30+
```jldoctest temporal
2931
julia> snapshots = [rand_graph(10,20), rand_graph(10,14), rand_graph(10,22)];
3032
3133
julia> tg = TemporalSnapshotsGNNGraph(snapshots)
@@ -43,7 +45,7 @@ TemporalSnapshotsGNNGraph:
4345

4446
See [`rand_temporal_radius_graph`](@ref) and [`rand_temporal_hyperbolic_graph`](@ref) for generating random temporal graphs.
4547

46-
```jldoctest
48+
```jldoctest temporal
4749
julia> tg = rand_temporal_radius_graph(10, 3, 0.1, 0.5)
4850
TemporalSnapshotsGNNGraph:
4951
num_nodes: [10, 10, 10]
@@ -54,7 +56,7 @@ TemporalSnapshotsGNNGraph:
5456
## Basic Queries
5557

5658
Basic queries are similar to those for [`GNNGraph`](@ref)s:
57-
```jldoctest
59+
```jldoctest temporal
5860
julia> snapshots = [rand_graph(10,20), rand_graph(10,14), rand_graph(10,22)];
5961
6062
julia> tg = TemporalSnapshotsGNNGraph(snapshots)
@@ -94,7 +96,7 @@ GNNGraph:
9496
A temporal graph can store global feature for the entire time series in the `tgdata` filed.
9597
Also, each snapshot can store node, edge, and graph features in the `ndata`, `edata`, and `gdata` fields, respectively.
9698

97-
```jldoctest
99+
```jldoctest temporal
98100
julia> snapshots = [rand_graph(10,20; ndata = rand(3,10)), rand_graph(10,14; ndata = rand(4,10)), rand_graph(10,22; ndata = rand(5,10))]; # node features at construction time
99101
100102
julia> tg = TemporalSnapshotsGNNGraph(snapshots);
@@ -124,22 +126,4 @@ julia> [g.x for g in tg.snapshots]; # same vector as above, now accessing
124126
# the x feature directly from the snapshots
125127
```
126128

127-
## Graph convolutions on TemporalSnapshotsGNNGraph
128-
129-
A graph convolutional layer can be applied to each snapshot independently, in the next example we apply a `GINConv` layer to each snapshot of a `TemporalSnapshotsGNNGraph`.
130-
131-
```jldoctest
132-
julia> using GNNGraphs, Flux
133-
134-
julia> snapshots = [rand_graph(10, 20; ndata = rand(3, 10)), rand_graph(10, 14; ndata = rand(3, 10))];
135-
136-
julia> tg = TemporalSnapshotsGNNGraph(snapshots);
137-
138-
julia> m = GINConv(Dense(3 => 1), 0.4);
139-
140-
julia> output = m(tg, tg.ndata.x);
141-
142-
julia> size(output[1])
143-
(1, 10)
144-
```
145129

GNNGraphs/src/datastore.jl

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ DataStore() with 2 elements:
3737
The `DataStore` has an interface similar to both dictionaries and named tuples.
3838
Arrays can be accessed and added using either the indexing or the property syntax:
3939
40-
```jldoctest
40+
```jldoctest datastore
4141
julia> ds = DataStore(x = ones(Float32, 2, 3), y = zeros(Float32, 3))
4242
DataStore() with 2 elements:
4343
y = 3-element Vector{Float32}
@@ -49,20 +49,21 @@ julia> ds.x # same as `ds[:x]`
4949
1.0 1.0 1.0
5050
5151
julia> ds.z = zeros(Float32, 3) # Add new feature array `z`. Same as `ds[:z] = rand(Float32, 3)`
52-
3-element Vector{Float64}:
53-
0.0
54-
0.0
55-
0.0
52+
3-element Vector{Float32}:
53+
0.0
54+
0.0
55+
0.0
5656
```
5757
5858
The `DataStore` can be iterated over, and the keys and values can be accessed
5959
using `keys(ds)` and `values(ds)`. `map(f, ds)` applies the function `f`
6060
to each feature array:
6161
62-
```jldoctest
63-
julia> ds = DataStore(a = zeros(2), b = zeros(2));
64-
62+
```jldoctest datastore
6563
julia> ds2 = map(x -> x .+ 1, ds)
64+
DataStore() with 2 elements:
65+
a = 2-element Vector{Float64}
66+
b = 2-element Vector{Float64}
6667
6768
julia> ds2.a
6869
2-element Vector{Float64}:

GNNGraphs/src/gnngraph.jl

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ functionality from that library.
6666
# Examples
6767
6868
```julia
69-
using GraphNeuralNetworks
69+
using GNNGraphs
7070
7171
# Construct from adjacency list representation
7272
data = [[2,3], [1,4,5], [1], [2,5], [2,4]]
@@ -101,11 +101,8 @@ g.edata.e # or just g.e
101101
# Both source and target are vectors of length num_edges
102102
source, target = edge_index(g)
103103
```
104-
A `GNNGraph` can be sent to the GPU using e.g. Flux's `gpu` function:
105-
```
106-
# Send to gpu
107-
using Flux, CUDA
108-
g = g |> Flux.gpu
104+
A `GNNGraph` can be sent to the GPU, for example by using Flux.jl's `gpu` function
105+
or MLDataDevices.jl's utilities.
109106
```
110107
"""
111108
struct GNNGraph{T <: Union{COO_T, ADJMAT_T}} <: AbstractGNNGraph{T}

GNNGraphs/src/gnnheterograph.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ It is similar to [`GNNGraph`](@ref) but nodes and edges are of different types.
3737
# Examples
3838
3939
```julia
40-
julia> using GraphNeuralNetworks
40+
julia> using GNNGraphs
4141
4242
julia> nA, nB = 10, 20;
4343

GNNGraphs/src/mldatasets.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Convert a graph dataset from the package MLDatasets.jl into one or many [`GNNGra
88
# Examples
99
1010
```jldoctest
11-
julia> using MLDatasets, GraphNeuralNetworks
11+
julia> using MLDatasets, GNNGraphs
1212
1313
julia> mldataset2gnngraph(Cora())
1414
GNNGraph:

GNNGraphs/src/temporalsnapshotsgnngraph.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ The features can be passed at construction time or added later.
1414
# Examples
1515
1616
```julia
17-
julia> using GraphNeuralNetworks
17+
julia> using GNNGraphs
1818
1919
julia> snapshots = [rand_graph(10,20) for i in 1:5];
2020
@@ -78,7 +78,7 @@ Return a `TemporalSnapshotsGNNGraph` created starting from `tg` by adding the sn
7878
# Examples
7979
8080
```jldoctest
81-
julia> using GraphNeuralNetworks
81+
julia> using GNNGraphs
8282
8383
julia> snapshots = [rand_graph(10, 20) for i in 1:5];
8484
@@ -138,7 +138,7 @@ Return a [`TemporalSnapshotsGNNGraph`](@ref) created starting from `tg` by remov
138138
# Examples
139139
140140
```jldoctest
141-
julia> using GraphNeuralNetworks
141+
julia> using GNNGraphs
142142
143143
julia> snapshots = [rand_graph(10,20), rand_graph(10,14), rand_graph(10,22)];
144144

GNNGraphs/src/transform.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ A new GNNGraph with the specified edges removed.
170170
171171
# Example
172172
```julia
173-
julia> using GraphNeuralNetworks
173+
julia> using GNNGraphs
174174
175175
# Construct a GNNGraph
176176
julia> g = GNNGraph([1, 1, 2, 2, 3], [2, 3, 1, 3, 1])
@@ -275,7 +275,7 @@ A new GNNGraph with the specified nodes and all edges associated with these node
275275
276276
# Example
277277
```julia
278-
using GraphNeuralNetworks
278+
using GNNGraphs
279279
280280
g = GNNGraph([1, 1, 2, 2, 3], [2, 3, 1, 3, 1])
281281
@@ -621,17 +621,17 @@ julia> e = [10.0, 20.0, 30.0, 40.0, 50.0];
621621
622622
julia> g = GNNGraph(s, t, w, edata = e)
623623
GNNGraph:
624-
num_nodes = 4
625-
num_edges = 5
626-
edata:
627-
e => (5,)
624+
num_nodes: 4
625+
num_edges: 5
626+
edata:
627+
e = 5-element Vector{Float64}
628628
629629
julia> g2 = to_bidirected(g)
630630
GNNGraph:
631-
num_nodes = 4
632-
num_edges = 7
633-
edata:
634-
e => (7,)
631+
num_nodes: 4
632+
num_edges: 7
633+
edata:
634+
e = 7-element Vector{Float64}
635635
636636
julia> edge_index(g2)
637637
([1, 2, 2, 3, 3, 4, 4], [2, 1, 3, 2, 4, 3, 4])

0 commit comments

Comments
 (0)