GraphFSA: A Finite State Automaton Framework for Algorithmic Learning on Graphs

Florian Grötschla, Joël Mathys, Christoffer Raun, Roger Wattenhofer

Introduction

Graph Neural Networks (GNNs) have demonstrated remarkable success in tasks ranging from molecular property prediction to social network analysis. However, a persistent challenge remains: "algorithmic thinking." While GNNs excel at pattern recognition within a specific distribution, they often struggle to capture the discrete, step-by-step logic required for algorithmic tasks. When a standard GNN trained on small graphs is tasked with solving the same problem on significantly larger graphs, its performance frequently collapses. GraphFSA addresses this gap by introducing a framework that learns discrete Finite State Automata (FSA) to solve graph-based problems.

The Challenge of Continuous Embeddings

The primary reason standard GNNs fail at algorithmic extrapolation is their reliance on continuous hidden states. While continuous spaces offer flexibility, they are ill-suited for representing the rigid, discrete logic of an algorithm—such as "if a neighbor is in state X, transition to state Y." Furthermore, GNNs often lack iteration stability. If a model is executed for more steps than it encountered during training, the continuous embeddings tend to diverge, leading to degraded results. To achieve true algorithmic reasoning, a model must distill the underlying "recipe" of a process rather than simply mimicking high-dimensional patterns.

The GraphFSA Framework

GraphFSA operates on the principle that every node in a graph executes the same Finite State Automaton. This approach enforces a discrete bottleneck that regularizes the model toward learning logical rules.

Architecture and Counting Aggregation

At each discrete time step, a node observes the states of its neighbors. To maintain a finite and manageable state space, GraphFSA employs "counting aggregation," inspired by the "Stone Age Computing" model. Instead of precise counting, a node distinguishes only if a specific state appears 0, 1, or "more than $b$" times, where $b$ is a small threshold. This "one-two-many" principle is theoretically powerful; it is sufficient to render the system Turing-complete, allowing it to simulate any computer algorithm.

Training via Diff-FSA

Because discrete transitions are non-differentiable, they cannot be trained using standard backpropagation. The authors circumvent this by introducing Diff-FSA, which relaxes discrete transitions into a probabilistic matrix during the training phase. To ensure the model remains robust and stable over long execution periods, two specific techniques are employed:

  1. Random Iteration Offset: The number of execution steps is varied during training, forcing the model to learn rules that are independent of a specific execution length.
  2. Final State Loss: A penalty is applied if the model attempts to transition out of a designated "halting" or "final" state, encouraging the discovery of stable terminal configurations.

Experimental Evaluation

The researchers evaluated GraphFSA across three distinct domains: Classical Cellular Automata (CA), the GRaph Automaton Benchmark (GRAB), and classic graph algorithms.

Classical Cellular Automata

On tasks like WireWorld—a CA used to simulate electronic circuits—GraphFSA demonstrated near 100% accuracy. In contrast, Recurrent GNNs and Graph Cellular Automata (GNCA) saw their performance plummet as the number of execution steps and grid sizes increased.

GRAB and Algorithmic Tasks

The GRAB benchmark was used to verify if the model could recover exact underlying logic. Even when the model was provided with more states than necessary (e.g., using a 6-state model for a 4-state problem), it successfully identified the correct algorithm. On the Distance task (calculating the parity of distance from a root), GraphFSA maintained perfect accuracy on graphs ten times larger than those in the training set, while baseline models performed no better than random chance.

Insights and Interpretability

A significant advantage of GraphFSA is its inherent interpretability. Unlike "black-box" neural networks, a learned GraphFSA can be visualized as a state-transition diagram. This allows researchers to inspect the "thought process" of the model directly. Furthermore, the discrete nature of the framework acts as a powerful regularizer, preventing the high-dimensional curve-fitting that leads to poor extrapolation in standard GNNs.

Limitations and Future Directions

Despite its strengths, GraphFSA faces challenges regarding the exponential growth of the state space as the number of states and the counting threshold increase. Currently, the framework is also limited to discrete input features. Future research may focus on developing modules to map continuous real-world data into these discrete states and refining the training process for discrete-logic models, which remains more complex than standard GNN optimization.

Summary updated

Abstract

Many graph algorithms can be viewed as sets of rules that are iteratively applied, with the number of iterations dependent on the size and complexity of the input graph. Existing machine learning architectures often struggle to represent these algorithmic decisions as discrete state transitions. Therefore, we propose a novel framework: GraphFSA (Graph Finite State Automaton). GraphFSA is designed to learn a finite state automaton that runs on each node of a given graph. We test GraphFSA on cellular automata problems, showcasing its abilities in a straightforward algorithmic setting. For a comprehensive empirical evaluation of our framework, we create a diverse range of synthetic problems. As our main application, we then focus on learning more elaborate graph algorithms. Our findings suggest that GraphFSA exhibits strong generalization and extrapolation abilities, presenting an alternative approach to represent these algorithms.
BibTeX
@inproceedings{grotschla2024graphfsa,
  author = {Florian Grötschla and Joël Mathys and Christoffer Raun and Roger Wattenhofer},
  title = {{GraphFSA: A Finite State Automaton Framework for Algorithmic Learning on Graphs}},
  booktitle = {ECAI},
  year = {2024},
  url = {https://openreview.net/forum?id=0CpE48nGeW},
}
Figure