Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Messages that carry edge information
The message-passing recipe has three parts: what a neighbour sends (the message), how a node combines what it receives (aggregation), and how it updates itself. In the MPNN framework the message can also depend on the edge, such as the type of a chemical bond or the distance between two atoms. Finally a readout sums up all nodes into one prediction for the whole graph. The demo shows how messages spread through the graph layer by layer.
Many graph quantities depend on edge properties: bond lengths in molecules, cable lengths in a grid, distances between agents. Edge-aware MPNNs predict energies, forces and loads directly from such graphs.
- 1. An MPNN's three learned parts are…
- 2. Messages can depend on…
- 3. A readout produces…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.By hand
- Message: m_i = Σ_(j ∈ N(i)) M(h_i, h_j, e_ij).
- Update: h_i’ = U(h_i, m_i).
- Readout: ŷ = R(multiset of h_i), for example a sum, or set2set as in the original paper.
- Edge network (Gilmer): M(h_i, h_j, e_ij) = A(e_ij) h_j, where a network A maps the edge feature to a d × d matrix. A linear A from 4 edge features to 64 × 64 matrices has 4·64² = 16,384 weights.
- Directed messages: each undirected edge sends two messages per layer (13 edges give 26 messages).
- Exercise 2’s target:
- spring energy Σ_edges k_(type_i, type_j)(d_ij − 0.7)²; one spring with k = 3 and d = 0.9 stores 3·0.04 = 0.12;
- with 2 node types there are 3 distinct spring constants.
- 1. Spring energy for k = 3, d = 0.9, rest length 0.7:
- 2. Messages per layer for 13 undirected edges:
- 3. Gilmer's edge network outputs…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.MPNNs in code
Exercise 1.
- A generic message-passing layer with edge-weighted messages gave the expected node updates and sum readout.
- An edge network produced a 2 × 2 transformation matrix.
Practice.
- In PyTorch Geometric, subclass
MessagePassingand definemessage(x_i, x_j, edge_attr); built-ins includeNNConv(edge network),GINEConv, and physics-aware models (SchNet, DimeNet). - Encode distances with radial basis functions rather than raw numbers.
- For physical systems, make sure messages respect symmetries (rotation and translation invariance) by using distances and angles, not raw coordinates.
from torch_geometric.nn import MessagePassing
class EdgeMP(MessagePassing):
def __init__(self, d, d_edge):
super().__init__(aggr="add"); self.mlp = nn.Sequential(nn.Linear(2 * d + d_edge, d), nn.SiLU(), nn.Linear(d, d))
def forward(self, x, edge_index, edge_attr):
return x + self.propagate(edge_index, x=x, edge_attr=edge_attr)
def message(self, x_i, x_j, edge_attr):
return self.mlp(torch.cat([x_i, x_j, edge_attr], dim=-1))- 1. PyG edge-network layer:
- 2. Distances are best encoded with…
- 3. For rotation invariance, messages should use…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
One framework for many models.
- GCN: message = normalised h_j; aggregate = sum; update = linear + nonlinearity.
- GraphSAGE: sampled mean plus concatenation. GAT: attention-weighted messages. GIN: sum plus MLP. Interaction networks and gated graph networks fit as well.
- Seeing them this way separates the design choices: what information messages carry, how they are pooled, and how states are updated.
Edge features add information, not just weights.
- If the target depends on edge attributes (bond lengths, line impedances), a model that sees only topology must guess from counts and node types.
- Message functions that take e_ij as input can represent such dependencies directly; for additive targets, a sum over edges of a learned function of e_ij is exact.
Readouts. Sum readouts suit extensive quantities that grow with size (energy); mean readouts suit intensive ones (per-atom averages). Attention-based readouts (set2set) are more flexible.
- 1. GAT in the MPNN view uses…
- 2. Energy is an extensive quantity, so use a…
- 3. Without edge features, a model must infer edge effects from…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.Do edge features matter?
History.
- J. Gilmer, S. Schoenholz, P. Riley, O. Vinyals and G. Dahl, “Neural message passing for quantum chemistry” (ICML 2017). It used QM9: 134 k molecules, 13 properties.
- Physics-aware successors include SchNet (2017, continuous distance filters) and DimeNet (2020, bond angles).
Exercise 2.
- Graphs: random spring networks of 8 points in a 2 × 2 square, each point of one of 2 types, with an edge between points closer than 1 (about 13 edges per graph).
- Target: total spring energy Σ k_(type pair)(d − 0.7)², with stiffness 1, 3 or 0.5 by type pair.
- Model: an MPNN whose message on each edge is an MLP of its input, with a sum readout (200 training graphs, 800 Adam steps, test on 200 new graphs). It receives either the type pair alone or the type pair plus the distance.
| model | test R² |
|---|---|
| edge count only (linear) | 0.261 |
| MPNN, node types + topology | 0.383 |
| MPNN, + distances as edge features | 0.986 |
- Edge features are decisive: with distances, the MPNN explains 98.6% of the energy variance. The energy is a sum over edges of a function of distance and type pair, which the message function learns directly.
- Without them, the model can only guess: it uses edge counts and type pairs (38%, only a little better than counting edges at 26%). The energy depends on how stretched each spring is, which the topology does not reveal.
- Seeds: with seeds 1 and 2: 0.26 and 0.27 without distances against 0.99 and 0.99 with them.
MPNNs in AI, robotics and aerospace
- Molecules and materials: energies, forces and properties of propellants, polymers and catalysts.
- Structures: load and stress prediction on truss and frame graphs, where member lengths and stiffnesses are edge features.
- Multi-agent systems: relative positions and velocities as edge features for interaction-aware prediction.
- Design lesson: put physically meaningful quantities on the edges, and use readouts that match how the target scales.
References
- J. Gilmer, S. S. Schoenholz, P. F. Riley, O. Vinyals and G. E. Dahl (2017). “Neural message passing for quantum chemistry.” Proc. ICML.
- K. T. Schütt et al. (2017). “SchNet: a continuous-filter convolutional neural network for modeling quantum interactions.” NeurIPS.
- P. W. Battaglia et al. (2018). “Relational inductive biases, deep learning, and graph networks.” arXiv:1806.01261.