From 837a6e95475e480780ae5686491582101ba499e0 Mon Sep 17 00:00:00 2001 From: Carlo Lucibello Date: Fri, 25 Oct 2024 16:52:30 +0200 Subject: [PATCH 1/2] fix vector DataStore (#505) * remove vector access to datastore * fix * deprecations --- GNNGraphs/src/GNNGraphs.jl | 2 ++ GNNGraphs/src/datastore.jl | 10 +--------- GNNGraphs/src/deprecations.jl | 13 +++++++++++++ GNNGraphs/test/datastore.jl | 8 +++----- GraphNeuralNetworks/docs/src/temporalgraph.md | 14 ++++++++------ 5 files changed, 27 insertions(+), 20 deletions(-) create mode 100644 GNNGraphs/src/deprecations.jl diff --git a/GNNGraphs/src/GNNGraphs.jl b/GNNGraphs/src/GNNGraphs.jl index 055ea2789..cd1848b28 100644 --- a/GNNGraphs/src/GNNGraphs.jl +++ b/GNNGraphs/src/GNNGraphs.jl @@ -111,4 +111,6 @@ include("gatherscatter.jl") include("mldatasets.jl") export mldataset2gnngraph +include("deprecations.jl") + end #module diff --git a/GNNGraphs/src/datastore.jl b/GNNGraphs/src/datastore.jl index 2afef8970..9581e266d 100644 --- a/GNNGraphs/src/datastore.jl +++ b/GNNGraphs/src/datastore.jl @@ -107,15 +107,7 @@ function Base.getproperty(ds::DataStore, s::Symbol) end end -function Base.getproperty(vds::Vector{DataStore}, s::Symbol) - if s === :_n - return [getn(ds) for ds in vds] - elseif s === :_data - return [getdata(ds) for ds in vds] - else - return [getdata(ds)[s] for ds in vds] - end -end + function Base.setproperty!(ds::DataStore, s::Symbol, x) @assert s != :_n "cannot set _n directly" diff --git a/GNNGraphs/src/deprecations.jl b/GNNGraphs/src/deprecations.jl new file mode 100644 index 000000000..d6a8e1797 --- /dev/null +++ b/GNNGraphs/src/deprecations.jl @@ -0,0 +1,13 @@ +## Deprecated in V0.6 + +function Base.getproperty(vds::Vector{DataStore}, s::Symbol) + if s ∈ (:ref, :size) # these are arrays fields in V0.11 + return getfield(vds, s) + elseif s === :_n + return [getn(ds) for ds in vds] + elseif s === :_data + return [getdata(ds) for ds in vds] + else + return [getdata(ds)[s] for ds in vds] + end +end diff --git a/GNNGraphs/test/datastore.jl b/GNNGraphs/test/datastore.jl index 1c8cfdc1c..404136bdf 100644 --- a/GNNGraphs/test/datastore.jl +++ b/GNNGraphs/test/datastore.jl @@ -20,11 +20,9 @@ end @test_throws DimensionMismatch ds.z=rand(12) ds.z = [1:10;] @test ds.z == [1:10;] - vec = [DataStore(10, (:x => x,)), DataStore(10, (:x => x, :y => rand(2, 10)))] - @test vec.x == [x, x] - @test_throws KeyError vec.z - @test vec._n == [10, 10] - @test vec._data == [Dict(:x => x), Dict(:x => x, :y => vec[2].y)] + + # issue #504, where vector creation failed + @test fill(DataStore(), 3) isa Vector end @testset "setindex!" begin diff --git a/GraphNeuralNetworks/docs/src/temporalgraph.md b/GraphNeuralNetworks/docs/src/temporalgraph.md index f8283c766..f90b73ff4 100644 --- a/GraphNeuralNetworks/docs/src/temporalgraph.md +++ b/GraphNeuralNetworks/docs/src/temporalgraph.md @@ -91,15 +91,15 @@ GNNGraph: ``` ## Data Features - -Node, edge, and graph features can be added at construction time or later using: +A temporal graph can stode global feautre for the entire time series in the `tgdata` filed. +Also, each snapshot can store node, edge, and graph features in the `ndata`, `edata`, and `gdata` fields, respectively. ```jldoctest 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 julia> tg = TemporalSnapshotsGNNGraph(snapshots); -julia> tg.tgdata.y = rand(3,1); # graph features after construction +julia> tg.tgdata.y = rand(3,1); # add global features after construction julia> tg TemporalSnapshotsGNNGraph: @@ -109,7 +109,7 @@ TemporalSnapshotsGNNGraph: tgdata: y = 3×1 Matrix{Float64} -julia> tg.ndata # vector of Datastore for node features +julia> tg.ndata # vector of DataStore containing node features for each snapshot 3-element Vector{DataStore}: DataStore(10) with 1 element: x = 3×10 Matrix{Float64} @@ -118,8 +118,10 @@ julia> tg.ndata # vector of Datastore for node features DataStore(10) with 1 element: x = 5×10 Matrix{Float64} -julia> typeof(tg.ndata.x) # vector containing the x feature of each snapshot -Vector{Matrix{Float64}} +julia> [ds.x for ds in tg.ndata]; # vector containing the x feature of each snapshot + +julia> [g.x for g in tg.snapshots]; # same vector as above, now accessing + # the x feature directly from the snapshots ``` ## Graph convolutions on TemporalSnapshotsGNNGraph From 9d9e8d0a99f779d6911ccf95bda01a9a9de89439 Mon Sep 17 00:00:00 2001 From: Carlo Lucibello Date: Fri, 25 Oct 2024 16:53:10 +0200 Subject: [PATCH 2/2] Update Project.toml --- GNNGraphs/Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GNNGraphs/Project.toml b/GNNGraphs/Project.toml index 97dee916c..310b1205e 100644 --- a/GNNGraphs/Project.toml +++ b/GNNGraphs/Project.toml @@ -1,7 +1,7 @@ name = "GNNGraphs" uuid = "aed8fd31-079b-4b5a-b342-a13352159b8c" authors = ["Carlo Lucibello and contributors"] -version = "1.2.0" +version = "1.2.1" [deps] Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"