# chiragfalor/ultimate-puppi architecture

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

- Interactive diagram: https://gitdiagram.com/chiragfalor/ultimate-puppi
- Repository: https://github.com/chiragfalor/ultimate-puppi

## Overview

##### Project type and purpose
- This is a research-oriented machine-learning pipeline (not a web app) for pileup removal and secondary vertex prediction at CERN. It uses Graph Neural Networks implemented in PyTorch (.pt model files) to classify particles/events.
- The README confirms the workflow: data preprocessing → model training (with hyperparameter search) → model saving → inference and analysis.

##### High-level architecture components
A. Data Sources and Configuration
- Raw event files (external data storage, e.g., ROOT or CSV files)
- Configuration files (home_path.txt, hyperparameter_list.txt, .slurm job script)
B. Preprocessing Layer
- data_read.py / upuppi_v0_dataset.py: read and wrap raw data
- data_rearrange.py → reorder vertices by pt
- data_process.py / data_process_new.py → transform to graph-network input format
C. Dataset and Loader
- dataset_graph_loader.py / dense_graph_loader.py: build PyTorch datasets and DataLoaders for GNNs
D. Model Definitions (models/)
- Graph-based architectures: DynamicPointTransformer, Dynamic_GATv2, various custom GCNs/transformers
- A common model interface in models/model.py or modelv2.py
E. Training and Hyperparameter Search
- multiclass_train_model.py, classification_train_model.py, emb_train_model.py, transformer_train_model.py
- hyperparameter_search.py / hyperparameter_search_multiclass.py: drive training loops over parameter grid
- loss_functions.py, helper_functions.py: shared utilities and custom losses
- Job scheduling via job1.slurm for HPC clusters
F. Model Persistence
- Models are checkpointed as .pt files (e.g., best_model.pt in models/ or root) and param_dict.pkl
G. Inference and Prediction
- load_pred_save.py: load a checkpoint, run forward passes on new data, save predictions, plot metrics
- best_model_prediction_events.py: event-level probability outputs
H. Analysis and Visualization
- analyze_MET.py, analyze_data.py, analyze_model.py, roc_pt.py, visualize_embeddings.py
- Results stored under results/ with subfolders by experiment name
I. Utilities and Scripts
- check_consistency.py, debug.py, read_hyperparameters.py, retrain_model.py

##### Relationships and Data Flow
- Raw Data → Preprocessing Layer → Graph Dataset → Training Module
↳ Hyperparameter Search drives multiple training runs → Model Checkpoints
- Best Checkpoint + New Data → Inference Module → Prediction Files
- Prediction Files → Analysis & Visualization → Results Directory
- Configuration files feed all stages with paths and parameter values; SLURM script orchestrates training on cluster.

##### Architectural patterns and principles
- Pipeline pattern: linear data flow through distinct stages
- Modular design: separate scripts for data, models, training, inference, analysis
- Reuse of utilities: helper_functions.py and loss_functions.py are shared across scripts
- Configuration-driven: all hyperparameters and paths externalized into text files

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Data Sources & Configuration"
        DS1["Raw Data Storage (ROOT/CSV)"]:::external
        HP["home_path.txt"]:::config
        HPL["hyperparameter_list.txt"]:::config
        SL["job1.slurm"]:::config
    end

    subgraph "Preprocessing Layer"
        DR["data_read.py"]:::preproc
        UDS["upuppi_v0_dataset.py"]:::preproc
        DRA["data_rearrange.py"]:::preproc
        DP["data_process.py"]:::preproc
        DPN["data_process_new.py"]:::preproc
    end

    subgraph "Dataset & Loader"
        DGL["dataset_graph_loader.py"]:::dataset
        DNGL["dense_graph_loader.py"]:::dataset
    end

    subgraph "Model Definitions"
        M1["models/model.py"]:::modeldef
        M2["models/modelv2.py"]:::modeldef
        M3["models/modelv3.py"]:::modeldef
        DPT["models/DynamicPointTransformer.py"]:::modeldef
        DGT["models/Dynamic_GATv2.py"]:::modeldef
        PTC["models/Point_transformer_connect_all.py"]:::modeldef
        PTCV["models/Point_transformer_conv.py"]:::modeldef
        OTHER["...other architectures"]:::modeldef
    end

    subgraph "Training & Hyperparameter Search"
        CTM["classification_train_model.py"]:::training
        MTM["multiclass_train_model.py"]:::training
        ETM["emb_train_model.py"]:::training
        TTM["transformer_train_model.py"]:::training
        HPS["hyperparameter_search.py"]:::training
        HPSM["hyperparameter_search_multiclass.py"]:::training
        LF["loss_functions.py"]:::training
        HF["helper_functions.py"]:::training
        SL2["job1.slurm"]:::training
    end

    ModelStore["Model Persistence (.pt/.pkl)"]:::store

    subgraph "Inference & Prediction"
        LPS["load_pred_save.py"]:::inference
        BMP["best_model_prediction_events.py"]:::inference
    end

    subgraph "Analysis & Visualization"
        AMET["analyze_MET.py"]:::analysis
        ADA["analyze_data.py"]:::analysis
        AMOD["analyze_model.py"]:::analysis
        ROC["roc_pt.py"]:::analysis
        VE["visualize_embeddings.py"]:::analysis
    end

    subgraph "Utilities & Miscellaneous"
        CC["check_consistency.py"]:::utils
        DBG["debug.py"]:::utils
        RHP["read_hyperparameters.py"]:::utils
        RTM["retrain_model.py"]:::utils
    end

    %% Data flow
    DS1 --> DR
    DR --> UDS --> DRA --> DP --> DPN --> DGL --> DNGL --> CTM
    MTM --> ModelStore
    CTM --> ModelStore
    ETM --> ModelStore
    TTM --> ModelStore
    HPS --> CTM
    HPSM --> MTM
    ModelStore --> LPS --> AMET
    ModelStore --> BMP --> AMET

    %% Config & orchestration
    HP -.-> DR
    HP -.-> UDS
    HPL -.-> HPS
    SL -.-> HPS
    SL -.-> SL2

    %% Utilities connections
    CC -.-> DR
    CC -.-> DGL
    CC -.-> CTM
    CC -.-> LPS
    CC -.-> AMET
    DBG -.-> DR
    DBG -.-> CTM
    RHP -.-> HPS
    RTM -.-> CTM

    %% Click events
    click HP "https://github.com/chiragfalor/ultimate-puppi/blob/main/home_path.txt"
    click HPL "https://github.com/chiragfalor/ultimate-puppi/blob/main/hyperparameter_list.txt"
    click SL "https://github.com/chiragfalor/ultimate-puppi/blob/main/job1.slurm"
    click DR "https://github.com/chiragfalor/ultimate-puppi/blob/main/data_read.py"
    click UDS "https://github.com/chiragfalor/ultimate-puppi/blob/main/upuppi_v0_dataset.py"
    click DRA "https://github.com/chiragfalor/ultimate-puppi/blob/main/data_rearrange.py"
    click DP "https://github.com/chiragfalor/ultimate-puppi/blob/main/data_process.py"
    click DPN "https://github.com/chiragfalor/ultimate-puppi/blob/main/data_process_new.py"
    click DGL "https://github.com/chiragfalor/ultimate-puppi/blob/main/dataset_graph_loader.py"
    click DNGL "https://github.com/chiragfalor/ultimate-puppi/blob/main/dense_graph_loader.py"
    click M1 "https://github.com/chiragfalor/ultimate-puppi/blob/main/models/model.py"
    click M2 "https://github.com/chiragfalor/ultimate-puppi/blob/main/models/modelv2.py"
    click M3 "https://github.com/chiragfalor/ultimate-puppi/blob/main/models/modelv3.py"
    click DPT "https://github.com/chiragfalor/ultimate-puppi/blob/main/models/DynamicPointTransformer.py"
    click DGT "https://github.com/chiragfalor/ultimate-puppi/blob/main/models/Dynamic_GATv2.py"
    click PTC "https://github.com/chiragfalor/ultimate-puppi/blob/main/models/Point_transformer_connect_all.py"
    click PTCV "https://github.com/chiragfalor/ultimate-puppi/blob/main/models/Point_transformer_conv.py"
    click CTM "https://github.com/chiragfalor/ultimate-puppi/blob/main/classification_train_model.py"
    click MTM "https://github.com/chiragfalor/ultimate-puppi/blob/main/multiclass_train_model.py"
    click ETM "https://github.com/chiragfalor/ultimate-puppi/blob/main/emb_train_model.py"
    click TTM "https://github.com/chiragfalor/ultimate-puppi/blob/main/transformer_train_model.py"
    click HPS "https://github.com/chiragfalor/ultimate-puppi/blob/main/hyperparameter_search.py"
    click HPSM "https://github.com/chiragfalor/ultimate-puppi/blob/main/hyperparameter_search_multiclass.py"
    click LF "https://github.com/chiragfalor/ultimate-puppi/blob/main/loss_functions.py"
    click HF "https://github.com/chiragfalor/ultimate-puppi/blob/main/helper_functions.py"
    click SL2 "https://github.com/chiragfalor/ultimate-puppi/blob/main/job1.slurm"
    click LPS "https://github.com/chiragfalor/ultimate-puppi/blob/main/load_pred_save.py"
    click BMP "https://github.com/chiragfalor/ultimate-puppi/blob/main/best_model_prediction_events.py"
    click AMET "https://github.com/chiragfalor/ultimate-puppi/blob/main/analyze_MET.py"
    click ADA "https://github.com/chiragfalor/ultimate-puppi/blob/main/analyze_data.py"
    click AMOD "https://github.com/chiragfalor/ultimate-puppi/blob/main/analyze_model.py"
    click ROC "https://github.com/chiragfalor/ultimate-puppi/blob/main/roc_pt.py"
    click VE "https://github.com/chiragfalor/ultimate-puppi/blob/main/visualize_embeddings.py"
    click CC "https://github.com/chiragfalor/ultimate-puppi/blob/main/check_consistency.py"
    click DBG "https://github.com/chiragfalor/ultimate-puppi/blob/main/debug.py"
    click RHP "https://github.com/chiragfalor/ultimate-puppi/blob/main/read_hyperparameters.py"
    click RTM "https://github.com/chiragfalor/ultimate-puppi/blob/main/retrain_model.py"

    %% Styles
    classDef config fill:#FFE4B5,stroke:#CC8400
    classDef external fill:#F0F0F0,stroke:#999999,stroke-dasharray: 5 5
    classDef preproc fill:#ADD8E6,stroke:#0366d6
    classDef dataset fill:#B3E5FC,stroke:#0277BD
    classDef modeldef fill:#E1BEE7,stroke:#6A1B9A
    classDef training fill:#C8E6C9,stroke:#2E7D32
    classDef store fill:#FFF59D,stroke:#F9A825
    classDef inference fill:#FFCC80,stroke:#EF6C00
    classDef analysis fill:#D7CCC8,stroke:#4E342E
    classDef utils fill:#ECEFF1,stroke:#607D8B,stroke-dasharray: 2 2
```
