# k-onoue/variational-tpr architecture

> Architecture diagram of the GitHub repository k-onoue/variational-tpr, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-11-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/k-onoue/variational-tpr
- Repository: https://github.com/k-onoue/variational-tpr

## Overview

##### Project Type and Purpose
- This is a Python research library and experiment orchestration toolkit for “Tractable Variational Student-t Process Regression.”
- It provides:
- Core implementations of dense and sparse Student-t process regression models (in src/student)
- Experiment definitions (in experiments/*.py)
- Shell scripts to launch those experiments under Slurm or locally.
- Use case: run hyperparameter-configurable GPR/TPR experiments on CPU/GPU and collect results.

##### File-Structure Analysis
- Top-level:
.gitignore, README.md, requirements.txt, pyproject.toml → project metadata and packaging
src/student → core ML library modules (gpr, kernels, priors, tpr, tang, xu, utils, constants)
experiments → Python scripts defining variants of dense_v{1..7}.py and sparse_v{1..6}.py
scripts → bash wrappers (run_dense.sh, run_dense_ablation.sh, run_sparse.sh, run_sparse_ablation.sh)
- Patterns:
- “src/student” follows a modular ML-library pattern.
- experiments folder holds high-level experiment scenarios.
- scripts folder defines orchestration on HPC/Slurm.
- Deployment/config: pyproject.toml for packaging, requirements.txt for dependencies, .python-version for pyenv.

##### README Insights
- Describes installation, directory layout, usage of hyper_settings dictionary for model configuration, and how to run experiments.
- Emphasizes two experiment modes: dense vs sparse (with GPU for sparse).

a. Main Components
- User/HPC Scheduler (Slurm)
- Orchestration Scripts (bash in scripts/)
- Experiment Definitions (Python in experiments/)
- Core Library (src/student modules)
- Data (datasets input, logs/, results/ output)
- External Dependencies (Python 3.12, pip packages, GPU/CPU resources)
b. Relationships & Interactions
- User invokes a script (e.g., run_sparse.sh)
→ Slurm schedules job on allocated CPU/GPU
→ Script calls appropriate experiments/*.py
→ Each experiment imports src/student to build and train a model
→ Model leverages kernels.py, priors.py, gpr.py, tpr.py, tang.py, xu.py, utils.py
→ Outputs (metrics, logs, serialized models) are written to logs/ and results/
c. Architectural Patterns
- Modular library-in-src pattern
- CLI orchestration via shell wrappers
- Experiment-per-script pattern for reproducibility
- Separation of concerns: hyperparameter configuration (dictionary), core math code, experiment definitions, orchestration
d. Key Technologies
- Python 3.12 environment managed via pyenv & venv
- Slurm job scheduler integration via bash scripts
- Numeric libraries from requirements.txt (e.g., torch, numpy, etc.)
- GPU acceleration for sparse models (NVIDIA A100)

## Diagram (Mermaid)

```mermaid
graph TB
    %% Layer 1: User & HPC Scheduler
    subgraph "Layer 1: User & HPC Scheduler"
        U["User"]:::external
        S["Slurm Scheduler"]:::external
    end

    %% Layer 2: Orchestration Scripts
    subgraph "Layer 2: Orchestration Scripts"
        SD["run_dense.sh"]:::code
        SDA["run_dense_ablation.sh"]:::code
        SS["run_sparse.sh"]:::code
        SSA["run_sparse_ablation.sh"]:::code
    end

    %% Layer 3: Experiment Definitions
    subgraph "Layer 3: Experiment Definitions"
        subgraph "Dense Branch"
            D1["dense_v1.py"]:::code
            D2["dense_v2.py"]:::code
            D3["dense_v3.py"]:::code
            D4["dense_v4.py"]:::code
            D5["dense_v5.py"]:::code
            D6["dense_v6.py"]:::code
            D7["dense_v7.py"]:::code
        end
        subgraph "Sparse Branch"
            S1["sparse_v1.py"]:::code
            S2["sparse_v2.py"]:::code
            S3["sparse_v3.py"]:::code
            S4["sparse_v4.py"]:::code
            S5["sparse_v5.py"]:::code
            S6["sparse_v6.py"]:::code
            note_sparse["requires GPU, 16GB RAM, 4 cores"]:::external
        end
    end

    %% Layer 4: Core Library
    subgraph "Layer 4: Core Library (src/student)"
        GPR["gpr.py"]:::code
        TPR["tpr.py"]:::code
        KER["kernels.py"]:::code
        PRI["priors.py"]:::code
        TAN["tang.py"]:::code
        XU["xu.py"]:::code
        UTIL["utils.py"]:::code
        CONS["constants.py"]:::code
        INIT["__init__.py"]:::code
    end

    %% Layer 5: Storage & Outputs
    subgraph "Layer 5: Storage & Outputs"
        DATA["datasets/"]:::storage
        LOGS["logs/"]:::storage
        RES["results/"]:::storage
    end

    %% Configuration & Metadata
    subgraph "Project Config & Metadata"
        RD["README.md"]:::config
        REQ["requirements.txt"]:::config
        PYT["pyproject.toml"]:::config
        PPV[".python-version"]:::config
        GITI[".gitignore"]:::config
        GITA[".gitattributes"]:::config
    end

    %% Environment
    ENV["Python 3.12\npip packages\nCPU/GPU resources"]:::external

    %% Connections
    U -->|"submit job"| S
    S -->|"allocate resources"| SD
    S -->|"allocate resources"| SDA
    S -->|"allocate resources"| SS
    S -->|"allocate resources"| SSA

    SD -->|"runs experiment"| D1
    SD -->|"runs experiment"| D2
    SD -->|"runs experiment"| D3
    SD -->|"runs experiment"| D4
    SD -->|"runs experiment"| D5
    SD -->|"runs experiment"| D6
    SD -->|"runs experiment"| D7

    SDA -->|"runs experiment"| D1
    SDA -->|"runs experiment"| D2

    SS -->|"runs experiment"| S1
    SS -->|"runs experiment"| S2
    SS -->|"runs experiment"| S3
    SS -->|"runs experiment"| S4
    SS -->|"runs experiment"| S5
    SS -->|"runs experiment"| S6

    SSA -->|"runs experiment"| S1
    SSA -->|"runs experiment"| S2

    %% Experiment to Core Library
    D1 -->|"import/use\nhyper_settings dict"| GPR
    D1 -->|"import/use\nhyper_settings dict"| KER
    D1 -->|"import/use\nhyper_settings dict"| PRI
    D1 -->|"import/use\nhyper_settings dict"| TPR
    D1 -->|"import/use\nhyper_settings dict"| TAN
    D1 -->|"import/use\nhyper_settings dict"| XU
    D1 -->|"import/use\nhyper_settings dict"| UTIL
    D1 -->|"import/use\nhyper_settings dict"| CONS

    %% replicate import for one node to indicate pattern
    S1 -->|"import/use\nhyper_settings dict"| GPR
    S1 -->|"import/use\nhyper_settings dict"| KER
    S1 -->|"import/use\nhyper_settings dict"| PRI
    S1 -->|"import/use\nhyper_settings dict"| TPR
    S1 -->|"import/use\nhyper_settings dict"| TAN
    S1 -->|"import/use\nhyper_settings dict"| XU
    S1 -->|"import/use\nhyper_settings dict"| UTIL
    S1 -->|"import/use\nhyper_settings dict"| CONS

    %% Data flow
    D1 -->|"read data"| DATA
    S1 -->|"read data"| DATA
    D1 -->|"write metrics"| LOGS
    D1 -->|"write models"| RES
    S1 -->|"write metrics"| LOGS
    S1 -->|"write models"| RES

    %% Environment dependencies
    ENV --> SD
    ENV --> SS
    ENV --> D1
    ENV --> S1
    ENV --> GPR

    RD -->|"defines setup"| ENV
    REQ -->|"defines deps"| ENV
    PYT -->|"defines packaging"| ENV
    PPV -->|"defines pyenv"| ENV
    GITI -->|"ignores files"| ENV
    GITA -->|"git attrs"| ENV

    %% Styling
    classDef code fill:#E3F2FD,stroke:#2196F3,color:#0D47A1
    classDef storage fill:#E8F5E9,stroke:#4CAF50,color:#1B5E20
    classDef external fill:#FFF3E0,stroke:#FB8C00,color:#E65100
    classDef config fill:#F3E5F5,stroke:#8E24AA,color:#4A148C

    %% Click Events
    click SD "https://github.com/k-onoue/variational-tpr/blob/main/scripts/run_dense.sh"
    click SDA "https://github.com/k-onoue/variational-tpr/blob/main/scripts/run_dense_ablation.sh"
    click SS "https://github.com/k-onoue/variational-tpr/blob/main/scripts/run_sparse.sh"
    click SSA "https://github.com/k-onoue/variational-tpr/blob/main/scripts/run_sparse_ablation.sh"

    click D1 "https://github.com/k-onoue/variational-tpr/blob/main/experiments/dense_v1.py"
    click D2 "https://github.com/k-onoue/variational-tpr/blob/main/experiments/dense_v2.py"
    click D3 "https://github.com/k-onoue/variational-tpr/blob/main/experiments/dense_v3.py"
    click D4 "https://github.com/k-onoue/variational-tpr/blob/main/experiments/dense_v4.py"
    click D5 "https://github.com/k-onoue/variational-tpr/blob/main/experiments/dense_v5.py"
    click D6 "https://github.com/k-onoue/variational-tpr/blob/main/experiments/dense_v6.py"
    click D7 "https://github.com/k-onoue/variational-tpr/blob/main/experiments/dense_v7.py"

    click S1 "https://github.com/k-onoue/variational-tpr/blob/main/experiments/sparse_v1.py"
    click S2 "https://github.com/k-onoue/variational-tpr/blob/main/experiments/sparse_v2.py"
    click S3 "https://github.com/k-onoue/variational-tpr/blob/main/experiments/sparse_v3.py"
    click S4 "https://github.com/k-onoue/variational-tpr/blob/main/experiments/sparse_v4.py"
    click S5 "https://github.com/k-onoue/variational-tpr/blob/main/experiments/sparse_v5.py"
    click S6 "https://github.com/k-onoue/variational-tpr/blob/main/experiments/sparse_v6.py"

    click GPR "https://github.com/k-onoue/variational-tpr/blob/main/src/student/gpr.py"
    click TPR "https://github.com/k-onoue/variational-tpr/blob/main/src/student/tpr.py"
    click KER "https://github.com/k-onoue/variational-tpr/blob/main/src/student/kernels.py"
    click PRI "https://github.com/k-onoue/variational-tpr/blob/main/src/student/priors.py"
    click TAN "https://github.com/k-onoue/variational-tpr/blob/main/src/student/tang.py"
    click XU "https://github.com/k-onoue/variational-tpr/blob/main/src/student/xu.py"
    click UTIL "https://github.com/k-onoue/variational-tpr/blob/main/src/student/utils.py"
    click CONS "https://github.com/k-onoue/variational-tpr/blob/main/src/student/constants.py"
    click INIT "https://github.com/k-onoue/variational-tpr/blob/main/src/student/__init__.py"

    click RD "https://github.com/k-onoue/variational-tpr/blob/main/README.md"
    click REQ "https://github.com/k-onoue/variational-tpr/blob/main/requirements.txt"
    click PYT "https://github.com/k-onoue/variational-tpr/blob/main/pyproject.toml"
    click PPV "https://github.com/k-onoue/variational-tpr/blob/main/.python-version"
    click GITI "https://github.com/k-onoue/variational-tpr/blob/main/.gitignore"
    click GITA "https://github.com/k-onoue/variational-tpr/blob/main/.gitattributes"
```
