Foundations to Frontier
Tests
E. Deep Learning › E14 Graph Neural Networks

Graph Isomorphism Network (GIN)

How powerful can a message-passing GNN be? Xu, Hu, Leskovec and Jegelka (ICLR 2019) proved that no message-passing GNN can distinguish more graphs than the 1-dimensional Weisfeiler–Lehman (WL) isomorphism test. They also showed that summing neighbour features and passing the result through an MLP reaches that limit. The resulting Graph Isomorphism Network (GIN) uses h' = MLP((1 + ε)h + Σ neighbours). Mean and max aggregation are strictly weaker, because they cannot count. This page covers the WL test, injective multiset functions and the expressiveness hierarchy. In the exercises you implement WL refinement and a GIN layer, then embed all 34 non-isomorphic 5-node graphs from constant features. Sum aggregation separated all 34, matching WL, while mean and max separated only 5. Like WL, GIN could not tell a hexagon from two triangles.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Counting matters

To tell two graphs apart, a GNN has to notice differences in how nodes are connected. An old test does this by repeatedly giving each node a colour based on its own colour and the colours of its neighbours. GIN copies that recipe exactly by adding up neighbour features, so it can count how many neighbours of each kind a node has. Averaging or taking the maximum loses those counts. The demo runs the colour-refinement test on a small graph.

Graph neural network lab
01234567891011
Distinct colours after each iteration: 1 → 3 → 5. WL refines colours by neighbour multisets; GIN is exactly as powerful as this test.
Why engineers care

For molecules, circuits and mechanical assemblies, telling structures apart is the whole task. GIN is a strong default for graph-level classification and regression.

📝 Quick check (Level 0)
0/3 answered
  1. 1. GIN aggregates neighbours by…
  2. 2. Summing lets a node…
  3. 3. GIN is as powerful as…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

By hand

  • WL refinement: start with equal colours. Repeatedly set colour(i) ← hash(colour(i), multiset of neighbour colours). Two graphs with different colour histograms are certainly not isomorphic.
  • Multiset functions:
    • sum separates the multisets (1, 1) and (1, 1, 1);
    • mean gives 1 for both;
    • max cannot tell (1, 2) from (1, 2, 2).
  • GIN layer: h_i’ = MLP((1 + ε) h_i + Σ_(j ∈ N(i)) h_j). On a 4-node path with all features 1, the aggregate is 2 at the ends and 3 in the middle.
  • Graph readout: sum the node embeddings of every layer and concatenate them.
  • Counts: there are 2^10 = 1024 labelled graphs on 5 nodes but only 34 up to isomorphism.
📝 Quick check (Level 1)
0/3 answered
  1. 1. Which aggregation separates {1, 1} from {1, 1, 1}?
  2. 2. GIN aggregate for h = 1 with three neighbours of value 1 (ε = 0):
  3. 3. Labelled graphs on 5 nodes:

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

GIN in code

Exercise 1.

  • One WL step on a 4-node path gave the ends one colour and the middle nodes another.
  • Sum separated multisets that mean and max merged.
  • A GIN layer counted neighbours.

Practice.

  • In PyTorch Geometric, use GINConv(nn.Sequential(Linear, BatchNorm, ReLU, Linear), train_eps=True) with sum pooling over layers (global_add_pool).
  • On molecules, add bond features (GINEConv).
  • If node features are absent, use constant or degree features. Positional or random features can push beyond 1-WL.
from torch_geometric.nn import GINConv, global_add_pool
mlp = nn.Sequential(nn.Linear(d, 64), nn.BatchNorm1d(64), nn.ReLU(), nn.Linear(64, 64))
conv = GINConv(mlp, train_eps=True)
h = conv(x, edge_index); g = global_add_pool(h, batch)      # sum readout keeps counts
🐍 Exercise 1: WL and GIN
Implement one WL refinement step, compare multiset aggregators, and write a GIN layer.
📝 Quick check (Level 2)
0/3 answered
  1. 1. PyG GIN layer with edge features:
  2. 2. GIN's graph readout uses…
  3. 3. To exceed 1-WL, add…

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

Upper bound.

  • Any message-passing GNN computes node states from the node’s state and the multiset of neighbour states, exactly the information WL uses.
  • By induction over layers, if WL gives two graphs the same colour histogram, so does every message-passing GNN (Xu and colleagues; Morris and colleagues, 2019).

Achieving it.

  • If the aggregate-and-update function is injective on multisets, the GNN matches WL.
  • Sums of a suitable feature map are injective on bounded multisets, and an MLP can approximate that feature map. Hence GIN, with sum aggregation and an MLP update, is as powerful as WL.
  • Mean (distributions only) and max (sets only) are not injective and are strictly weaker.

Beyond WL.

  • WL fails on regular graphs of the same size and degree, such as a 6-cycle versus two triangles, and so does every message-passing GNN.
  • Higher-order GNNs (k-WL), subgraph GNNs, and positional or structural encodings (Laplacian eigenvectors, random features) break this limit.
📝 Quick check (Level 3)
0/3 answered
  1. 1. Message-passing GNNs are at most as powerful as…
  2. 2. Mean aggregation captures…
  3. 3. WL fails to separate…

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

How many graphs can each aggregator tell apart?

History.

  • B. Weisfeiler and A. Leman (1968) introduced colour refinement.
  • K. Xu, W. Hu, J. Leskovec and S. Jegelka, “How powerful are graph neural networks?” (ICLR 2019).
  • C. Morris et al., “Weisfeiler and Leman go neural” (AAAI 2019), introduced higher-order GNNs.

Exercise 2.

  • Graphs: all 34 non-isomorphic graphs on 5 nodes.
  • Embeddings: a 4-layer GNN with a random 2-layer MLP update, constant input features and sum readout, using sum, mean or max neighbour aggregation.
  • Count: distinct graph embeddings for each aggregator, compared with the classes WL separates. A hexagon versus two triangles is tested as well.
method graphs separated (of 34)
1-WL test 34
sum aggregation (GIN) 34
mean aggregation 5
max aggregation 5

Hexagon versus two triangles: WL gives them the same colours, and the sum GNN gives identical embeddings.

  • Sum aggregation matches WL: every one of the 34 graphs got its own embedding, even with random, untrained weights. Injectivity does the work.
  • Mean and max are almost blind here: with constant features, every neighbour looks the same, so the mean or max of neighbours is just “1 if the node has any neighbours.” The only thing left is the number of isolated nodes (0, 1, 2, 3 or 5), hence 5 classes.
  • The WL ceiling is real: a hexagon and two triangles (both 2-regular on 6 nodes) are indistinguishable to WL and to GIN alike.
  • Robust to the random weights: seeds 1 and 2 gave the same counts (34, 5, 5).
🐍 Exercise 2 (research): how many graphs can each aggregator tell apart?
Embed all 34 five-node graphs with sum, mean and max aggregation and compare with the WL test.

GIN in AI, robotics and aerospace

  • Molecules and materials: property prediction for fuels, propellants and coatings, where small structural differences matter.
  • Circuits and assemblies: classifying netlists and CAD assembly graphs.
  • Design lesson: if counts of neighbours matter for your task, use sum aggregation. Check whether your task needs to go beyond WL, for example to tell regular structures apart.

References

  1. K. Xu, W. Hu, J. Leskovec and S. Jegelka (2019). “How powerful are graph neural networks?” ICLR.
  2. C. Morris et al. (2019). “Weisfeiler and Leman go neural: higher-order graph neural networks.” Proc. AAAI.
  3. B. Weisfeiler and A. Leman (1968). “The reduction of a graph to canonical form and the algebra which appears therein.” NTI 2.