add_nodes and add_edges leave graph_indicator inconsistent on batched graphs

未关闭
#733 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
julia
领域
backend, data

调研方向

Read GNNGraphs/src/transform.jl, focusing on add_nodes and add_edges, and compare their handling of graph_indicator with the remove_nodes fix in PR #717. Decide or confirm the intended semantics for assigning new nodes in a batched graph, then check that the indicator stays consistent and sorted. Done when the chosen behavior is documented and tests cover batched additions, including the reported examples.

由索引模型根据 Issue 内容生成。

描述

gnngraphs

add_nodes and add_edges (when the new edges reference nodes beyond num_nodes) increase num_nodes but pass g.graph_indicator through unchanged. On a batched graph this leaves graph_indicator shorter than num_nodes:

using GNNGraphs
g = batch([rand_graph(3, 4), rand_graph(4, 6)])
g.num_nodes, length(g.graph_indicator)              # (7, 7)

g1 = add_nodes(g, 2)
g1.num_nodes, length(g1.graph_indicator)            # (9, 7)

g2 = add_edges(g, [8], [1])
g2.num_nodes, length(g2.graph_indicator)            # (8, 7)

The resulting graph is inconsistent, so functions relying on graph_indicator (e.g. unbatch, getgraph, graph-level pooling) are likely to misbehave or error on it. The relevant code is add_nodes and add_edges in GNNGraphs/src/transform.jl, which both build the new GNNGraph with g.graph_indicator.

It's not a one-line fix because the correct behavior is ambiguous: it's unclear which graph of the batch the new nodes belong to. Options:

  1. Add a keyword (e.g. graph = ...) to assign the new nodes to an existing graph, extending graph_indicator accordingly (and keeping it sorted, which unbatch requires).
  2. Allow the new nodes to be appended as a new graph.
  3. Throw an informative error for batched graphs (g.num_graphs > 1) until the semantics are decided.

Found while reviewing #717, which fixes the same class of inconsistency for remove_nodes.

🧔‍♂️🤖 Assisted by AI

主要语言
Julia
星标
310
派生
75
平均合并
2 天 15 小时
30 天内合并 PR
10

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

JuliaGraphs/GraphNeuralNetworks.jl 的其他 Issue

查看 JuliaGraphs/GraphNeuralNetworks.jl 的全部 Issue

相似的 Issue

更多 Julia Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。