GNNGEDAnalysis is a lightweight experiment wrapper for studying how graph neural
networks behave along graph edit distance (GED) paths. It trains graph
classification models with the simplegnn
framework, evaluates trained models
on original graph splits and generated GED path graphs, merges evaluation
artifacts, and runs post-hoc analyses for decision changes along edit paths.
The GED path graphs themselves are generated upstream by the
gedpaths repository (see
Generating the Pipeline Input with gedpaths)
and consumed here as PyTorch Geometric datasets.
- Train GNN classifiers for configured datasets and architectures.
- Evaluate trained models on train, validation, and GED path graph variants.
- Copy generated GED graph path datasets into the local data layout.
- Merge per-fold evaluation outputs into
results/all_results.csv. - Enrich merged results with GED metadata.
- Run experiment summaries and plots for edit-operation instability.
The full workflow consists of an upstream data-generation stage (in the
gedpaths repository) followed by six stages in this repository. Each
stage reads the output of the previous one:
Copies the generated path-graph datasets from the gedpaths results tree into
the local data layout. For every Paths_<STRATEGY> directory under the source
root it scans the mapping-method subdirectories (only F2 and Precomputed
are accepted) and copies each dataset folder that contains all three required
items:
processed/— the PyTorch Geometric dataset (data.pt),raw/— the raw-data folder created during conversion,<DB>_edit_paths_data.txt— the per-step edit-operation metadata.
The copy target is data/GEDGraphs/<METHOD>/<DB>_<STRATEGY>/, e.g.
../GNNGED/Results/Paths_d-E_d-IsoN/F2/MUTAG/ becomes
data/GEDGraphs/F2/MUTAG_d-E_d-IsoN/. Incomplete source folders are skipped
and reported. This stage runs automatically at the start of
evaluate_models.py (with --copy-skip-existing enabled by default), but can
also be run standalone.
The <DB>_edit_paths_data.txt file contains one edit operation per line in the
format
<source_graph_id> <step_id> <target_graph_id> <ELEMENT_TYPE> <ELEMENT> <OPERATION>
for example 0 1 2 EDGE 0--5 DELETE (parsed by utils/load_path_info.py and
by the evaluation/merge stages to attribute each intermediate path graph to an
edit operation such as EDGE INSERT, NODE DELETE, or NODE RELABEL).
For each selected dataset, loads configs/<DB>/main_config.yml into the
simplegnn FrameworkMain, preprocesses the original dataset (e.g. TUDataset,
downloaded automatically into data/TUDatasets/), trains every configured
architecture (GIN, GCN, GAT, GATv2, GraphSAGE — one config entry per
models_<GNN>.yml) across all cross-validation folds defined in the split
file, and evaluates validation performance. Trained model checkpoints and
training logs are written under the per-architecture results/<GNN>/ directory
configured in the YAML.
For every combination of dataset, path strategy, and GNN architecture:
-
Preprocesses both the original dataset (
main_config.yml) and the path graph dataset<DB>_<STRATEGY>(paths_config.yml, loaded fromdata/GEDGraphs/<METHOD>/), aligning path-graph node features with the original feature space. -
Loads the trained model checkpoint for each configuration and validation fold.
-
Runs inference on the train split, the validation split, and all path graphs (source graphs, intermediate edit-step graphs, and target graphs).
-
Saves per-fold tensors and a human-readable text dump to
results/<GNN>/path_evaluation/(configurable via--evaluation-folder):train_results_config<C>_val<V>_<DB>.ptvalidation_results_config<C>_val<V>_<DB>.ptpath_results_config<C>_val<V>_<DB>_<STRATEGY>.ptpath_results_config<C>_val<V>_<DB>_<STRATEGY>.txt
Each path-result row records the source graph id, edit step id, target graph id, the model output logits, and the edit operation applied at that step.
Walks the evaluation folders for all selected datasets, strategies, and
architectures, joins the per-fold train/validation/path outputs, and derives
per-row analysis columns such as predicted_label, true_label,
is_flipping (does the prediction change at this edit step), is_correct,
is_source/is_target, train/validation membership of path endpoints, and
endpoint-label agreement. The merged table is written to
results/all_results.csv (one row per graph and edit step, per fold, per
architecture, per strategy).
Joins results/all_results.csv with structural metadata recomputed from the
copied GED graph datasets under data/GEDGraphs/ (e.g. number of connected
components and cycle counts of length 3–6 per path graph) and writes
results/all_results_enriched.csv.
Consume the merged CSV and produce summary tables and plots, e.g. prediction
flips per edit-operation type (absolute, relative, combined), flip statistics,
and class-change heatmaps along edit paths. Outputs go to
results/Experiments/ and results/ExperimentsAdditional/ by default. Both
CLIs support filtering by dataset, GNN, path strategy, validation fold, path
split (train/validation), and correctness of path endpoints.
The input to this pipeline — the GED path graph datasets — is produced by the
gedpaths library (expected as a
sibling checkout at ../GNNGED). gedpaths builds on libGraph and GEDLIB to
compute graph edit
distance mappings between graph pairs and to materialize the intermediate
graphs along the corresponding edit paths.
The simplest way is the bundled experiment script (see the gedpaths README for
build prerequisites; the exact solvers such as F2 require GUROBI):
cd ../GNNGED
chmod u+x experiment.sh
./experiment.sh -db <DB> # e.g. ./experiment.sh -db MUTAG,NCI1For each dataset this runs, in order:
- Download the TU dataset (
python_src/data_loader.py) intoData/Graphs/<DB>/. - Compute GED mappings (
build/CreateMappings, default methodF2, 5000 graph pairs) intoResults/Mappings/<METHOD>/<DB>/(<DB>_ged_mapping.bin,<DB>_ged_mapping.csv,graph_ids.txt). - Validate mappings (
build/AnalyzeMappings). - Build edit paths (
build/CreatePaths) for the four path strategies intoResults/Paths_<STRATEGY>/<METHOD>/<DB>/. This produces the edit-path graphs (<DB>_edit_paths.bgf) and the edit-operation metadata file<DB>_edit_paths_data.txtrequired by this repository. - Compute path statistics (
build/AnalyzePaths). - Convert to PyTorch Geometric (
python_src/converter/bgf_to_pt.py), which createsprocessed/data.pt(and theraw/folder) inside eachResults/Paths_<STRATEGY>/<METHOD>/<DB>/directory. - Optional plotting and Weisfeiler–Leman analysis stages.
The four path strategies are:
| Strategy id | Meaning |
|---|---|
Rnd |
Random edit-operation order |
Rnd_d-IsoN |
Random order, delete isolated nodes |
i-E_d-IsoN |
Insert edges first, delete isolated nodes |
d-E_d-IsoN |
Delete edges first, delete isolated nodes |
After a successful gedpaths run, each dataset folder must contain the three
items checked by copy_ged_graphs.py:
../GNNGED/Results/Paths_<STRATEGY>/<METHOD>/<DB>/
|-- processed/ # PyTorch Geometric dataset (data.pt, ...)
|-- raw/ # raw-data folder from the conversion
`-- <DB>_edit_paths_data.txt # one edit operation per line
Only mapping methods F2 and Precomputed are picked up by the copy step;
other mapping directories are ignored.
Suppose you ran ./experiment.sh -db <DB> in the gedpaths repository for a new
dataset <DB>. To analyze it here:
-
Create the dataset config folder
configs/<DB>/(easiest: copy an existing one such asconfigs/MUTAG/and replace the dataset name):main_config.yml— one entry per architecture pointing atdata/TUDatasets/,results/<GNN>/,models_<GNN>.yml,parameters.yml, and the split file (for TU datasets:../SimpleGNN/repo/src/simplegnn/datasets/splits/tu_splits/<DB>_splits.json; custom split files live undersplits/).paths_config.yml— one entry per path strategy withname: "<DB>_<STRATEGY>",source: "path", anddata: "data/GEDGraphs/<METHOD>/"(matching the copy destination).parameters.ymlandmodels_<GNN>.yml— hyperparameters and architecture definitions (usually reusable as-is).
Note: The train/validation/test split file is the one input that is not produced by gedpaths. For the classical TU datasets, ready-made splits ship with SimpleGNN under
../SimpleGNN/repo/src/simplegnn/datasets/splits/tu_splits/<DB>_splits.json. For any other dataset you must provide a split JSON yourself (place it undersplits/in this repository and reference it frommain_config.ymlandpaths_config.yml; see the existing files insplits/for the expected format). Training, evaluation, and the train/validation columns in the merged results all depend on this file. -
Train the models on the original dataset:
python train_models.py --db <DB> --num_threads 4
-
Evaluate on the GED paths (this first copies
../GNNGED/Results/Paths_*intodata/GEDGraphs/automatically):python evaluate_models.py --db <DB> \ --path-strategy d-E_d-IsoN --path-strategy i-E_d-IsoN \ --num_threads 4
-
Merge the evaluation artifacts:
python analyze_evaluated_results.py --db <DB> --results-path results
-
Enrich (optional) and run the experiments:
python utils/enrich_all_results.py \ --input-csv results/all_results.csv \ --output-csv results/all_results_enriched.csv \ --ged-root data/GEDGraphs --overwrite python experiments.py --data-path results/all_results.csv \ --output-dir results/Experiments --dataset <DB>
.
|-- train_models.py # Training and validation evaluation CLI
|-- evaluate_models.py # Model and GED path evaluation CLI
|-- analyze_evaluated_results.py # Merge evaluation artifacts into CSV
|-- experiments.py # Main post-hoc experiment suite
|-- experiments_additional.py # Additional post-hoc experiment suite
|-- copy_ged_graphs.py # Copy GED path graphs from gedpaths output
|-- configs/ # Per-dataset experiment configs
|-- splits/ # Split artifacts for selected datasets
|-- tests/ # Pytest coverage for CLIs and utilities
|-- utils/ # Shared utilities (path info loader, enrichment, plotting)
|-- data/ # Local datasets and copied GED graph data
`-- results/ # Training, evaluation, and analysis output
Large or generated data is expected under data/, tmp/, results/, and
results_old/.
- Python 3.9 or newer.
simplegnn, either installed as a package or available at../SimpleGNN/repo/srcrelative to this repository.- Python packages used by the scripts:
click,joblib,torch,polars,pytest, and optionallymatplotlibfor plots. - For generating new input data: a sibling checkout of the
gedpathsrepository at../GNNGEDwith its C++ tools built (see itsINSTALLATION.md; exact GED solvers require GUROBI).
This repository does not currently include a requirements.txt or packaging
configuration. Install dependencies in the environment used for simplegnn.
git clone <repository-url>
cd GNNGEDAnalysis
python -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install click joblib torch polars pytest matplotlibIf simplegnn is not installed, clone the
SimpleGNN repository next to this
repository so that ../SimpleGNN/repo/src exists, or install it into the active
environment.
Experiment behavior is driven by YAML files under configs/<dataset>/:
main_config.yml: original dataset, model config, hyperparameters, split file, and results directory.paths_config.yml: GED path graph datasets for evaluation (one entry per path strategy, withsource: "path"and data rooted atdata/GEDGraphs/<METHOD>/).parameters.yml: optimizer, loss, batch size, learning rate, epochs, feature handling, and model-saving options.models_<algorithm>.yml: model architecture definitions for algorithms such asGIN,GCN,GAT,GATv2, andGraphSAGE.
Run commands from the repository root so relative paths in these configs resolve correctly.
Train the default dataset (MUTAG):
python train_models.py --num_threads 4Train one or more configured datasets:
python train_models.py --db MUTAG --db PTC_MR --num_threads 4Train every dataset with configs/<dataset>/main_config.yml:
python train_models.py --all --num_threads 4Evaluate the default dataset, path strategy, and algorithms:
python evaluate_models.py --num_threads 4Evaluate selected datasets, strategies, and algorithms:
python evaluate_models.py \
--db MUTAG \
--path-strategy d-E_d-IsoN \
--path-strategy i-E_d-IsoN \
--gnn-algorithm GIN \
--gnn-algorithm GCN \
--num_threads 4Before evaluation, evaluate_models.py copies GED graph datasets from
../GNNGED/Results into data/GEDGraphs by default. Override those paths when
needed:
python evaluate_models.py \
--copy-source-root /path/to/GNNGED/Results \
--copy-dest-root data/GEDGraphsThe copy step can also be run standalone:
python copy_ged_graphs.py --source-root ../GNNGED/Results --dest-root data/GEDGraphsMerge per-fold train, validation, and path outputs into a single CSV:
python analyze_evaluated_results.py --results-path resultsThe default output is:
results/all_results.csv
Add GED graph metadata to merged results:
python utils/enrich_all_results.py \
--input-csv results/all_results.csv \
--output-csv results/all_results_enriched.csv \
--ged-root data/GEDGraphs \
--overwriteRun the main experiment suite:
python experiments.py \
--data-path results/all_results.csv \
--output-dir results/ExperimentsRun the additional experiment suite:
python experiments_additional.py \
--data-path results/all_results.csv \
--output-dir results/ExperimentsAdditionalBoth experiment CLIs support filters such as --dataset, --gnn,
--path-strategy, --val-id, --path-split, and --correct-filter.
Training outputs are written under the results path configured in each
dataset's YAML files. Evaluation writes artifacts to the selected
--evaluation-folder under each algorithm results directory, for example:
results/GIN/path_evaluation/
|-- train_results_config0_val0_MUTAG.pt
|-- validation_results_config0_val0_MUTAG.pt
|-- path_results_config0_val0_MUTAG_d-E_d-IsoN.pt
`-- path_results_config0_val0_MUTAG_d-E_d-IsoN.txt
Post-hoc experiment outputs are written to results/Experiments and
results/ExperimentsAdditional by default.
Run the test suite:
python -m pytestRun a quick syntax check:
python -m py_compile \
train_models.py \
evaluate_models.py \
analyze_evaluated_results.py \
experiments.py \
experiments_additional.py \
copy_ged_graphs.py \
utils/*.py- The training and evaluation scripts validate requested dataset names against
configs/*/main_config.yml. --all_dbs_classicalinevaluate_models.pytargets the classical paper datasets listed in the script.- GED path evaluation expects path graph data with
processed/,raw/, and<dataset>_edit_paths_data.txtpresent for each copied dataset.