AlterLab-Academic-Skills alterlab-torch-geometric
Graph Neural Networks with PyTorch Geometric (PyG) — node and graph classification, link prediction, GCN, GAT, and GraphSAGE layers, heterogeneous graphs, and molecular property prediction. Use when building or training GNNs for geometric deep learning on graph-structured data. Part of the AlterLab Academic Skills suite.
git clone https://github.com/AlterLab-IEU/AlterLab-Academic-Skills
T=$(mktemp -d) && git clone --depth=1 https://github.com/AlterLab-IEU/AlterLab-Academic-Skills "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/data-science/alterlab-torch-geometric" ~/.claude/skills/alterlab-ieu-alterlab-academic-skills-alterlab-torch-geometric && rm -rf "$T"
skills/data-science/alterlab-torch-geometric/SKILL.mdPyTorch Geometric (PyG)
Overview
PyTorch Geometric is a library built on PyTorch for developing and training Graph Neural Networks (GNNs). Apply this skill for deep learning on graphs and irregular structures, including mini-batch processing, multi-GPU training, and geometric deep learning applications.
When to Use This Skill
This skill should be used when working with:
- Graph-based machine learning: Node classification, graph classification, link prediction
- Molecular property prediction: Drug discovery, chemical property prediction
- Social network analysis: Community detection, influence prediction
- Citation networks: Paper classification, recommendation systems
- 3D geometric data: Point clouds, meshes, molecular structures
- Heterogeneous graphs: Multi-type nodes and edges (e.g., knowledge graphs)
- Large-scale graph learning: Neighbor sampling, distributed training
Quick Start
uv pip install torch_geometric
Graphs are
torch_geometric.data.Data objects: x (node features [N, F]), edge_index
(connectivity in COO [2, E]), optional edge_attr, y, pos, and any custom attribute
(train_mask, etc.). DataLoader batches multiple graphs into one block-diagonal graph
(no padding); a batch vector maps nodes back to their source graph.
Full install/sparse-deps, basic graph creation, benchmark loading, edge-index format, and mini-batching details:
references/getting_started.md.
Core Workflow
- Load or build data — benchmark datasets, custom
, or from CSV (InMemoryDataset
; full catalog inreferences/datasets_and_loading.md
).references/datasets_reference.md - Define a GNN — stack pre-built conv layers (GCNConv, GATConv, SAGEConv) or subclass
for custom layers (MessagePassing
; full layer list inreferences/building_gnns.md
).references/layers_reference.md - Train — node classification (single graph, train/test masks), graph classification
(
+ global pooling), or large-scale viaDataLoader
neighbor sampling (NeighborLoader
).references/training_workflows.md - Go advanced if needed —
/HeteroData
for heterogeneous graphs, transforms,to_hetero
explainability, hierarchical pooling, GPU, save/load (GNNExplainer
; transforms catalog inreferences/advanced_features.md
).references/transforms_reference.md
Building GNNs (at a glance)
GNNs follow neighborhood aggregation: transform node features → propagate messages along edges → aggregate from neighbors → update representations. PyG ships 40+ conv layers. When choosing one, check its capabilities: SparseTensor support,
edge_weight, edge_attr, bipartite, and lazy
(-1 channel) initialization. Code for GCN/GAT/GraphSAGE and custom MessagePassing layers
(including the _i/_j target/source naming convention) is in references/building_gnns.md.
Resources
Bundled References
This skill includes detailed reference documentation:
: Install, basic graph creation,references/getting_started.md
structure, edge-index format, mini-batchingData
: Message passing, GCN/GAT/GraphSAGE code, customreferences/building_gnns.md
layers, layer capabilitiesMessagePassing
: Built-in datasets, customreferences/datasets_and_loading.md
, loading graphs from CSVInMemoryDataset
: Node classification, graph classification, large-scale neighbor samplingreferences/training_workflows.md
: Heterogeneous graphs, transforms, explainability, pooling, GPU, save/loadreferences/advanced_features.md
: Complete listing of all 40+ GNN layers with descriptions and capabilitiesreferences/layers_reference.md
: Comprehensive dataset catalog organized by categoryreferences/datasets_reference.md
: All available transforms and their use casesreferences/transforms_reference.md
Scripts
Utility scripts are provided in
scripts/:
: Visualize graph structure using networkx and matplotlibscripts/visualize_graph.py
: Generate boilerplate code for common GNN architecturesscripts/create_gnn_template.py
: Benchmark model performance on standard datasetsscripts/benchmark_model.py
Execute scripts directly or read them for implementation patterns.