# brouthenkamel/cnn-hpo-carbon architecture

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

- Interactive diagram: https://gitdiagram.com/brouthenkamel/cnn-hpo-carbon
- Repository: https://github.com/brouthenkamel/cnn-hpo-carbon

## Overview

##### Project type and purpose
- This is a research‐grade Neural Architecture Search (NAS) and hyperparameter optimization framework for convolutional neural networks (CNNs). It combines:
- Model loading/building (AlexNet, MobileNet, ResNet, SimpleCNN…)
- Training pipelines
- Metaheuristic optimizers (hill climbing, simulated annealing)
- Surrogate modeling for fast performance approximation
- Its goal is to explore network configurations, evaluate them via full training or surrogate inference, and log results for analysis.

##### File‐structure analysis
- Top‐level directories
- src/: contains all core modules, split by functionality
- scripts/, notebooks/: user‐facing experiment entry points
- dataset/: raw data artifacts for surrogate training
- docs/: design rationale, algorithm descriptions
- records/: output logs and CSV/JSON result dumps
- Key src/ subdirectories
- src/loading: data loaders + model definitions + a model_builder
- src/schema: shared schema for datasets, layers, blocks, models, training jobs
- src/optim: hill_climbing and sa_optimization submodules, each with algorithm entry points and record storage
- src/surrogate_modeling: surrogate pipeline (data loaders, dataset generators, architectures, trainers, inference modules)
- src/training: orchestrates full training runs
- src/utils: cross‐cutting utilities (e.g., data helpers)
- src/neighborhood: code to generate neighboring architectures

a. Main components
- Data Ingestion & Preprocessing
- Model Loader & Builder
- Training Engine
- Optimization Engine
– Hill Climbing
– Simulated Annealing
- Surrogate Modeling Subsystem
- Schema Definitions (shared types)
- Logging / Records Database
- CLI & Scripts Interface
- Experiment Notebooks (Jupyter)
b. Interactions
1. Data Ingestion → Training Engine
2. Model Loader & Builder → Training Engine
3. Training Engine → Records DB (writes metrics)
4. Optimization Engine invokes neighborhood module to generate candidates
5. For each candidate:
- Either call Training Engine (full eval)
- Or call Surrogate Modeling Inference (fast eval)
6. Surrogate Modeling Subsystem trains on past records → provides inference API → fed back into Optimization Engine
7. CLI/Scripts & Notebooks orchestrate these flows, reading/writing from Records DB
c. Architectural patterns
- Modular, layered pipeline (clear separation: loading → building → training → optimization → logging)
- Plugin-style model definitions in src/loading/models
- Shared schema ensures consistency across modules
- Metaheuristic strategy pattern in optim/ subdirectories
- Surrogate modeling as a side pipeline that reuses data and schema
d. Key technologies
- Python + Conda (environment.yaml)
- Jupyter notebooks for rapid prototyping
- CSV/JSON for record keeping
- Possibly PyTorch/TensorFlow in src/loading/models (inferred)

## Diagram (Mermaid)

```mermaid
graph TB
    %% Data & Schema Layer
    subgraph "Data & Schema" 
        direction TB
        DataLoader["Data Ingestion & Preprocessing"]:::blue
        SchemaDefs["Schema Definitions"]:::blue
    end

    %% Model & Training Layer
    subgraph "Model & Training"
        direction TB
        ModelLoader["Model Loader & Builder"]:::green
        Trainer["Training Engine"]:::green
    end

    %% Records DB
    RecordsDB[(Records DB)]:::blue

    %% Optimization Layer
    subgraph "Optimization Engine" 
        direction TB
        OptEngine["Optimization Engine"]:::orange
        subgraph Strategies
            direction TB
            HC["Hill Climbing"]:::orange
            SA["Simulated Annealing"]:::orange
        end
        Neighborhood["Neighborhood Generation Module"]:::orange
    end

    %% Surrogate Modeling Layer
    subgraph "Surrogate Modeling Subsystem"
        direction TB
        SurrogateMain["Surrogate Modeling Subsystem"]:::purple
    end

    %% Utilities & UI
    subgraph "Utilities & Interfaces"
        direction TB
        Utils["Utilities"]:::gray
        Scripts["CLI & Scripts Interface"]:::gray
        Notebooks["Experiment Notebooks"]:::gray
    end

    %% Connections
    Scripts -->|orchestrates| DataLoader
    Notebooks -->|orchestrates| DataLoader
    DataLoader -->|"data|train()"| Trainer
    ModelLoader -->|"buildModel()"| Trainer
    Trainer -->|"writes CSV/JSON"| RecordsDB
    RecordsDB -->|"train()/infer() data"| SurrogateMain
    SurrogateMain -->|"infer_surrogate()"| OptEngine
    OptEngine -->|"candidate|train()"| Trainer
    OptEngine -->|"candidate|infer_surrogate()"| SurrogateMain
    OptEngine --> Neighborhood
    Scripts -->|launches| OptEngine
    Notebooks -->|launches| OptEngine
    Utils --> DataLoader
    Utils --> ModelLoader
    Utils --> Trainer
    Utils --> OptEngine
    Utils --> SurrogateMain

    %% Click Events
    click DataLoader "https://github.com/brouthenkamel/cnn-hpo-carbon/blob/main/src/loading/data/loader.py"
    click ModelLoader "https://github.com/brouthenkamel/cnn-hpo-carbon/blob/main/src/loading/models/model_builder.py"
    click ModelLoader "https://github.com/brouthenkamel/cnn-hpo-carbon/tree/main/src/loading/models/"
    click Trainer "https://github.com/brouthenkamel/cnn-hpo-carbon/blob/main/src/training/train.py"
    click HC "https://github.com/brouthenkamel/cnn-hpo-carbon/blob/main/src/optim/hill_climbing/algorithm.py"
    click HC "https://github.com/brouthenkamel/cnn-hpo-carbon/blob/main/src/optim/hill_climbing/main.py"
    click SA "https://github.com/brouthenkamel/cnn-hpo-carbon/blob/main/src/optim/sa_optimization/algorithm.py"
    click SA "https://github.com/brouthenkamel/cnn-hpo-carbon/blob/main/src/optim/sa_optimization/main.py"
    click Neighborhood "https://github.com/brouthenkamel/cnn-hpo-carbon/blob/main/src/neighborhood/neighboring.py"
    click SurrogateMain "https://github.com/brouthenkamel/cnn-hpo-carbon/blob/main/src/surrogate_modeling/main.py"
    click SurrogateMain "https://github.com/brouthenkamel/cnn-hpo-carbon/tree/main/src/surrogate_modeling/architectures/"
    click SurrogateMain "https://github.com/brouthenkamel/cnn-hpo-carbon/tree/main/src/surrogate_modeling/data_loaders/"
    click SurrogateMain "https://github.com/brouthenkamel/cnn-hpo-carbon/tree/main/src/surrogate_modeling/datasets/"
    click SurrogateMain "https://github.com/brouthenkamel/cnn-hpo-carbon/tree/main/src/surrogate_modeling/generators/"
    click SurrogateMain "https://github.com/brouthenkamel/cnn-hpo-carbon/tree/main/src/surrogate_modeling/models/"
    click SurrogateMain "https://github.com/brouthenkamel/cnn-hpo-carbon/tree/main/src/surrogate_modeling/trainers/"
    click SurrogateMain "https://github.com/brouthenkamel/cnn-hpo-carbon/blob/main/src/surrogate_modeling/utils.py"
    click SchemaDefs "https://github.com/brouthenkamel/cnn-hpo-carbon/tree/main/src/schema/"
    click RecordsDB "https://github.com/brouthenkamel/cnn-hpo-carbon/tree/main/records/"
    click Scripts "https://github.com/brouthenkamel/cnn-hpo-carbon/tree/main/scripts/"
    click Notebooks "https://github.com/brouthenkamel/cnn-hpo-carbon/tree/main/notebooks/"
    click Utils "https://github.com/brouthenkamel/cnn-hpo-carbon/blob/main/src/utils/data.py"

    %% Styles
    classDef blue fill:#AED6F1,stroke:#000
    classDef green fill:#A9DFBF,stroke:#000
    classDef orange fill:#F5B041,stroke:#000
    classDef purple fill:#D7BDE2,stroke:#000
    classDef gray fill:#D5D8DC,stroke:#000
```
