# vgsatorras/egnn architecture

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

- Interactive diagram: https://gitdiagram.com/vgsatorras/egnn
- Repository: https://github.com/vgsatorras/egnn

## Overview

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`](https://github.com/vgsatorras/egnn/blob/main/main_qm9.py) (QM9 entry), [`main_ae.py`](https://github.com/vgsatorras/egnn/blob/main/main_ae.py) (AE entry), [`main_nbody.py`](https://github.com/vgsatorras/egnn/blob/main/main_nbody.py) (N-body entry), [`models/ae.py`](https://github.com/vgsatorras/egnn/blob/main/models/ae.py) (AE model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_shared["Shared core"]
  node_graph["Graph utils<br/>graph ops<br/>[graph.py]"]
  node_losses["Losses<br/>objective<br/>[losess.py]"]
  node_eval["Eval<br/>[eval.py]"]
  node_utils["Utils<br/>helpers<br/>[utils.py]"]
  node_egnn["EGNN core<br/>equivariant model<br/>[egnn_clean.py]"]
  node_gcl["GCL blocks<br/>message passing<br/>[gcl.py]"]
end

subgraph group_ae["Autoencoder"]
  node_main_ae["AE entry<br/>training entry<br/>[main_ae.py]"]
  node_ae_model["AE model<br/>model wrapper<br/>[ae.py]"]
  node_ae_creator["Dataset creator<br/>synthetic data<br/>[d_creator.py]"]
  node_ae_selector["Dataset selector<br/>dataset selection<br/>[d_selector.py]"]
  node_ae_loader["AE dataloader<br/>batching<br/>[dataloader.py]"]
end

subgraph group_nbody["N-body"]
  node_main_nbody["N-body entry<br/>training entry<br/>[main_nbody.py]"]
  node_nbody_data["N-body data<br/>dataset<br/>[dataset_nbody.py]"]
  node_nbody_loader["N-body loader<br/>batching<br/>[dataloader.py]"]
  node_nbody_model["N-body model<br/>task model<br/>[model.py]"]
  node_nbody_post["Post-process<br/>output handling<br/>[post_process.py]"]
  node_se3_dyn["SE(3) dynamics<br/>baseline model<br/>[dynamics.py]"]
  node_se3_models["SE(3) models<br/>baseline model<br/>[models.py]"]
end

subgraph group_qm9["QM9"]
  node_main_qm9["QM9 entry<br/>training entry<br/>[main_qm9.py]"]
  node_qm9_data["QM9 data<br/>dataset<br/>[dataset.py]"]
  node_qm9_collate["QM9 collate<br/>batching<br/>[collate.py]"]
  node_qm9_model["QM9 model<br/>regression model<br/>[models.py]"]
  node_qm9_args["QM9 args<br/>config<br/>[args.py]"]
  node_qm9_utils["QM9 utils<br/>helpers<br/>[utils.py]"]
end

subgraph group_prep["Data prep"]
  node_nbody_gen["Sim generator<br/>simulation prep"]
  node_nbody_sim["Synthetic sim<br/>simulation<br/>[synthetic_sim.py]"]
  node_qm9_prep["QM9 prep<br/>data preparation<br/>[process.py]"]
end

node_main_nbody -->|"loads batches"| node_nbody_loader
node_main_nbody -->|"trains"| node_nbody_model
node_main_nbody -->|"evaluates"| node_eval
node_main_nbody -->|"optimizes"| node_losses
node_main_ae -->|"loads graphs"| node_ae_loader
node_main_ae -->|"trains"| node_ae_model
node_main_ae -->|"optimizes"| node_losses
node_main_ae -->|"evaluates"| node_eval
node_main_qm9 -->|"loads molecules"| node_qm9_data
node_main_qm9 -->|"trains"| node_qm9_model
node_main_qm9 -->|"configures"| node_qm9_args
node_main_qm9 -->|"uses"| node_qm9_utils
node_main_qm9 -->|"evaluates"| node_eval
node_graph -->|"builds graphs"| node_ae_loader
node_graph -->|"builds graphs"| node_nbody_loader
node_graph -->|"builds graphs"| node_qm9_data
node_ae_selector -->|"selects"| node_ae_creator
node_ae_creator -->|"feeds"| node_ae_loader
node_ae_loader -->|"input"| node_ae_model
node_ae_model -->|"uses core"| node_egnn
node_ae_model -->|"uses blocks"| node_gcl
node_nbody_gen -->|"simulates"| node_nbody_sim
node_nbody_sim -->|"produces data"| node_nbody_data
node_nbody_data -->|"batches"| node_nbody_loader
node_nbody_loader -->|"input"| node_nbody_model
node_nbody_model -->|"outputs"| node_nbody_post
node_se3_dyn -->|"uses"| node_se3_models
node_qm9_prep -->|"prepares"| node_qm9_data
node_qm9_data -->|"batches"| node_qm9_collate
node_qm9_collate -->|"input"| node_qm9_model
node_qm9_model -->|"uses core"| node_egnn
node_qm9_model -->|"helpers"| node_utils

click node_main_nbody "https://github.com/vgsatorras/egnn/blob/main/main_nbody.py"
click node_main_ae "https://github.com/vgsatorras/egnn/blob/main/main_ae.py"
click node_main_qm9 "https://github.com/vgsatorras/egnn/blob/main/main_qm9.py"
click node_graph "https://github.com/vgsatorras/egnn/blob/main/graph.py"
click node_losses "https://github.com/vgsatorras/egnn/blob/main/losess.py"
click node_eval "https://github.com/vgsatorras/egnn/blob/main/eval.py"
click node_utils "https://github.com/vgsatorras/egnn/blob/main/utils.py"
click node_egnn "https://github.com/vgsatorras/egnn/blob/main/models/egnn_clean/egnn_clean.py"
click node_ae_model "https://github.com/vgsatorras/egnn/blob/main/models/ae.py"
click node_gcl "https://github.com/vgsatorras/egnn/blob/main/models/gcl.py"
click node_ae_creator "https://github.com/vgsatorras/egnn/blob/main/ae_datasets/d_creator.py"
click node_ae_selector "https://github.com/vgsatorras/egnn/blob/main/ae_datasets/d_selector.py"
click node_ae_loader "https://github.com/vgsatorras/egnn/blob/main/ae_datasets/dataloader.py"
click node_nbody_gen "https://github.com/vgsatorras/egnn/blob/main/n_body_system/dataset/generate_dataset.py"
click node_nbody_sim "https://github.com/vgsatorras/egnn/blob/main/n_body_system/dataset/synthetic_sim.py"
click node_nbody_data "https://github.com/vgsatorras/egnn/blob/main/n_body_system/dataset_nbody.py"
click node_nbody_loader "https://github.com/vgsatorras/egnn/blob/main/n_body_system/dataloader.py"
click node_nbody_model "https://github.com/vgsatorras/egnn/blob/main/n_body_system/model.py"
click node_nbody_post "https://github.com/vgsatorras/egnn/blob/main/n_body_system/post_process.py"
click node_se3_dyn "https://github.com/vgsatorras/egnn/blob/main/n_body_system/se3_dynamics/dynamics.py"
click node_se3_models "https://github.com/vgsatorras/egnn/blob/main/n_body_system/se3_dynamics/models.py"
click node_qm9_prep "https://github.com/vgsatorras/egnn/blob/main/qm9/data/prepare/process.py"
click node_qm9_data "https://github.com/vgsatorras/egnn/blob/main/qm9/data/dataset.py"
click node_qm9_collate "https://github.com/vgsatorras/egnn/blob/main/qm9/data/collate.py"
click node_qm9_model "https://github.com/vgsatorras/egnn/blob/main/qm9/models.py"
click node_qm9_args "https://github.com/vgsatorras/egnn/blob/main/qm9/args.py"
click node_qm9_utils "https://github.com/vgsatorras/egnn/blob/main/qm9/utils.py"

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_graph,node_losses,node_eval,node_utils,node_egnn,node_gcl toneBlue
class node_main_ae,node_ae_model,node_ae_creator,node_ae_selector,node_ae_loader toneAmber
class node_main_nbody,node_nbody_data,node_nbody_loader,node_nbody_model,node_nbody_post,node_se3_dyn,node_se3_models toneMint
class node_main_qm9,node_qm9_data,node_qm9_collate,node_qm9_model,node_qm9_args,node_qm9_utils toneRose
class node_nbody_gen,node_nbody_sim,node_qm9_prep toneIndigo
```

## Components

### Shared core

Repository-wide graph utilities, losses, evaluation, and EGNN building blocks.

- [Graph utils](https://github.com/vgsatorras/egnn/blob/main/graph.py): graph ops · Shared graph construction and edge handling. · `graph.py`
- [Losses](https://github.com/vgsatorras/egnn/blob/main/losess.py): objective · Shared loss functions used across tasks. · `losess.py`
- [Eval](https://github.com/vgsatorras/egnn/blob/main/eval.py): evaluation · Shared evaluation helpers. · `eval.py`
- [Utils](https://github.com/vgsatorras/egnn/blob/main/utils.py): helpers · General utility functions. · `utils.py`
- [EGNN core](https://github.com/vgsatorras/egnn/blob/main/models/egnn_clean/egnn_clean.py): equivariant model · Minimal E(n)-equivariant graph network implementation. · `models/egnn_clean/egnn_clean.py`
- [GCL blocks](https://github.com/vgsatorras/egnn/blob/main/models/gcl.py): message passing · Graph convolution and message-passing building blocks. · `models/gcl.py`

### Autoencoder

Synthetic graph autoencoding experiments built on EGNN-style models.

- [AE entry](https://github.com/vgsatorras/egnn/blob/main/main_ae.py): training entry · Launches graph autoencoder experiments. · `main_ae.py`
- [AE model](https://github.com/vgsatorras/egnn/blob/main/models/ae.py): model wrapper · Autoencoder-specific EGNN wrapper and blocks. · `models/ae.py`
- [Dataset creator](https://github.com/vgsatorras/egnn/blob/main/ae_datasets/d_creator.py): synthetic data · Builds synthetic graph datasets for autoencoding. · `ae_datasets/d_creator.py`
- [Dataset selector](https://github.com/vgsatorras/egnn/blob/main/ae_datasets/d_selector.py): dataset selection · Selects graph families and dataset variants. · `ae_datasets/d_selector.py`
- [AE dataloader](https://github.com/vgsatorras/egnn/blob/main/ae_datasets/dataloader.py): batching · 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](https://github.com/vgsatorras/egnn/blob/main/main_nbody.py): training entry · Launches the particle-dynamics experiment. · `main_nbody.py`
- [N-body data](https://github.com/vgsatorras/egnn/blob/main/n_body_system/dataset_nbody.py): dataset · Turns simulations into training examples. · `n_body_system/dataset_nbody.py`
- [N-body loader](https://github.com/vgsatorras/egnn/blob/main/n_body_system/dataloader.py): batching · Constructs batches for N-body training. · `n_body_system/dataloader.py`
- [N-body model](https://github.com/vgsatorras/egnn/blob/main/n_body_system/model.py): task model · Task-specific dynamics model for particle prediction. · `n_body_system/model.py`
- [Post-process](https://github.com/vgsatorras/egnn/blob/main/n_body_system/post_process.py): output handling · Handles experiment outputs and result formatting. · `n_body_system/post_process.py`
- [SE(3) dynamics](https://github.com/vgsatorras/egnn/blob/main/n_body_system/se3_dynamics/dynamics.py): baseline model · Alternative equivariant dynamics stack for N-body baselines. · `n_body_system/se3_dynamics/dynamics.py`
- [SE(3) models](https://github.com/vgsatorras/egnn/blob/main/n_body_system/se3_dynamics/models.py): baseline model · SE(3)-equivariant model definitions and components. · `n_body_system/se3_dynamics/models.py`

### QM9

Molecular property regression pipeline for QM9.

- [QM9 entry](https://github.com/vgsatorras/egnn/blob/main/main_qm9.py): training entry · Launches molecular property regression runs. · `main_qm9.py`
- [QM9 data](https://github.com/vgsatorras/egnn/blob/main/qm9/data/dataset.py): dataset · QM9 dataset definitions and loading path. · `qm9/data/dataset.py`
- [QM9 collate](https://github.com/vgsatorras/egnn/blob/main/qm9/data/collate.py): batching · Collates molecular examples into batches. · `qm9/data/collate.py`
- [QM9 model](https://github.com/vgsatorras/egnn/blob/main/qm9/models.py): regression model · Models for molecular property prediction. · `qm9/models.py`
- [QM9 args](https://github.com/vgsatorras/egnn/blob/main/qm9/args.py): config · Training and model configuration arguments. · `qm9/args.py`
- [QM9 utils](https://github.com/vgsatorras/egnn/blob/main/qm9/utils.py): helpers · QM9-specific utility functions. · `qm9/utils.py`

### Data prep

Upstream dataset generation and preprocessing utilities.

- [Sim generator](https://github.com/vgsatorras/egnn/blob/main/n_body_system/dataset/generate_dataset.py): simulation prep · Generates synthetic N-body simulation data. · `n_body_system/dataset/generate_dataset.py`
- [Synthetic sim](https://github.com/vgsatorras/egnn/blob/main/n_body_system/dataset/synthetic_sim.py): simulation · Defines the particle-system simulation process. · `n_body_system/dataset/synthetic_sim.py`
- [QM9 prep](https://github.com/vgsatorras/egnn/blob/main/qm9/data/prepare/process.py): data preparation · Download and preprocessing scripts for QM9. · `qm9/data/prepare/process.py`

## Connections

- 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.
