# wanifarooq/glnbench architecture

> Architecture diagram of the GitHub repository wanifarooq/glnbench, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/wanifarooq/glnbench
- Repository: https://github.com/wanifarooq/glnbench

## Overview

#### Purpose and entry points
This is a Python benchmark framework for comparing 13 GNN label-noise robustness methods across graph datasets, noise models, backbones, and repeated runs. The production entry point is `main.py`, which expands YAML sweeps and incrementally executes missing runs. `main_multithreading.py` runs a fixed-seed, multi-method comparison in parallel. Programmatic execution centers on `util/experiment.py`.

Paths: `main.py`, `main_multithreading.py`, `util/experiment.py`

#### Experiment orchestration and reproducibility
An experiment initializes deterministic run-specific seeds, selects CPU/CUDA, derives output/checkpoint locations, and coordinates the full lifecycle. Sweep expansion, configuration hashing, completion detection, and aggregation support resumable multi-run benchmarks. Each run emits per-epoch logs and optionally checkpoints; aggregate results are persisted by the top-level runner.

Paths: `main.py`, `sweep_utils.py`, `util/experiment.py`

#### Data ingestion, split boundaries, and label corruption
Dataset loading/preprocessing creates PyTorch Geometric graph data, uses supplied splits or deterministic generated masks, and downloads supported sources as needed. Noise injection modifies only train and validation labels while retaining clean labels and corruption masks for factual-versus-corrected analysis; test labels remain ground truth. Inductive mode partitions the graph into disconnected train/validation/test subgraphs, while default transductive mode exposes the full graph for message passing.

Paths: `util/data.py`, `util/noise.py`, `util/inductive.py`

#### Backbone and algorithm extension layers
`model/gnns.py` provides shared GCN, GIN, GAT, GATv2, GPS, and tuned modified-GCN backbones. Robustness algorithms are split into thin registered trainer wrappers and registered helper implementations: wrappers may host algorithm-specific model/loss components, while helpers own setup, optimization, train/validation/prediction, and embedding extraction. This two-registry design makes method selection configuration-driven.

Paths: `model/gnns.py`, `model/registry.py`, `methods/registry.py`

#### Unified training control plane
`TrainingLoop` invokes the selected helper over epochs, handling full-graph or compatible mini-batch training, early stopping, best-state restoration, periodic oversmoothing measurement, and final inference. The helper interface is the key boundary between common lifecycle behavior and method-specific learning logic. Unsupported methods remain full-batch for training but can use batched evaluation/inference.

Paths: `training/training_loop.py`, `training/early_stopping.py`, `methods/base_helper.py`

#### Sampling and runtime execution modes
When batching is configured, the sampler factory supplies PyG NeighborLoader, ClusterLoader, GraphSAINT, or RandomNode loaders. Batched inference scatters predictions/embeddings back to global node IDs; inductive execution instead evaluates within each partition and reconstructs global outputs. Material runtime dependencies are Python 3.10/3.11, PyTorch 2.2.1, PyTorch Geometric, and optional CUDA 11.8.

Paths: `util/graph_sampling.py`, `util/inductive.py`, `setup.sh`

#### Evaluation, profiling, and artifacts
Evaluation produces macro classification metrics for splits and clean/corrupted subsets, plus embedding-based oversmoothing metrics. Profiling captures inference/training FLOPs and timing; CodeCarbon can record emissions. Training logs, plots, best/per-epoch checkpoints, and aggregate experiment JSON are the durable interface to downstream analysis scripts.

Paths: `model/evaluation.py`, `util/profiling.py`, `util/plot.py`

Main entry points: [`training/training_loop.py`](https://github.com/wanifarooq/glnbench/blob/main/training/training_loop.py) (Training loop), [`util/experiment.py`](https://github.com/wanifarooq/glnbench/blob/main/util/experiment.py) (Experiment lifecycle), [`util/data.py`](https://github.com/wanifarooq/glnbench/blob/main/util/data.py) (Dataset ingestion), [`methods/base_helper.py`](https://github.com/wanifarooq/glnbench/blob/main/methods/base_helper.py) (Method helper interface)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_orchestration["Benchmark orchestration"]
  node_main["Sweep runner<br/>CLI entry point<br/>[main.py]"]
  node_parallel_runner["Parallel comparison runner<br/>CLI entry point"]
  node_sweep_utils["Sweep management<br/>configuration planner<br/>[sweep_utils.py]"]
  node_experiment{{"Experiment lifecycle<br/>execution coordinator<br/>[experiment.py]"}}
end

subgraph group_data["Data and corruption"]
  node_data_loader["Dataset ingestion<br/>PyG data pipeline<br/>[data.py]"]
  node_noise["Label corruption<br/>noise pipeline<br/>[noise.py]"]
  node_inductive["Inductive partitioning<br/>graph partition runtime<br/>[inductive.py]"]
end

subgraph group_learning["Learning runtime"]
  node_sampling["Sampler factory<br/>PyG loader factory<br/>[graph_sampling.py]"]
  node_backbones["GNN backbones<br/>model library<br/>[gnns.py]"]
  node_trainer_registry["Trainer registry<br/>method registry<br/>[registry.py]"]
  node_helper_registry["Helper registry<br/>method registry<br/>[registry.py]"]
  node_method_helper{{"Method helper interface<br/>learning contract<br/>[base_helper.py]"}}
  node_training_loop{{"Training loop<br/>common lifecycle controller<br/>[training_loop.py]"}}
  node_early_stopping["Early stopping<br/>training policy<br/>[early_stopping.py]"]
  node_runtime["Python / PyTorch runtime<br/>execution environment<br/>[setup.sh]"]
end

subgraph group_analysis["Evaluation and artifacts"]
  node_evaluation["Metrics evaluation<br/>classification analysis<br/>[evaluation.py]"]
  node_profiling["Runtime profiling<br/>performance analysis<br/>[profiling.py]"]
  node_plotting["Plots and logs<br/>artifact writer<br/>[plot.py]"]
  node_experiment_artifacts[("Experiment artifacts<br/>durable results")]
end

node_main -->|"expands and resumes"| node_sweep_utils
node_main -->|"executes runs"| node_experiment
node_parallel_runner -->|"parallel runs"| node_experiment
node_sweep_utils -->|"aggregates results"| node_experiment_artifacts
node_experiment -->|"loads graph data"| node_data_loader
node_data_loader -->|"clean split labels"| node_noise
node_data_loader -.->|"optional inductive mode"| node_inductive
node_experiment -->|"selects method wrapper"| node_trainer_registry
node_trainer_registry -->|"resolves helper"| node_helper_registry
node_helper_registry -->|"implements contract"| node_method_helper
node_experiment -->|"configures backbone"| node_backbones
node_experiment -.->|"configures batching"| node_sampling
node_noise -->|"corrupted training data"| node_training_loop
node_inductive -.->|"partitioned data"| node_training_loop
node_sampling -.->|"mini-batches"| node_training_loop
node_training_loop -->|"invokes learning steps"| node_method_helper
node_method_helper -->|"trains and predicts with"| node_backbones
node_training_loop -->|"applies policy"| node_early_stopping
node_training_loop -->|"final predictions and embeddings"| node_evaluation
node_training_loop -.->|"measures execution"| node_profiling
node_training_loop -->|"per-epoch logs"| node_plotting
node_evaluation -->|"metrics"| node_experiment_artifacts
node_profiling -->|"performance records"| node_experiment_artifacts
node_plotting -->|"logs and plots"| node_experiment_artifacts
node_training_loop -->|"checkpoints"| node_experiment_artifacts
node_runtime -->|"executes on"| node_experiment

click node_main "https://github.com/wanifarooq/glnbench/blob/main/main.py"
click node_parallel_runner "https://github.com/wanifarooq/glnbench/blob/main/main_multithreading.py"
click node_sweep_utils "https://github.com/wanifarooq/glnbench/blob/main/sweep_utils.py"
click node_experiment "https://github.com/wanifarooq/glnbench/blob/main/util/experiment.py"
click node_data_loader "https://github.com/wanifarooq/glnbench/blob/main/util/data.py"
click node_noise "https://github.com/wanifarooq/glnbench/blob/main/util/noise.py"
click node_inductive "https://github.com/wanifarooq/glnbench/blob/main/util/inductive.py"
click node_sampling "https://github.com/wanifarooq/glnbench/blob/main/util/graph_sampling.py"
click node_backbones "https://github.com/wanifarooq/glnbench/blob/main/model/gnns.py"
click node_trainer_registry "https://github.com/wanifarooq/glnbench/blob/main/model/registry.py"
click node_helper_registry "https://github.com/wanifarooq/glnbench/blob/main/methods/registry.py"
click node_method_helper "https://github.com/wanifarooq/glnbench/blob/main/methods/base_helper.py"
click node_training_loop "https://github.com/wanifarooq/glnbench/blob/main/training/training_loop.py"
click node_early_stopping "https://github.com/wanifarooq/glnbench/blob/main/training/early_stopping.py"
click node_evaluation "https://github.com/wanifarooq/glnbench/blob/main/model/evaluation.py"
click node_profiling "https://github.com/wanifarooq/glnbench/blob/main/util/profiling.py"
click node_plotting "https://github.com/wanifarooq/glnbench/blob/main/util/plot.py"
click node_runtime "https://github.com/wanifarooq/glnbench/blob/main/setup.sh"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_parallel_runner,node_sweep_utils,node_experiment toneBlue
class node_data_loader,node_noise,node_inductive toneAmber
class node_sampling,node_backbones,node_trainer_registry,node_helper_registry,node_method_helper,node_training_loop,node_early_stopping,node_runtime toneMint
class node_evaluation,node_profiling,node_plotting,node_experiment_artifacts toneRose
```

## Components

### Benchmark orchestration

- [Sweep runner](https://github.com/wanifarooq/glnbench/blob/main/main.py): CLI entry point · Expands YAML sweeps and resumes missing runs. · `main.py`
- [Parallel comparison runner](https://github.com/wanifarooq/glnbench/blob/main/main_multithreading.py): CLI entry point · Runs fixed-seed multi-method comparisons in parallel. · `main_multithreading.py`
- [Sweep management](https://github.com/wanifarooq/glnbench/blob/main/sweep_utils.py): configuration planner · Hashes configurations, detects completion, and aggregates runs. · `sweep_utils.py`
- [Experiment lifecycle](https://github.com/wanifarooq/glnbench/blob/main/util/experiment.py): execution coordinator · Sets seeds, device, locations, and coordinates each run. · `util/experiment.py`

### Data and corruption

- [Dataset ingestion](https://github.com/wanifarooq/glnbench/blob/main/util/data.py): PyG data pipeline · Loads, preprocesses, and creates deterministic graph splits. · `util/data.py`
- [Label corruption](https://github.com/wanifarooq/glnbench/blob/main/util/noise.py): noise pipeline · Corrupts train and validation labels while preserving clean labels and masks. · `util/noise.py`
- [Inductive partitioning](https://github.com/wanifarooq/glnbench/blob/main/util/inductive.py): graph partition runtime · Creates disconnected split subgraphs and reconstructs global outputs. · `util/inductive.py`

### Learning runtime

- [Sampler factory](https://github.com/wanifarooq/glnbench/blob/main/util/graph_sampling.py): PyG loader factory · Builds neighbor, cluster, GraphSAINT, or random-node loaders. · `util/graph_sampling.py`
- [GNN backbones](https://github.com/wanifarooq/glnbench/blob/main/model/gnns.py): model library · Provides shared GCN, GIN, GAT, GPS, and modified-GCN models. · `model/gnns.py`
- [Trainer registry](https://github.com/wanifarooq/glnbench/blob/main/model/registry.py): method registry · Selects registered algorithm trainer wrappers. · `model/registry.py`
- [Helper registry](https://github.com/wanifarooq/glnbench/blob/main/methods/registry.py): method registry · Selects registered method learning implementations. · `methods/registry.py`
- [Method helper interface](https://github.com/wanifarooq/glnbench/blob/main/methods/base_helper.py): learning contract · Owns setup, optimization, validation, prediction, and embeddings. · `methods/base_helper.py`
- [Training loop](https://github.com/wanifarooq/glnbench/blob/main/training/training_loop.py): common lifecycle controller · Runs epochs, early stopping, restoration, oversmoothing checks, and inference. · `training/training_loop.py`
- [Early stopping](https://github.com/wanifarooq/glnbench/blob/main/training/early_stopping.py): training policy · `training/early_stopping.py`
- [Python / PyTorch runtime](https://github.com/wanifarooq/glnbench/blob/main/setup.sh): execution environment · Uses Python, PyTorch, PyG, and optional CUDA. · `setup.sh`

### Evaluation and artifacts

- [Metrics evaluation](https://github.com/wanifarooq/glnbench/blob/main/model/evaluation.py): classification analysis · Calculates split and clean/corrupted macro metrics plus oversmoothing measures. · `model/evaluation.py`
- [Runtime profiling](https://github.com/wanifarooq/glnbench/blob/main/util/profiling.py): performance analysis · Captures FLOPs, timing, and optional emissions. · `util/profiling.py`
- [Plots and logs](https://github.com/wanifarooq/glnbench/blob/main/util/plot.py): artifact writer · Produces training logs and plots. · `util/plot.py`
- **Experiment artifacts**: durable results · Stores checkpoints and aggregate experiment JSON for downstream analysis.

## Connections

- Sweep runner → Sweep management: expands and resumes
- Sweep runner → Experiment lifecycle: executes runs
- Parallel comparison runner → Experiment lifecycle: parallel runs
- Sweep management → Experiment artifacts: aggregates results
- Experiment lifecycle → Dataset ingestion: loads graph data
- Dataset ingestion → Label corruption: clean split labels
- Dataset ingestion → Inductive partitioning: optional inductive mode
- Experiment lifecycle → Trainer registry: selects method wrapper
- Trainer registry → Helper registry: resolves helper
- Helper registry → Method helper interface: implements contract
- Experiment lifecycle → GNN backbones: configures backbone
- Experiment lifecycle → Sampler factory: configures batching
- Label corruption → Training loop: corrupted training data
- Inductive partitioning → Training loop: partitioned data
- Sampler factory → Training loop: mini-batches
- Training loop → Method helper interface: invokes learning steps
- Method helper interface → GNN backbones: trains and predicts with
- Training loop → Early stopping: applies policy
- Training loop → Metrics evaluation: final predictions and embeddings
- Training loop → Runtime profiling: measures execution
- Training loop → Plots and logs: per-epoch logs
- Metrics evaluation → Experiment artifacts: metrics
- Runtime profiling → Experiment artifacts: performance records
- Plots and logs → Experiment artifacts: logs and plots
- Training loop → Experiment artifacts: checkpoints
- Python / PyTorch runtime → Experiment lifecycle: executes on
