This repository contains the official code to reproduce the experimental results from the paper:
Learning to Execute Graph Algorithms Exactly with Graph Neural Networks
The codebase covers verification of algorithmic instructions, training the proposed Graph Neural Network (GNN), ablation studies, and theoretical/numerical bounds, as reported in the paper.
First, download and extract the ZIP file containing this repository. Then navigate to the extracted folder:
unzip graph_algorithms.zip
cd graph_algorithmsWe provide a Conda environment specification to ensure reproducibility.
conda env create -f environment.yml
conda activate exact-learningTo verify the correctness of flooding instructions for graphs on 1000 randomly generated graphs with:
- Maximum degree:
D - Number of nodes:
n ∈ [5, 20]
Run the following:
cd validate_flooding_graphs- Open
validate_flooding.sh - Choose
D ∈ {2, 3, 4}(other values ofDare also supported) - Save the file
- Run:
bash validate_flooding.shTo verify flooding instructions on trees:
cd validate_flooding_trees-
Open
validate_flooding.sh -
Set
n = 7(number of nodes). The test set includes all labeled trees withn = 7nodes.- Other values of
n ≥ 2are also supported.
- Other values of
-
Choose:
- Maximum degree
D ∈ {2, 3, 4}(other values are also possible) - Desired message bit precision
- Maximum degree
-
Save the file
-
Run:
bash validate_flooding.shTo train the proposed GNN for executing flooding on graphs with maximum degree D:
cd training_flooding_graphs- Choose
D ∈ {2, 3, 4}(anyD ≥ 2is supported) - Run:
bash train_flooding.shEvaluation setup:
While training the code will test on:
- 1000 randomly generated test graphs
- Maximum degree
D - Number of nodes
n ∈ [5, 20]
To train the proposed GNN for executing flooding on trees:
cd training_flooding_trees-
Choose:
- Maximum degree
D ∈ {2, 3, 4}(other values supported) - Desired message bit precision
- Maximum degree
-
Run:
bash train_flooding.shEvaluation setup:
While training the code will test on:
- All labeled trees with
n = 7nodes and maximum degreeD - Other values of
n ≥ 2are supported
To verify the correctness of instructions for BFS, DFS, and Bellman–Ford on 100 randomly generated graphs with:
- Number of nodes:
n ∈ [2, 7] - Maximum degree:
D ∈ [1, 3] - Edge weights:
w ∈ [0, 3](Bellman–Ford only)
Navigate to:
cd validate_othersRun the following scripts:
python validate_bellman_ford.py
python validate_bfs.py
python validate_dfs.pyNavigate to:
cd ablationThis experiment studies:
-
Using vs. not using orthogonal encoding at the input
-
Applying the Heaviside function:
- Before aggregation
- After aggregation
- Not using it at all
Compared against the main proposed GNN:
python ablation_experiment.pyTo study the effect of collisions in templates and how the cascade chain mechanism mitigates them:
python collision_experiment.pyNavigate to:
cd boundsTo compute theoretical and numerical bounds when the maximum degree D is fixed and message length ℓ varies:
python bounds_ell.pyTo compute bounds for fixed ℓ and varying D:
python bounds_D.py- All scripts are designed to reproduce the results reported in the paper.
- Most parameters (e.g.,
D,n, bit precision) can be modified directly in the provided.shor.pyfiles. - For large configurations, experiments may be computationally expensive.
- For training experiments, you will need a cuda enabled GPU