Md. Asif Uddin
    Problem I.14.B05

    A batch of three graphs

    shape▲▲△

    Exact.

    STATEMENT

    Put three graphs of different sizes into one batch, give the shape of every array, and find what goes wrong when the edge lists are not offset.

    GIVEN

    The paw graph (44 nodes, edges 0101, 0202, 1212, 2323), a path on 33 nodes (0101, 1212) and a cycle on 55 nodes (0101, 1212, 2323, 3434, 4040), each numbered from 00. Node features have width dd. The readout sums node states per graph. For the check, every feature is 11 and one round of sum aggregation is applied.

    FIND

    The total node count; the shapes of the batched features, the batch vector, the edge index and the readout; the offsets; the readouts with and without offsets.

    STRATEGY

    Stack the graphs’ nodes one after another. A batch is then one large graph whose adjacency matrix is block diagonal, provided every edge is shifted by the number of nodes before its graph.

    SOLUTION

    Shapes. There are 4+3+5=124+3+5=12 nodes, so the features are 12×d12\times d. The batch vector, of length 1212, records each node’s graph: (0,0,0,0,1,1,1,2,2,2,2,2)(0,0,0,0,1,1,1,2,2,2,2,2). The 1111 undirected edges become 2222 directed entries, so the edge index is 2×222\times22. The readout is 3×d3\times d, one row per graph.

    Offsets. Graph gg‘s node ii becomes node i+ogi+o_g with o=(0,4,7)o=(0,4,7), the running total of earlier sizes. The adjacency matrix of the batch is then block diagonal, and no message crosses between graphs. Since sum aggregation over a block-diagonal matrix acts on each block separately, batching changes no graph’s result.

    The check. With all features 11, one round of sum aggregation gives each node its degree, and the per-graph sum of degrees is twice the edge count: 88, 44 and 1010.

    Without offsets. All three edge lists then refer to nodes 00 to 44. The path’s edges coincide with two of the paw’s and merge into them, and the cycle’s edges connect the paw’s nodes to one another and to node 44, which belongs to the path. The readouts become 1010, 22 and 00. The shapes are all still correct, so nothing fails until the numbers are compared.

    Answer

    1212 nodes; features 12×d12\times d; batch vector length 1212; edge index 2×222\times22; readout 3×d3\times d; offsets (0,4,7)(0,4,7). Readouts 88, 44, 1010 with offsets and 1010, 22, 00 without.

    Check — sanity

    Each correct readout equals twice that graph’s number of edges, 2⋅42\cdot4, 2⋅22\cdot2 and 2⋅52\cdot5, as the handshake count requires.

    Where this breaks

    A readout by mean needs each graph’s node count, 44, 33 and 55, taken from the batch vector; dividing by 1212 would mix the graphs again. Graph libraries keep the batch vector for exactly this reason.

    Variation

    A dense alternative pads every graph to the largest size, 55, giving features of shape 3×5×d3\times5\times d and three 5×55\times5 adjacency matrices. It wastes 33 of 1515 node slots here, and far more when sizes vary widely.

    Draws on