Treedepth-Indexed Message Passing for Molecules

Graph neural networks for chemistry are usually judged by which pairs of non-identical molecules they can tell apart, a scale borrowed from the Weisfeiler–Lehman color-refinement test. This note proposes a different scale that fits molecules better. Molecules are small and sparse, so one can ask which logical properties a network can express on graphs of bounded treedepth. Treedepth measures how few rounds of deleting one atom per connected piece it takes to break the graph into nothing. On a chain of $n$ atoms it grows only as $\log_2 n$, and on drug-sized molecules it is a small integer. A result from finite model theory says that on such graphs, first-order logic, which talks about individual atoms and bonds, can express everything monadic second-order logic can, including statements that quantify over whole sets of atoms such as "the aromatic part has a Kekulé structure" or "the ring system has an odd cycle."

We propose a message-passing network that runs on an elimination forest: the rooted forest that witnesses a molecule's treedepth. In it, every atom exchanges information only with its forest ancestors. The network's depth is then set by treedepth rather than by molecule size, and its computation follows the textbook dynamic program that decides monadic second-order properties on bounded-treedepth graphs. The bet is twofold. First, such a network learns set-quantifying chemical properties that standard networks miss. Second, it extrapolates to larger molecules exactly when their treedepth stays within the training range, and fails in a predictable way when it does not. This would give molecular machine learning a structural measure of distribution shift that is sharper than "scaffold split."

Core Claim

Where First-Order and Monadic Second-Order Logic Coincide proves that on subgraph-closed graph classes, first-order logic and monadic second-order logic have equal expressive power if and only if treedepth is bounded. The proof uses a composition theorem over an unbounded number of components. That paper is purely descriptive and builds no inference engine. On the learning side, Expressive Power of Graph Transformers via Logic pins down plain graph transformers and hybrid local-plus-global networks as fragments of propositional and graded modal logic with a global modality, and shows the fragment shifts between real and floating-point arithmetic. It deliberately puts no structural restriction on the input graphs. Weisfeiler and Lehman Go Cellular: CW Networks moves beyond the 1-WL ceiling by lifting rings to 2-cells, but it measures expressivity only against the WL hierarchy and names no logic.

Our claim joins these results, which nobody has done. Let $d$ be the treedepth bound and $q$ the quantifier rank of a monadic second-order sentence. We claim that a network whose atom states are conditioned on their at most $d$ forest ancestors, with state width depending only on $d$ and $q$, can express every such sentence on molecules of treedepth at most $d$, independent of molecule size. Graded modal logic is what plain message passing captures, and it provably cannot express these sentences. The new content is therefore a learned architecture whose expressivity guarantee is indexed by a structural graph parameter. Its empirical consequence is falsifiable: size extrapolation should succeed within a treedepth band and break across it.

Research Program

The first component is the construction itself. For each molecule we compute an elimination forest of minimum or near-minimum depth. Exact treedepth is NP-hard in general but solvable in time exponential only in the treedepth. That puts exact computation within reach for drug-sized molecules, and we fall back to a separator-based heuristic for larger ones.

The network then runs two passes over the forest. The upward pass computes, for each subtree, a vector summarizing that subtree. The summary is conditioned on which forest ancestors the subtree's atoms bond to, together with the bond and atom features. This is the learned analogue of the "type of a subtree relative to its ancestor path" that the dynamic program tabulates. The downward pass broadcasts root-level summaries back so the network can make per-atom predictions. Atoms on a graph edge are always in an ancestor–descendant relation in the forest, so every chemical bond is seen by exactly one ancestor-conditioned update. The total number of sequential steps is $2d$.

The second component is theoretical. We aim to prove the expressivity statement above by simulating the Feferman–Vaught-style composition with ancestor-indexed sum aggregation, and to give a matching limitation: any fixed-width instance of the network fails on some property once treedepth exceeds its design bound. We will also check whether the floating-point saturation effects identified by Ahvonen et al. undercut the counting the construction needs. If the proof only goes through with unbounded width, we will say so and treat the architecture as an empirical hypothesis.

The third component is a benchmark of exactly labeled, set-quantifying properties on real molecular graphs drawn from ZINC. The labels are computed by exact solvers. They include existence of a perfect matching on the aromatic subgraph, which is the Kekulé question; presence of an odd cycle; whether a marked atom's removal disconnects the molecule; and whether the ring system admits a proper 3-coloring. All are monadic second-order definable, and none is a simple count. Each molecule is annotated with its exact treedepth, treewidth, and cyclomatic number, the number of independent rings. This lets us separate the three parameters, which the parameterized-complexity literature shows can behave very differently (Distance-based (and path-based) covering problems for graphs of given cyclomatic number, Geodetic Set on Graphs of Constant Pathwidth and Feedback Vertex Set Number).

The Geodetic Set hardness result constrains the design. Shortest-path properties stay NP-complete at constant pathwidth, so we deliberately exclude distance-covering properties from the guarantee and test them only as an out-of-scope control.

Baselines

The naive reference points are two. The first is extended-connectivity fingerprints with a random forest. The second is a standard message-passing network with the same parameter count. On the set-quantifying tasks we expect the message-passing network to sit near the majority-class rate on molecule pairs it cannot distinguish. If it does not, our premise is wrong. For ZINC regression and MoleculeNet, MoleculeNet: A Benchmark for Molecular Machine Learning reports that learnable graph models beat fixed-feature models on 11 of 17 datasets, so fingerprints are a real competitor on some tasks.

The strongest existing method for structure-aware molecular expressivity is CW Networks, which lift rings to cells. They report a ZINC test MAE of 0.079 with edge features (Weisfeiler and Lehman Go Cellular: CW Networks) and 100% accuracy on the CSL isomorphism benchmark. We rerun the authors' configuration on our splits rather than copying numbers, giving every model the same data, the same hyperparameter search budget of 50 trials, and the same GPU-hour cap. We also include a local-plus-global transformer with random-walk positional encodings, the setting Ahvonen et al. left uncharacterized. For MoleculeNet classification we include GEM (Geometry-enhanced molecular representation learning for property prediction). The file reports GEM only in aggregate form, as best results on 14 of 15 benchmarks and a 4.7% average relative ROC-AUC gain on classification, with no single-task numbers. We will therefore rerun it without pre-training for a like-for-like comparison and separately report its released pre-trained variant.

The most dangerous competitor is a tree-decomposition network: a learned dynamic program over a junction tree, using the cluster decomposition and tree encoder of Junction Tree Variational Autoencoder for Molecular Graph Generation. By Courcelle's theorem it also captures monadic second-order logic on bounded treewidth, and molecular treewidth is smaller than treedepth.

Three ablations isolate the key ingredient:

  • Valid but deep forest: the same network on a valid elimination forest of deliberately poor depth, such as a depth-first-search tree. This tests whether minimal depth matters.
  • No ancestor conditioning: the optimal forest with ancestor conditioning removed, giving plain tree message passing. This tests whether the guarded ancestor context is what carries the expressivity.
  • Raw-graph control: the network applied to the raw graph with matched depth $2d$.

Beating the field means one of three outcomes. On the set-quantifying tasks, at least 95% accuracy within the training treedepth range on molecules up to twice the training size, while CW Networks and the transformer degrade. Non-inferiority to CW Networks on ZINC MAE. Or the predicted sharp drop at the treedepth boundary that the junction-tree network does not show.

Why not just…?

Why not just use CW Networks, since ring cells already exceed 3-WL? Their guarantee is about distinguishing graphs, not about expressing a quantified property uniformly across sizes. Telling apart all pairs a test can separate does not imply learning "has a Kekulé structure" with a size-independent model. This is a real threat on odd-cycle detection, where explicit ring cells may suffice. The size-extrapolation split settles it: if CW Networks match us there, our contribution shrinks to the treedepth-indexed diagnosis, and we will report that.

Why not just run a learned dynamic program over a junction tree, since treewidth is smaller? This is the strongest alternative. On chains and long linkers, a junction tree has height linear in molecule size, so information crosses linearly many sequential steps. The elimination forest crosses about $\log n$. The over-squashing evidence from RingTransfer in the CW Networks paper and the "telephone game" degradation in Tree Decomposed Graph Neural Network suggest long sequential paths hurt learning even when they are expressive in principle. Only the treedepth view, through Elberfeld et al., makes these properties first-order with bounded quantifier rank, and therefore computable in bounded rounds. If the junction-tree network extrapolates equally well on long-linker molecules, the depth argument fails, and we would fold treewidth indexing into the proposal instead.

Why not just add positional encodings to a graph transformer? Random-walk and spectral encodings inject cycle information cheaply. No logical characterization covers them, and the floating-point analysis of Ahvonen et al. warns that global aggregation saturates on larger inputs. The size-extrapolation split tests this directly.

Why not just use fingerprints? Fixed-radius fingerprints encode local substructures and cannot represent global properties like matching existence. We include them anyway, because on real MoleculeNet endpoints they may tie everything. That would show the expressivity gain is irrelevant for those labels, which is itself worth reporting.

Decisive Experiments

The first check is the size-extrapolation grid on the exactly labeled benchmark. We train on ZINC molecules below a size cutoff, then test on larger molecules split by whether their treedepth falls inside or outside the training range, with treewidth and ring count held as matched as possible. The architecture is supported if its accuracy stays flat across size within the treedepth range and drops at the treedepth boundary, while the ablated variants and baselines degrade with size regardless of treedepth. Distance-covering control tasks should show no such guarantee, consistent with Tale's hardness result.

The second check moves to real labels. On ZINC regression and the MoleculeNet classification tasks (BACE, BBBP, Tox21, HIV) we compare scaffold splits against treedepth-shift splits. We test whether the drop from random to scaffold split that MoleculeNet documents is better predicted by a treedepth mismatch between train and test than by scaffold novelty itself. If it is, treedepth becomes a practical tool for anticipating where molecular models will fail.

The third check concerns cost. Exact treedepth computation and the network's runtime must stay within a small constant factor of a standard message-passing network on ZINC-scale molecules. Otherwise the method is a theoretical curiosity, and we will say so.