From b3de706c2c51e40d0a013ef7b16039eb7f768864 Mon Sep 17 00:00:00 2001 From: parth-patel010 Date: Tue, 27 Oct 2026 21:00:13 +0530 Subject: [PATCH 1/2] Update graph_indicator in remove_nodes --- GNNGraphs/src/transform.jl | 3 ++- GNNGraphs/test/transform.jl | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/GNNGraphs/src/transform.jl b/GNNGraphs/src/transform.jl index a89035de7..12d438528 100644 --- a/GNNGraphs/src/transform.jl +++ b/GNNGraphs/src/transform.jl @@ -246,12 +246,13 @@ function remove_nodes(g::GNNGraph{<:COO_T}, nodes_to_remove::AbstractVector) nodes_to_keep = setdiff(1:g.num_nodes, nodes_to_remove) ndata = getobs(ndata, nodes_to_keep) edata = getobs(edata, mask_edges_to_keep) + graph_indicator = isnothing(g.graph_indicator) ? nothing : g.graph_indicator[nodes_to_keep] num_nodes = g.num_nodes - length(nodes_to_remove) return GNNGraph((s, t, w), num_nodes, length(s), g.num_graphs, - g.graph_indicator, + graph_indicator, ndata, edata, g.gdata) end diff --git a/GNNGraphs/test/transform.jl b/GNNGraphs/test/transform.jl index 508cc6b16..6422f7b74 100644 --- a/GNNGraphs/test/transform.jl +++ b/GNNGraphs/test/transform.jl @@ -379,6 +379,27 @@ end end end +@testitem "remove_nodes on batched graph" setup=[GraphsTestModule] begin + using .GraphsTestModule + g1 = GNNGraph([1, 2], [2, 3], ndata = [1.0, 2.0, 3.0]) + g2 = GNNGraph([1, 2, 3], [2, 3, 4], ndata = [4.0, 5.0, 6.0, 7.0]) + g = MLUtils.batch([g1, g2]) + + gnew = remove_nodes(g, [2, 5]) + @test gnew.num_nodes == 5 + @test gnew.num_graphs == 2 + @test gnew.graph_indicator == [1, 1, 2, 2, 2] + @test gnew.ndata.x == [1.0, 3.0, 4.0, 6.0, 7.0] + + gs = MLUtils.unbatch(gnew) + @test gs[1].num_nodes == 2 + @test gs[1].num_edges == 0 + @test gs[2].num_nodes == 3 + @test edge_index(gs[2]) == ([2], [3]) + @test gs[2].ndata.x == [4.0, 6.0, 7.0] + @test getgraph(gnew, 2).ndata.x == [4.0, 6.0, 7.0] +end + @testitem "remove_nodes(g, p)" setup=[GraphsTestModule] begin using .GraphsTestModule for GRAPH_T in GRAPH_TYPES From 9008bcadfe311ad1bdcd2d69c99759a5bb8cc66c Mon Sep 17 00:00:00 2001 From: parth-patel010 Date: Tue, 27 Oct 2026 21:00:37 +0530 Subject: [PATCH 2/2] Add CHANGELOG entry --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ae90818b..614cb882a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ Entries link to the pull request that introduced them. - Added a `Mooncake` package extension, so that Mooncake can differentiate on CUDA through `add_self_loops` and through adjacency-matrix graphs. Float edge weights of adjacency-matrix graphs stay differentiable ([#704]). **Fixed** +- `remove_nodes` now updates the `graph_indicator` of batched graphs. It was previously left unchanged, so calling `unbatch` or `getgraph` on the result threw a `BoundsError` ([#717]). - Added an `EnzymeCore` package extension marking `scaled_laplacian` inactive for Enzyme, matching its existing `@non_differentiable` ChainRules declaration. Enzyme previously differentiated the Krylov eigensolve inside it and failed; this unblocks `ChebConv`, `GConvGRUCell` and `GConvLSTMCell` ([#706]). - Enzyme can now differentiate through the adjacency-matrix → COO graph conversion: a new internal keyword-free helper `_to_coo_graph` avoids the union-typed keyword handling of the `GNNGraph(g; graph_type)` constructor and of `to_coo`, which Enzyme's type analysis cannot compile. Together with upstream fixes in Enzyme ≥ 0.13.197 this removes the `EnzymeInternalError` crash on `:dense`/`:sparse` graphs ([#703]). @@ -238,4 +239,5 @@ Lux implementations of the graph convolutional, pooling, and temporal layers [#704]: https://github.com/JuliaGraphs/GraphNeuralNetworks.jl/pull/704 [#707]: https://github.com/JuliaGraphs/GraphNeuralNetworks.jl/pull/707 [#706]: https://github.com/JuliaGraphs/GraphNeuralNetworks.jl/pull/706 +[#717]: https://github.com/JuliaGraphs/GraphNeuralNetworks.jl/pull/717 [FluxML/Zygote.jl#1662]: https://github.com/FluxML/Zygote.jl/issues/1662