The Weisfeiler-Lehman (WL) test is a classical, iterative algorithm for determining whether two graphs are isomorphic—structurally identical despite potential differences in node labeling. It operates by iteratively color-refining nodes based on the multiset of colors from their immediate neighbors, assigning a new, compressed color label to each node in each iteration. If, after refinement, the histograms of color labels for two graphs differ, the graphs are provably non-isomorphic; however, the test is not a complete isomorphism check, as some non-isomorphic graphs cannot be distinguished by it, a limitation known as the test's expressivity.
Glossary
Weisfeiler-Lehman Test

What is the Weisfeiler-Lehman Test?
The Weisfeiler-Lehman (WL) test is a classical, iterative algorithm for testing graph isomorphism that colors nodes based on their neighborhood structures, forming the theoretical basis for analyzing the expressive power of Graph Neural Networks.
In modern machine learning, the WL test provides the fundamental theoretical framework for analyzing Graph Neural Networks (GNNs). The 1-dimensional WL test (1-WL) defines an upper bound on the discriminative power of standard message-passing GNNs; a GNN is at most as powerful as the 1-WL test in distinguishing graph structures. This insight has driven the development of more expressive architectures, such as the Graph Isomorphism Network (GIN), which are designed to match the WL test's power. Consequently, the test is a cornerstone for understanding the capabilities and limitations of models in graph representation learning and generative graph modeling.
Key Characteristics of the WL Test
The Weisfeiler-Lehman (WL) test is a classical, iterative algorithm for testing graph isomorphism. Its core mechanism of iterative node coloring provides the fundamental theoretical framework for analyzing the expressive power of modern Graph Neural Networks.
Iterative Node Coloring
The WL test's core algorithm is an iterative color refinement procedure. It starts by assigning an initial color (or label) to each node, often based on its degree or features. In each iteration, a node's color is updated by hashing the multiset of colors from its immediate neighbors combined with its own previous color. This process aggregates local structural information outward.
- Initialization: Assign initial colors (e.g., node degree).
- Aggregation: For each node, collect the colors of its neighbors.
- Hashing: Create a new, unique color for each distinct aggregated multiset.
- Iteration: Repeat until the coloring stabilizes (no new colors are created).
Two graphs are considered non-isomorphic if their final color histograms differ.
Isomorphism Testing & Limitations
The WL test is a necessary but not sufficient condition for graph isomorphism. If the test determines two graphs are different (their color histograms diverge), they are definitively non-isomorphic. However, if the test deems them equivalent (same histogram), they are not guaranteed to be isomorphic; they are WL-equivalent or 1-WL indistinguishable.
- Sound but Incomplete: It never returns a false negative for non-isomorphism but can return false positives for isomorphism.
Key Limitation: The 1-dimensional WL test (1-WL) fails to distinguish certain strongly regular graphs and other complex structures, establishing a clear upper bound on its discriminative power. Higher-order k-WL tests (k>1) are more powerful but computationally prohibitive.
Theoretical Basis for GNN Expressiveness
The WL test provides the primary theoretical lens for analyzing Graph Neural Networks. The message-passing mechanism of a standard GNN is analogous to the WL test's color refinement step.
- GNNs are at most as powerful as 1-WL: If two graphs are indistinguishable by the 1-WL test, no standard message-passing GNN can distinguish them either. This defines the expressive upper bound for most GNN architectures.
- Architectures Matching WL Power: The Graph Isomorphism Network (GIN) was explicitly designed using injective multiset functions to match the expressive power of the 1-WL test, making it maximally powerful within this class.
- Beyond 1-WL: Research into higher-expressive models (e.g., k-GNNs, Graph Transformers) seeks to surpass the 1-WL limit, often by incorporating higher-order topological features or more complex aggregation schemes.
Kernel & Graph Feature Generation
The sequence of color histograms produced during WL iterations can be used to construct the Weisfeiler-Lehman Graph Kernel. This kernel measures graph similarity by counting common refined colors across iterations, providing a powerful method for graph classification tasks without deep learning.
- Feature Vector: For a graph, the feature vector is a histogram counting the occurrences of each unique color (label) at each iteration.
- Kernel Computation: The WL kernel between two graphs is computed as the inner product of their feature vectors across all iterations.
- Application: Serves as a strong baseline for graph classification, especially when dataset sizes are small. It explicitly captures multiscale substructure information, from local node neighborhoods to broader graph regions.
Higher-Order k-WL Tests
To overcome the limitations of the 1-WL test, more powerful k-dimensional Weisfeiler-Lehman (k-WL) tests were developed. Instead of coloring single nodes, the k-WL test colors k-tuples of nodes (i.e., subgraphs of size k).
- Increased Expressiveness: The (k+1)-WL test is strictly more powerful than the k-WL test. For example, 2-WL (also known as the Folklore WL or FWL test) can distinguish some graphs that 1-WL cannot.
- Computational Cost: The complexity grows exponentially with k, making k-WL for k>2 impractical for large graphs.
- Connection to GNNs: This hierarchy inspires the development of k-GNNs, which operate on k-tuples but use practical approximations to manage computational cost while aiming for higher discriminative power.
WL Hierarchy & Graph Properties
The WL test hierarchy (1-WL, 2-WL, etc.) establishes a formal classification of which graph properties can be detected. This is crucial for understanding what tasks a given GNN can inherently learn.
Properties distinguishable by 1-WL (and thus by standard GNNs) include:
- Node degree distribution
- Presence of triangles and other small, connected subgraphs (graphlets)
- Connectivity and diameter (indirectly, via color propagation)
Properties NOT distinguishable by 1-WL include:
- Exact cycle detection for cycles longer than a certain length (dependent on iterations)
- Certain regular graph structures where all nodes have identical local neighborhoods at every depth
- General graph connectivity (whether the graph is connected or not) cannot be decided in a bounded number of iterations for all graphs.
This hierarchy directly informs the inductive biases and limitations of graph learning models.
WL Test Variants and Their Power
This table compares the distinguishing power and key characteristics of different variants of the Weisfeiler-Lehman test, which serve as theoretical benchmarks for the expressive power of Graph Neural Networks.
| Variant | Distinguishing Power | Computational Complexity | Common GNN Analogue | Limitations |
|---|---|---|---|---|
WL (1-dimensional) | Equivalent to 1-WL test. Distinguishes most non-isomorphic graphs but fails on certain regular graphs (e.g., strongly regular graphs). | O(hm) | Standard Message-Passing GNNs (GCN, GAT) | Cannot distinguish regular graphs of the same degree and size. |
k-WL (k-dimensional) | Strictly more powerful than (k-1)-WL. 2-WL is equivalent to 3-WL in distinguishing power. | O(n^k) | Higher-Order GNNs, k-GNNs | Exponential complexity in k. Not commonly implemented for k > 3. |
k-FWL (Folklore WL) | k-FWL is as powerful as (k+1)-WL. More practical and commonly referenced than k-WL. | O(k n^{k+1}) | Higher-Order GNNs using FWL-style aggregation | High memory footprint for coloring tuples. |
WL with Subtree Kernels | Power equal to 1-WL. Used to compute the WL subtree kernel for graph classification. | O(hm) | GNNs followed by a global pooling operation (e.g., sum, mean) | Same limitations as 1-WL. Kernel computation can be costly for large graphs. |
Local Iterative WL | Focuses on local neighborhoods. Power is upper-bounded by the global 1-WL test. | O(hm) for h iterations | GNNs with limited message-passing steps | May fail to capture global graph structure if iterations are limited. |
WL Optimal Assignment Kernels | Enhanced via optimal assignment between neighbor bags. Can be more powerful than standard 1-WL. | Higher than O(hm) | Not directly analogous to a standard GNN architecture | Computationally intensive; lacks a straightforward neural counterpart. |
Shervashidze et al. Shortest-Path Kernel | Based on shortest-path distances, not WL iterations. Incomparable power; can distinguish some graphs 1-WL cannot. | O(n^4) | GNNs that explicitly encode shortest-path distances (e.g., using positional encodings) | Very high computational cost for large graphs. |
WL Test and GNN Architectures
The Weisfeiler-Lehman (WL) test is a classical, iterative algorithm for testing graph isomorphism. Its underlying mechanism provides the formal framework for analyzing the expressive power and limitations of modern Graph Neural Networks.
Core Algorithm: The 1-WL Test
The 1-dimensional Weisfeiler-Lehman (1-WL) test is an iterative, color-refinement algorithm for graph isomorphism. It operates by:
- Initializing each node with a color based on its initial features (or a constant if none exist).
- Iteratively refining each node's color by hashing the multiset of its neighbors' colors from the previous iteration.
- Comparing the final multisets of node colors between two graphs. If the multisets differ, the graphs are provably non-isomorphic. If they are identical, the graphs are possibly isomorphic (the test is necessary but not sufficient for a full isomorphism guarantee). This process creates a WL subtree kernel, a powerful graph similarity measure.
Theoretical Limit of GNN Expressiveness
A seminal theoretical result establishes that standard Message-Passing Graph Neural Networks (MPNNs) are at most as powerful as the 1-WL test. This means:
- If two graphs are distinguishable by the 1-WL test, a sufficiently powerful MPNN can learn to distinguish them.
- If two graphs are indistinguishable (or "WL-equivalent"), no MPNN can produce different embeddings for them, limiting their ability to solve certain graph problems. This WL equivalence defines the upper bound on what information MPNNs can capture, primarily local neighborhood structures. It explains why basic GNNs struggle with tasks requiring counting specific substructures (like cycles) or identifying certain graph properties.
GIN: A Maximally Powerful GNN
The Graph Isomorphism Network (GIN) was explicitly designed to match the expressive power of the 1-WL test. Its key innovation is the use of an injective multiset aggregation function. The GIN update rule is:
h_v^(k) = MLP^((k))((1 + ε^(k)) * h_v^(k-1) + Σ_(u ∈ N(v)) h_u^(k-1))
- The sum aggregator is provably injective for multisets, unlike mean or max pooling.
- The MLP acts as a universal approximator of injective functions.
- The learnable parameter ε allows the model to weigh the central node's features. GIN achieves maximum discriminative power within the 1-WL framework, making it a theoretically grounded and highly expressive architecture for graph classification tasks.
Beyond 1-WL: k-WL Hierarchy
The k-dimensional WL test (k-WL) is a more powerful generalization that colors k-tuples of nodes instead of single nodes. This hierarchy is strictly increasing in power: (k+1)-WL is strictly more powerful than k-WL.
- 2-WL (equivalent to Folklore WL) is significantly more powerful than 1-WL and can distinguish almost all practical graphs.
- Higher-order GNNs are designed to match the expressiveness of k-WL tests by operating on tuples, subgraphs, or using higher-order invariants.
- k-GNNs and Invariant Graph Networks are examples that can count complex substructures (e.g., triangles, cliques) that 1-WL and standard MPNNs cannot, bridging the expressiveness gap for molecular and social network analysis.
Practical Implications for Graph Learning
The WL-GNN equivalence has direct consequences for engineering graph ML solutions:
- Task Selection: Understanding that MPNNs are inherently local guides architecture choice. For tasks requiring global structure (e.g., detecting long-range interactions), higher-order models or explicit structural encodings are necessary.
- Feature Engineering: Node/edge features break WL equivalence. Rich, discriminative features can allow MPNNs to distinguish graphs that are structurally WL-equivalent.
- Evaluation Caution: Performance on standard benchmarks (like molecular datasets) must be interpreted through this lens. A model may perform well not by understanding complex topology, but by leveraging informative features.
- Beyond Isomorphism: Real-world tasks rarely require perfect isomorphism detection. The WL test provides a rigorous vocabulary for discussing what graph properties a given model can and cannot learn.
Connection to Graph Kernels & Synthetic Data
The WL test is the foundation for the Weisfeiler-Lehman Graph Kernel, a fast and effective method for graph comparison without training. For synthetic graph generation:
- Evaluation Metric: The WL kernel is used to measure the distributional similarity between sets of real and generated graphs, ensuring synthetic data captures essential topological properties.
- Expressiveness Target: Generative models like GraphVAEs or Graph Diffusion Models are evaluated on their ability to produce graphs that are not easily distinguishable from real graphs by WL-based metrics.
- Controlled Generation: Understanding WL equivalence allows for the targeted generation of graphs that are structurally distinct (WL-distinguishable) or equivalent (WL-equivalent) for stress-testing GNN robustness and studying out-of-distribution generalization.
Frequently Asked Questions
The Weisfeiler-Lehman (WL) test is a foundational algorithm in graph theory and machine learning. These questions address its core mechanics, its critical relationship to Graph Neural Networks (GNNs), and its practical applications in modern AI systems.
The Weisfeiler-Lehman (WL) test is a classical, iterative algorithm for testing graph isomorphism—the problem of determining whether two graphs are structurally identical. It operates by iteratively coloring or labeling nodes based on the multiset of colors in their immediate neighborhood, refining the partition of nodes in each graph. If, after a number of iterations, the histograms of node colors differ between the two graphs, they are declared non-isomorphic; however, if the colorings become stable and match, the graphs are possibly isomorphic (the test is necessary but not sufficient for a definitive isomorphism guarantee). Its computational efficiency and intuitive mechanism have made it a cornerstone for analyzing the expressive power of Graph Neural Networks (GNNs).
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
The Weisfeiler-Lehman (WL) test is a cornerstone in graph theory with profound implications for modern Graph Neural Networks. These related concepts connect its theoretical foundations to practical algorithms and models.
Graph Isomorphism
Graph isomorphism is the problem of determining whether two graphs are structurally identical, meaning there exists a bijection (one-to-one mapping) between their node sets that preserves adjacency. The WL test is a classical, efficient heuristic for this NP-intermediate problem.
- It provides a necessary but not sufficient condition for isomorphism; non-isomorphic graphs that pass the test are called WL-indistinguishable or cospectral.
- This problem is fundamental for validating the expressive power of Graph Neural Networks, as a model that cannot distinguish non-isomorphic graphs has inherent limitations.
Graph Isomorphism Network (GIN)
The Graph Isomorphism Network (GIN) is a Graph Neural Network architecture specifically designed to match the expressive power of the 1-dimensional Weisfeiler-Lehman (1-WL) graph isomorphism test. It achieves this through an injective multiset aggregation function.
- Its update rule is:
h_v^(k) = MLP^(k)((1 + ε^(k)) * h_v^(k-1) + Σ_{u ∈ N(v)} h_u^(k-1)). - By using a multi-layer perceptron (MLP) and a learnable parameter
ε, GIN can model injective functions, making it as powerful as the 1-WL test in distinguishing graph structures. - This theoretical grounding makes GIN a maximally expressive GNN under the 1-WL framework, often used as a baseline for graph classification tasks.
Message Passing
Message passing is the fundamental, iterative computational framework underpinning most Graph Neural Networks, directly analogous to the neighborhood aggregation step in the WL test. In each layer, nodes:
- Aggregate information (messages) from their neighboring nodes.
- Update their own representation by combining this aggregated information with their previous state.
- The WL test can be viewed as a simple, non-learnable form of message passing where the "message" is a node color and aggregation is a hashed multiset of neighbor colors.
- The expressiveness of a GNN is bounded by the WL test if its aggregation function is not injective (i.e., it can map different multisets of neighbor features to the same representation).
k-Dimensional WL Test (k-WL)
The k-dimensional Weisfeiler-Lehman test (k-WL) is a hierarchy of more powerful algorithms for graph isomorphism testing, generalizing the classic 1-WL test. Instead of coloring single nodes, it colors k-tuples of nodes.
- 1-WL (the standard test) colors individual nodes.
- 2-WL colors pairs of nodes, offering strictly greater discriminative power. It can distinguish some graphs that 1-WL cannot.
- Higher-order k-WL tests are increasingly powerful but computationally expensive (time complexity O(n^k)).
- This hierarchy establishes a theoretical ceiling for higher-order GNNs, which attempt to mimic k-WL test expressiveness through more complex tensor-based operations.
Permutation Invariance
Permutation invariance is a critical property required for any function operating on graph-structured data. It means the function's output is unchanged regardless of the arbitrary ordering (permutation) of the input nodes.
- The WL test is inherently permutation invariant because it operates on unordered multisets of neighbor colors.
- Graph Neural Networks enforce this property by using permutation-invariant aggregation functions like sum, mean, or max. The choice of aggregator affects both the model's expressiveness (its relationship to the WL test) and its inductive biases.
- A model that is not permutation invariant would be learning from an artificial artifact (node ID ordering) rather than the true graph structure.
Graph Kernel
A graph kernel is a function that measures the similarity between two graphs, enabling kernel-based machine learning methods (like SVMs) to be applied to graph-structured data. The WL test directly inspired one of the most successful families of graph kernels.
- The Weisfeiler-Lehman Subtree Kernel uses the color refinement sequence of the 1-WL test. At each iteration, it counts the occurrences of each node color, creating a histogram for the graph. The kernel similarity is the dot product of these histograms across iterations.
- This provides a computationally efficient way to capture increasingly large neighborhood substructures, bridging classical graph theory with kernel methods.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us