How vgsatorras/egnn works
1. What this repo is
- This is the official PyTorch 1.7.1 implementation of E(n)-Equivariant Graph Neural Networks (EGNNs).
- The codebase is organized around a shared equivariant graph model core plus three experiment tracks: N-body dynamics, graph autoencoding, and QM9 molecular property prediction.
2. Main entry points
- main_nbody.py trains and evaluates models on the N-body system task.
- main_ae.py runs the graph autoencoder experiments.
- main_qm9.py runs molecular property regression on QM9.
- eval.py, graph.py, utils.py, and losess.py provide shared evaluation, graph-building, utilities, and loss logic used across experiments.
3. Core model layer
- models/egnn_clean/egnn_clean.py is the clean, minimal EGNN implementation highlighted in the README example.
- models/ae.py wraps EGNN-style blocks for autoencoder use cases.
- models/gcl.py contains graph convolution / message-passing building blocks used by some baselines or variants.
- The core abstraction is a graph network that updates node features and coordinates jointly while preserving E(n)-equivariance.
4. Autoencoder pipeline
- ae_datasets/ contains dataset creation, selection, and dataloading for the graph autoencoder experiments.
- These datasets include synthetic graph families such as Erdős–Rényi and community graphs, matching the README commands.
- Data flows from dataset generation/selection into a graph autoencoder model, then into reconstruction-style losses and evaluation.
5. N-body dynamics pipeline
- n_body_system/ is a self-contained experiment package for learning particle dynamics.
- n_body_system/dataset/ generates synthetic simulations via generate_dataset.py and synthetic_sim.py.
- n_body_system/dataloader.py and n_body_system/dataset_nbody.py turn those simulations into training batches.
- n_body_system/model.py and n_body_system/post_process.py handle experiment-specific modeling and output handling.
6. Alternative equivariant baselines for N-body
- n_body_system/se3_dynamics/ packages a more complex SE(3)-equivariant stack for comparison baselines.
- It includes dynamics.py, models.py, and an equivariant_attention/ subpackage, plus copied SE3CNN-related utilities under from_se3cnn/.
- This is a separate model family from EGNN, used to compare against TFN / SE3 Transformer-style approaches.
7. QM9 molecular property pipeline
- qm9/ contains the dataset and model code for predicting molecular properties on QM9.
- qm9/data/prepare/ includes download and preprocessing scripts, while qm9/data/ and qm9/dataset.py define the actual data loading path.
- qm9/models.py, qm9/utils.py, and qm9/args.py support training configuration and model setup for the molecular regression experiments.
8. Data preparation boundaries
- This repo separates raw data generation/preprocessing from training-time loading.
- N-body uses synthetic simulation generation inside the repo.
- QM9 uses dedicated download/process scripts.
- Autoencoder experiments use internal synthetic graph datasets created by ae_datasets/.
- That separation is important for an architecture diagram: generation/prep sits upstream of dataloaders, which sit upstream of model training.
9. Shared execution pattern
- Across tasks, the flow is essentially: prepare dataset → build graph batches → feed nodes/edges/coordinates into model → compute task-specific loss → evaluate.
- The main difference between task tracks is the structure of the input graph and the output objective:
- N-body: dynamics prediction
- Autoencoder: graph reconstruction / latent modeling
- QM9: property regression
10. Supporting utilities and organization
- graph.py likely centralizes graph construction / edge handling.
- utils.py and qm9/utils.py provide generic helpers and task-specific utilities.
- n_body_system/se3_dynamics/utils/ and the from_se3cnn subtree are vendor-style support code for the SE(3) baseline.
- Overall, the repo is split cleanly into core equivariant model code and task-specific experiment packages rather than a single monolithic application.
Main entry points: main_qm9.py QM9 entry · main_ae.py AE entry · main_nbody.py N-body entry · ae.py AE model
Components 27
Shared core
Repository-wide graph utilities, losses, evaluation, and EGNN building blocks.
- Graph utils · Shared graph construction and edge handling.
graph.py - Losses · Shared loss functions used across tasks.
losess.py - Eval · Shared evaluation helpers.
eval.py - Utils · General utility functions.
utils.py - EGNN core · Minimal E(n)-equivariant graph network implementation.
models/egnn_clean/egnn_clean.py - GCL blocks · Graph convolution and message-passing building blocks.
models/gcl.py
Autoencoder
Synthetic graph autoencoding experiments built on EGNN-style models.
- AE entry · Launches graph autoencoder experiments.
main_ae.py - AE model · Autoencoder-specific EGNN wrapper and blocks.
models/ae.py - Dataset creator · Builds synthetic graph datasets for autoencoding.
ae_datasets/d_creator.py - Dataset selector · Selects graph families and dataset variants.
ae_datasets/d_selector.py - AE dataloader · Batches synthetic graphs for training.
ae_datasets/dataloader.py
N-body
Synthetic particle-dynamics experiments and an alternative SE(3) baseline stack.
- N-body entry · Launches the particle-dynamics experiment.
main_nbody.py - N-body data · Turns simulations into training examples.
n_body_system/dataset_nbody.py - N-body loader · Constructs batches for N-body training.
n_body_system/dataloader.py - N-body model · Task-specific dynamics model for particle prediction.
n_body_system/model.py - Post-process · Handles experiment outputs and result formatting.
n_body_system/post_process.py - SE(3) dynamics · Alternative equivariant dynamics stack for N-body baselines.
n_body_system/se3_dynamics/dynamics.py - SE(3) models · SE(3)-equivariant model definitions and components.
n_body_system/se3_dynamics/models.py
QM9
Molecular property regression pipeline for QM9.
- QM9 entry · Launches molecular property regression runs.
main_qm9.py - QM9 data · QM9 dataset definitions and loading path.
qm9/data/dataset.py - QM9 collate · Collates molecular examples into batches.
qm9/data/collate.py - QM9 model · Models for molecular property prediction.
qm9/models.py - QM9 args · Training and model configuration arguments.
qm9/args.py - QM9 utils · QM9-specific utility functions.
qm9/utils.py
Data prep
Upstream dataset generation and preprocessing utilities.
- Sim generator · Generates synthetic N-body simulation data.
n_body_system/dataset/generate_dataset.py - Synthetic sim · Defines the particle-system simulation process.
n_body_system/dataset/synthetic_sim.py - QM9 prep · Download and preprocessing scripts for QM9.
qm9/data/prepare/process.py
Connections 32
- N-body entry → N-body loader: loads batches · Main training script feeds the N-body dataloader.
- N-body entry → N-body model: trains · Main training script instantiates the N-body model.
- N-body entry → Eval: evaluates · Uses shared evaluation helpers.
- N-body entry → Losses: optimizes · Uses shared losses for the dynamics objective.
- AE entry → AE dataloader: loads graphs · Main AE script consumes synthetic graph batches.
- AE entry → AE model: trains · Main AE script instantiates the autoencoder model.
- AE entry → Losses: optimizes · Uses reconstruction-style losses.
- AE entry → Eval: evaluates · Uses shared evaluation helpers.
- QM9 entry → QM9 data: loads molecules · Main QM9 script consumes prepared molecular data.
- QM9 entry → QM9 model: trains · Main QM9 script instantiates regression models.
- QM9 entry → QM9 args: configures · Reads task-specific training arguments.
- QM9 entry → QM9 utils: uses · Uses QM9-specific helpers.
- QM9 entry → Eval: evaluates · Uses shared evaluation helpers.
- Graph utils → AE dataloader: builds graphs · Shared graph construction supports AE batching.
- Graph utils → N-body loader: builds graphs · Shared graph construction supports N-body batching.
- Graph utils → QM9 data: builds graphs · Shared graph construction supports QM9 data handling.
- Dataset selector → Dataset creator: selects · Chooses which synthetic graph families to generate.
- Dataset creator → AE dataloader: feeds · Generated datasets are batched for training.
- AE dataloader → AE model: input · Graph batches flow into the AE model.
- AE model → EGNN core: uses core · AE wrapper is built on the EGNN core.
- AE model → GCL blocks: uses blocks · May reuse graph convolution/message-passing blocks.
- Sim generator → Synthetic sim: simulates · Dataset generation is driven by the particle simulator.
- Synthetic sim → N-body data: produces data · Simulation output becomes training examples.
- N-body data → N-body loader: batches · Dataset is converted into batches.
- N-body loader → N-body model: input · Batched trajectories are consumed by the model.
- N-body model → Post-process: outputs · Model predictions are post-processed for reporting.
- SE(3) dynamics → SE(3) models: uses · Baseline dynamics stack is assembled from SE(3) models.
- QM9 prep → QM9 data: prepares · Preprocessing feeds the dataset layer.
- QM9 data → QM9 collate: batches · Dataset examples are collated for training.
- QM9 collate → QM9 model: input · Batched molecules flow into the regression model.
- QM9 model → EGNN core: uses core · QM9 models can build on the shared equivariant core.
- QM9 model → Utils: helpers · May reuse general helper functions.