# gduthe/windfarm-gnn architecture

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

- Interactive diagram: https://gitdiagram.com/gduthe/windfarm-gnn
- Repository: https://github.com/gduthe/windfarm-gnn

## Overview

##### Project Type and Purpose
- This is a research-oriented, modular graph-ML pipeline (not a web or full-stack app).
- Purpose: generate wind-farm graph datasets via PyWake, train/finetune Graph Neural Networks (GNNs) for power and load prediction, and provide inference + plotting tools.

##### File Structure
Top-level components:
- gnn_framework/ – core ML pipeline
– train.py, predict.py
– config.yml (training)
– data/ (Dataset class, stats computation)
– models/ (encoder, processor, decoder, WindFarmGNN definitions)
– finetuning/ (LoRA & other finetuning scripts + configs)
- graph_farms/ – data-generation module
– generate_graphs.py (parallel PyWake + Sobol sampling)
– inflow_gen.py, layout_gen.py, pywake_sim.py
– config.yml (generation parameters)
- notebooks/ – Jupyter examples invoking generation, training, evaluation, plotting
- plotting/ – post-processing and visualization utilities

##### Extract Insights from the README
- Workflow stages:
a) Generate dataset (graph_farms)
b) Train base GNN (gnn_framework/train.py)
c) Finetune (LoRA or other methods)
d) Predict/infer on test data (gnn_framework/predict.py)
e) Plot results (plotting/) or explore via notebooks
- Config-driven design via YAML files at each stage
- External dependency: parallelized PyWake for fluid dynamics simulation

##### Main Components & Interactions
A. Data Generation Layer (“graph_farms” module)
- Sobol Sampler + Layout Generator
- PyWake Simulation Engine (external)
→ Outputs: serialized graph datasets (e.g., .pt, .npz, or custom) on disk
B. Data Ingestion Layer (“gnn_framework/data”)
- Dataset class
- compute_dataset_stats
C. Model Training Layer (“gnn_framework/models” + train.py)
- Encoder, Message-Passing Processor, Decoder, Task Heads
- Training Engine (PyTorch)
→ Generates: trained model checkpoint
D. Fine-Tuning Layer (“gnn_framework/finetuning”)
- LoRA adapter or other strategies
→ Outputs: fine-tuned model checkpoint
E. Inference Layer (“gnn_framework/predict.py”)
- Loads model + test graphs → runs batch inference
F. Visualization Layer (“plotting” + notebooks)
- Plotting scripts
- Interactive notebooks invoking generation/training/inference

graph_farms → dataset storage → data ingestion → training → (optionally) finetuning → inference → plotting

##### Architectural Patterns & Design Principles
- Modular separation of concerns (data gen vs. data loader vs. model vs. finetune vs. visualization)
- Pipeline-driven, config-as-code (YAML)
- Plugin-style finetuning (LoRA, all-layers, decoder-only)
- Batch-parallel data generation (multiprocessing of PyWake simulations)
- Layout-agnostic GNN (graph abstraction layer in models/)

##### Detailed Element Checklist
- Component names matching directory names (e.g., “gnn_framework/models”)
- Config files next to each module
- Storage blocks for raw graphs, processed datasets, model artifacts
- Notebook layer as an orchestration client

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Generation Layer
    subgraph "Data Generation Layer" 
        direction TB
        GF["graph_farms/"]:::dataModule
        CFG_GF["config.yml"]:::dataModule
        GG["generate_graphs.py"]:::dataModule
        IG["inflow_gen.py"]:::dataModule
        LG["layout_gen.py"]:::dataModule
        PS["pywake_sim.py"]:::external
        UT["utils.py"]:::dataModule
        GF --> CFG_GF
        GF --> GG
        GF --> IG
        GF --> LG
        GF --> PS
        GF --> UT
    end

    %% Storage for generated graphs
    DSTORE[(Raw Graph Dataset Storage)]:::storage

    %% Data Ingestion Layer
    subgraph "Data Ingestion Layer" 
        direction TB
        DI["gnn_framework/data/"]:::dataModule
        DS["dataset.py"]:::dataModule
        ST["compute_dataset_stats.py"]:::dataModule
        II["__init__.py"]:::dataModule
        DI --> DS
        DI --> ST
        DI --> II
    end

    %% Model Training Layer
    subgraph "Model Training Layer"
        direction TB
        TM["train.py"]:::mlModule
        CFG_T["config.yml"]:::mlModule
        subgraph "Models Module"
            direction TB
            MD["gnn_framework/models/"]:::mlModule
            ENC["encoder.py"]:::mlModule
            PROC["processor.py"]:::mlModule
            DEC["decoder.py"]:::mlModule
            WFG["windfarmgnn.py"]:::mlModule
            BAS["basics.py"]:::mlModule
            MI["__init__.py"]:::mlModule
            MD --> ENC
            MD --> PROC
            MD --> DEC
            MD --> WFG
            MD --> BAS
            MD --> MI
        end
    end

    %% Storage for processed dataset and model checkpoints
    PDATA[(Processed Dataset Storage)]:::storage
    CKPT[(Model Checkpoints)]:::storage

    %% Fine-Tuning Layer
    subgraph "Fine-Tuning Layer"
        direction TB
        FT["finetune.py"]:::mlModule
        CFG_FT["ft_config.yml"]:::mlModule
        subgraph "LoRA Adapter"
            direction TB
            MINL["minlora/"]:::mlModule
            MLP["model.py"]:::mlModule
            UTL["utils.py"]:::mlModule
            INI2["__init__.py"]:::mlModule
            MINL --> MLP
            MINL --> UTL
            MINL --> INI2
        end
    end

    %% Inference Layer
    INF["predict.py"]:::mlModule

    %% Visualization Layer
    subgraph "Visualization Layer"
        direction TB
        PLOT["plotting/"]:::viz
        PLOT_S["plotting.py"]:::viz
        INI3["__init__.py"]:::viz
        NB["notebooks/"]:::viz
        NB1["compare_connectivities.ipynb"]:::viz
        NB2["compare_loads_models.ipynb"]:::viz
        PLOT --> PLOT_S
        PLOT --> INI3
        NB --> NB1
        NB --> NB2
    end

    %% External Cloud
    PYWAKE("PyWake Simulation Engine"):::external

    %% Data Flow Arrows
    GF -->|1 serialize graphs| DSTORE
    DSTORE -->|2 load graphs| DI
    DI -->|3 train on batch| TM
    TM -->|outputs checkpoint| CKPT
    CKPT -->|4 apply LoRA| FT
    CKPT -->|4 finetune| FT
    FT -->|outputs fine-tuned checkpoint| CKPT
    CKPT -->|5 batch inference| INF
    INF -->|prediction results| PDATA
    PDATA -->|plot data| PLOT
    INF -->|invoke notebooks| NB

    %% Click Events
    click GF "https://github.com/gduthe/windfarm-gnn/tree/main/graph_farms/"
    click CFG_GF "https://github.com/gduthe/windfarm-gnn/blob/main/graph_farms/config.yml"
    click GG "https://github.com/gduthe/windfarm-gnn/blob/main/graph_farms/generate_graphs.py"
    click IG "https://github.com/gduthe/windfarm-gnn/blob/main/graph_farms/inflow_gen.py"
    click LG "https://github.com/gduthe/windfarm-gnn/blob/main/graph_farms/layout_gen.py"
    click PS "https://github.com/gduthe/windfarm-gnn/blob/main/graph_farms/pywake_sim.py"
    click UT "https://github.com/gduthe/windfarm-gnn/blob/main/graph_farms/utils.py"
    click DI "https://github.com/gduthe/windfarm-gnn/tree/main/gnn_framework/data/"
    click DS "https://github.com/gduthe/windfarm-gnn/blob/main/gnn_framework/data/dataset.py"
    click ST "https://github.com/gduthe/windfarm-gnn/blob/main/gnn_framework/data/compute_dataset_stats.py"
    click II "https://github.com/gduthe/windfarm-gnn/blob/main/gnn_framework/data/__init__.py"
    click TM "https://github.com/gduthe/windfarm-gnn/blob/main/gnn_framework/train.py"
    click CFG_T "https://github.com/gduthe/windfarm-gnn/blob/main/gnn_framework/config.yml"
    click MD "https://github.com/gduthe/windfarm-gnn/tree/main/gnn_framework/models/"
    click ENC "https://github.com/gduthe/windfarm-gnn/blob/main/gnn_framework/models/encoder.py"
    click PROC "https://github.com/gduthe/windfarm-gnn/blob/main/gnn_framework/models/processor.py"
    click DEC "https://github.com/gduthe/windfarm-gnn/blob/main/gnn_framework/models/decoder.py"
    click WFG "https://github.com/gduthe/windfarm-gnn/blob/main/gnn_framework/models/windfarmgnn.py"
    click BAS "https://github.com/gduthe/windfarm-gnn/blob/main/gnn_framework/models/basics.py"
    click MI "https://github.com/gduthe/windfarm-gnn/blob/main/gnn_framework/models/__init__.py"
    click FT "https://github.com/gduthe/windfarm-gnn/blob/main/gnn_framework/finetuning/finetune.py"
    click CFG_FT "https://github.com/gduthe/windfarm-gnn/blob/main/gnn_framework/finetuning/ft_config.yml"
    click MINL "https://github.com/gduthe/windfarm-gnn/tree/main/gnn_framework/finetuning/minlora/"
    click MLP "https://github.com/gduthe/windfarm-gnn/blob/main/gnn_framework/finetuning/minlora/model.py"
    click UTL "https://github.com/gduthe/windfarm-gnn/blob/main/gnn_framework/finetuning/minlora/utils.py"
    click INI2 "https://github.com/gduthe/windfarm-gnn/blob/main/gnn_framework/finetuning/minlora/__init__.py"
    click INF "https://github.com/gduthe/windfarm-gnn/blob/main/gnn_framework/predict.py"
    click PLOT "https://github.com/gduthe/windfarm-gnn/tree/main/plotting/"
    click PLOT_S "https://github.com/gduthe/windfarm-gnn/blob/main/plotting/plotting.py"
    click INI3 "https://github.com/gduthe/windfarm-gnn/blob/main/plotting/__init__.py"
    click NB "https://github.com/gduthe/windfarm-gnn/tree/main/notebooks/"
    click NB1 "https://github.com/gduthe/windfarm-gnn/blob/main/notebooks/compare_connectivities.ipynb"
    click NB2 "https://github.com/gduthe/windfarm-gnn/blob/main/notebooks/compare_loads_models.ipynb"

    %% Styles
    classDef dataModule fill:#cfe2f3,stroke:#0366d6,stroke-width:1px;
    classDef mlModule fill:#d9ead3,stroke:#38761d,stroke-width:1px;
    classDef external fill:#fce5cd,stroke:#b45f06,stroke-width:1px;
    classDef storage fill:#eeeeee,stroke:#888888,stroke-width:1px;
    classDef viz fill:#fff2cc,stroke:#b59f31,stroke-width:1px;
```
