# do-not-circulate/genni architecture

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

- Interactive diagram: https://gitdiagram.com/do-not-circulate/genni
- Repository: https://github.com/do-not-circulate/genni

## Overview

##### Main Components
– Experiment management (experiment.py)
– Data getters (data_getters.py) to handle data extraction for experiments.
– Training logic (training.py, training_utils.py)
– Model-related functionality (nets and their definitions in genni/nets)
– Griding functionality (in genni/griding/…) for grid creation, interpolation and statistics.
– Save/Load utilities, along with other helper functions (utils.py)
- Experiment Scripts and Configuration:
– The entry point for running experiments is in the “scripts/experiment.py” file.
– The configuration file “genni.yml” (along with pyproject.toml, setup.py) is used to define settings such as the GENNI_HOME directory.
- Experiment Storage and Outputs:
– The experiments folder (with subdirectories like FCN_Sample and LeNet_Sample) holds all the training artifacts – model snapshots (.pt files), logs, and post-processing results. Inside each experiment directory, you have “models”, “runs”, and “postprocessing” structure.
- Postprocessing and Plotting:
– The “notebooks” folder (e.g., SubspaceAnalysis.ipynb) and the “postprocessing” subdirectories under both FCN_Sample and LeNet_Sample offer insight into visualization, grid computation, and analysis of the learned equivalence classes.
- Testing and Deployment:
– While minimal, the “tests” directory signals that some test routines exist to verify functionality.

##### Relationships and Data Flow
- User/Experimenter launches a run by invoking “scripts/experiment.py” (or through pip installed package interface) using the configuration provided in “genni.yml.”
- The experiment script leverages the core library (genni) to load data (via data_getters) and define the network architecture (via nets).
- Training is conducted using routines found in training.py and training_utils.py. During training, model snapshots and logs are saved under the experiments directory (organized by timestamp and experimental ID).
- The griding module (located in genni/griding) performs analyses on the trained model’s parameter space. It uses interpolation and statistics methods to compute the equivalence classes’ geometry.
- The overall data flow is: Configuration & Input Data → Experiment Runner (scripts) → Core GENNI Modules (training, griding, nets, utilities) → Experiment Outputs (models, logs, grid data) → Visualization (notebooks and plotting scripts).

##### Architectural Patterns and Design Principles
- Modular Design: The project separates concerns by grouping experiment logic, neural network definitions, training routines, griding/interpolation functionality, and utilities into different modules.
- Configurability: Use of configuration files (genni.yml) makes the experiments flexible.
- Separation of Experiment and Analysis: The use of a dedicated experiments output directory and separate notebooks/postprocessing routines emphasizes a clear boundary between computation and visualization.
- Reusability: The core library is structured so that new experiments, architectures, or visualization methods can be added without needing to change the core workflow.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Configuration/Settings Subgraph
    subgraph "Configuration/Settings"
        cfg1("Configuration File: genni.yml"):::config
        cfg2("Configuration File: pyproject.toml"):::config
        cfg3("Configuration File: setup.py"):::config
    end

    %% Experiment Runner Subgraph
    subgraph "Experiment Runner"
        runner("Experiment Runner"):::runner
    end

    %% Core GENNI Library Subgraph
    subgraph "Core GENNI Library"
        expMgmt("Experiment Management"):::core
        dataGet("Data Getters"):::core
        trainingLogic("Training Logic"):::core
        trainingUtils("Training Utils"):::core
        nets("Model Definitions"):::core
        griding("Griding Module"):::core
        saveLoad("Save/Load"):::core
        util("Utilities"):::core
    end

    %% Experiment Outputs Subgraph
    subgraph "Experiment Outputs"
        storage("Experiment Storage"):::storage
    end

    %% Visualization Subgraph
    subgraph "Visualization/Analysis"
        visualize("Visualization & Postprocessing"):::viz
        notebooks("Notebooks"):::viz
    end

    %% Testing Subgraph
    subgraph "Testing"
        testing("Testing"):::test
    end

    %% Connections from Configuration to Experiment Runner
    cfg1 --> runner
    cfg2 --> runner
    cfg3 --> runner

    %% Connections from Experiment Runner to Core GENNI Library
    runner --> expMgmt
    runner --> dataGet
    runner --> trainingLogic
    runner --> trainingUtils
    runner --> nets
    runner --> griding
    runner --> saveLoad
    runner --> util

    %% Connections from Core GENNI Library to Experiment Outputs
    expMgmt --> storage
    trainingLogic --> storage
    trainingUtils --> storage
    nets --> storage
    griding --> storage

    %% Connection from Experiment Outputs to Visualization
    storage --> visualize
    visualize --> notebooks

    %% Connections from Core GENNI Library to Testing
    expMgmt --> testing
    dataGet --> testing
    trainingLogic --> testing
    trainingUtils --> testing
    nets --> testing
    griding --> testing
    saveLoad --> testing
    util --> testing

    %% Class Definitions for coloring
    classDef config fill:#9FD,stroke:#333,stroke-width:2px;
    classDef runner fill:#FDD,stroke:#333,stroke-width:2px;
    classDef core fill:#CDF,stroke:#333,stroke-width:2px;
    classDef storage fill:#FC9,stroke:#333,stroke-width:2px;
    classDef viz fill:#FF9,stroke:#333,stroke-width:2px;
    classDef test fill:#DDD,stroke:#333,stroke-width:2px;

    %% Click Events for Configuration Files
    click cfg1 "https://github.com/do-not-circulate/genni/blob/main/genni.yml"
    click cfg2 "https://github.com/do-not-circulate/genni/blob/main/pyproject.toml"
    click cfg3 "https://github.com/do-not-circulate/genni/blob/main/setup.py"

    %% Click Event for Experiment Runner
    click runner "https://github.com/do-not-circulate/genni/blob/main/scripts/experiment.py"

    %% Click Events for Core GENNI Library components
    click expMgmt "https://github.com/do-not-circulate/genni/blob/main/genni/experiment.py"
    click dataGet "https://github.com/do-not-circulate/genni/blob/main/genni/data_getters.py"
    click trainingLogic "https://github.com/do-not-circulate/genni/blob/main/genni/training.py"
    click trainingUtils "https://github.com/do-not-circulate/genni/blob/main/genni/training_utils.py"
    click nets "https://github.com/do-not-circulate/genni/blob/main/genni/nets/Nets.py"
    click griding "https://github.com/do-not-circulate/genni/tree/main/genni/griding/"
    click saveLoad "https://github.com/do-not-circulate/genni/blob/main/genni/save_load.py"
    click util "https://github.com/do-not-circulate/genni/blob/main/genni/utils.py"

    %% Click Events for Experiment Storage
    click storage "https://github.com/do-not-circulate/genni/tree/main/experiments/"

    %% Click Event for Notebooks
    click notebooks "https://github.com/do-not-circulate/genni/blob/main/notebooks/SubspaceAnalysis.ipynb"

    %% Click Event for Testing
    click testing "https://github.com/do-not-circulate/genni/tree/main/tests/"
```
