# hcb06/pyerualjetwork architecture

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

- Interactive diagram: https://gitdiagram.com/hcb06/pyerualjetwork
- Repository: https://github.com/hcb06/pyerualjetwork

## Overview

##### Project Type and Purpose
- This is a Python-based machine-learning library (formerly “anaplan”, now “pyerualjetwork”) designed to offer multiple training algorithms (PLAN, MLP/PTNN, ENE) with CPU and GPU (CUDA) backends.
- It provides data preprocessing, model construction, training, evaluation, visualization, serialization, and memory management utilities.

##### File Structure Analysis
- Top-level packaging under “pyerualjetwork-X.YY”:
- pyerualjetwork/nn.py, ene.py, model_ops.py, memory_ops.py, help.py, issue_solver.py, fitness_functions.py
- Subpackages cpu/ (activation_functions.py, data_ops.py, loss_functions.py, metrics.py, visualizations.py)
- Subpackages cuda/ (same modules as cpu/)
- Demo code under Welcome_to_* directories is illustrative only and not part of the shipped library.
- setup.py, setup.cfg, PKG-INFO files define packaging and dependencies.

##### Key Components (to represent
A. User Application Layer
- User’s script / Jupyter notebook importing “pyerualjetwork” modules.
B. API Layer (Core Modules)
- nn module: building and training neural-network architectures (PLAN, MLP, PTNN functions)
- ene module: genetic / neuroevolution routines
- model_ops module: save/load models, checkpointing, serialization
- memory_ops module: memory allocation, GPU/CPU memory management
- issue_solver module: compatibility checks and version-issue resolution
- help, fitness_functions modules: utilities and objective functions
C. Backend Layer
- cpu.data_ops, cpu.activation_functions, cpu.loss_functions, cpu.metrics, cpu.visualizations
- cuda.data_ops, cuda.activation_functions, cuda.loss_functions, cuda.metrics, cuda.visualizations
–– Each backend exports the same interface but routes compute to NumPy/SciPy (CPU) or CuPy (CUDA).
D. External Dependencies
- NumPy, pandas, networkx, scipy, tqdm, matplotlib, seaborn (optional), cupy-cuda, psutil
E. Hardware Layer
- CPU cores and GPU devices

##### Relationships and Data Flows
- User code calls high-level API (nn.fit, ene.run, etc.) → Core Module
- Core Module delegates tensor operations & graph construction to selected backend (CPU vs. CUDA) based on user choice or default.
- Backend layer executes numerical kernels via NumPy or CuPy and returns results.
- model_ops writes to disk (pickle, numpy .npy) and fetches models.
- memory_ops mediates memory allocation/frees on CPU/GPU.
- Visualizations modules extract metrics/history from core modules and render via matplotlib/networkx.

##### Architectural Patterns and Design Principles
- Layered architecture: clear separation between API, backend, and hardware.
- Strategy pattern for backend selection (CPU vs. CUDA).
- Modular design: each concern (data, metrics, activations, loss) lives in its own module/subpackage.
- Dependency injection: core modules accept data arrays and loss/activation functions interchangeably.
- Singleton or factory pattern for issue_solver to manage global compatibility checks.

##### Technologies and Frameworks
- Python packaging (setuptools) via setup.py / setup.cfg
- NumPy, pandas, SciPy for CPU compute
- CuPy for GPU compute
- Matplotlib, seaborn, networkx for visualizations
- pickle / .npy for model serialization
- tqdm for progress bars
- psutil for resource monitoring

##### Essential Elements to Capture
- Module boundaries: API vs. backend
- Data flow: training data → pipeline → compute → model artifacts → visualization
- Dependency graph: core modules depend on backend modules; backend modules depend on external libraries; core modules depend on model_ops/memory_ops.
- Support for eager vs. static execution (annotate plan_fit vs. learn functions).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User Layer
    subgraph "User Application"
        User["User Script / Jupyter Notebook"]
    end

    %% Library Layer
    subgraph "PyerualJetwork Library"
        subgraph "Core API Modules"
            NN["nn"]:::core
            ENE["ene"]:::core
            MO["model_ops"]:::core
            MEM["memory_ops"]:::core
            IS["issue_solver"]:::core
            HELP["help"]:::core
            FF["fitness_functions"]:::core
            BackendSelector["Backend Selector"]:::core
        end
        subgraph "Backend Modules"
            subgraph "CPU Backend"
                cACT["cpu.activation_functions"]:::backend
                cDATA["cpu.data_ops"]:::backend
                cLOSS["cpu.loss_functions"]:::backend
                cMET["cpu.metrics"]:::backend
                cVIS["cpu.visualizations"]:::backend
            end
            subgraph "CUDA Backend"
                gACT["cuda.activation_functions"]:::backend
                gDATA["cuda.data_ops"]:::backend
                gLOSS["cuda.loss_functions"]:::backend
                gMET["cuda.metrics"]:::backend
                gVIS["cuda.visualizations"]:::backend
            end
        end
    end

    %% Data Store
    subgraph "Data Store"
        Models[(Saved Models)]:::datastore
    end

    %% External Dependencies
    subgraph "External Dependencies"
        NP["NumPy"]:::external
        PD["pandas"]:::external
        NX["networkx"]:::external
        SP["SciPy"]:::external
        TQ["tqdm"]:::external
        MPL["matplotlib"]:::external
        SB["seaborn"]:::external
        CP["cupy-cuda"]:::external
        PS["psutil"]:::external
    end

    %% Hardware Layer
    subgraph "Hardware"
        CPUCores["CPU Cores"]:::hardware
        GPUDevices["GPU Devices"]:::hardware
    end

    %% Connections
    User -->|imports / calls| NN
    User -->|imports / calls| ENE

    NN -->|uses| BackendSelector
    ENE -->|runs| BackendSelector

    BackendSelector -->|select CPU| cDATA
    BackendSelector -->|select GPU| gDATA

    cDATA --> NP
    cACT --> NP
    cLOSS --> SP
    cMET --> SP
    cVIS --> MPL
    cVIS --> NX
    cVIS --> SB

    gDATA --> CP
    gACT --> CP
    gLOSS --> CP
    gMET --> CP
    gVIS --> MPL
    gVIS --> NX
    gVIS --> SB

    MO -->|save/load| Models
    MEM -->|allocate/free| CPUCores
    MEM -->|allocate/free| GPUDevices

    FF -->|provides| NN
    FF -->|provides| ENE

    IS -.->|checks compatibility| BackendSelector

    HELP -.->|utility| NN
    HELP -.->|utility| ENE

    %% Click Events
    click NN "https://github.com/hcb06/pyerualjetwork/blob/main/pyerualjetwork-5.56/pyerualjetwork/nn.py"
    click ENE "https://github.com/hcb06/pyerualjetwork/blob/main/pyerualjetwork-5.56/pyerualjetwork/ene.py"
    click MO "https://github.com/hcb06/pyerualjetwork/blob/main/pyerualjetwork-5.56/pyerualjetwork/model_ops.py"
    click MEM "https://github.com/hcb06/pyerualjetwork/blob/main/pyerualjetwork-5.56/pyerualjetwork/memory_ops.py"
    click IS "https://github.com/hcb06/pyerualjetwork/blob/main/pyerualjetwork-5.56/pyerualjetwork/issue_solver.py"
    click HELP "https://github.com/hcb06/pyerualjetwork/blob/main/pyerualjetwork-5.56/pyerualjetwork/help.py"
    click FF "https://github.com/hcb06/pyerualjetwork/blob/main/pyerualjetwork-5.56/pyerualjetwork/fitness_functions.py"
    click cACT "https://github.com/hcb06/pyerualjetwork/blob/main/pyerualjetwork-5.56/pyerualjetwork/cpu/activation_functions.py"
    click cDATA "https://github.com/hcb06/pyerualjetwork/blob/main/pyerualjetwork-5.56/pyerualjetwork/cpu/data_ops.py"
    click cLOSS "https://github.com/hcb06/pyerualjetwork/blob/main/pyerualjetwork-5.56/pyerualjetwork/cpu/loss_functions.py"
    click cMET "https://github.com/hcb06/pyerualjetwork/blob/main/pyerualjetwork-5.56/pyerualjetwork/cpu/metrics.py"
    click cVIS "https://github.com/hcb06/pyerualjetwork/blob/main/pyerualjetwork-5.56/pyerualjetwork/cpu/visualizations.py"
    click gACT "https://github.com/hcb06/pyerualjetwork/blob/main/pyerualjetwork-5.56/pyerualjetwork/cuda/activation_functions.py"
    click gDATA "https://github.com/hcb06/pyerualjetwork/blob/main/pyerualjetwork-5.56/pyerualjetwork/cuda/data_ops.py"
    click gLOSS "https://github.com/hcb06/pyerualjetwork/blob/main/pyerualjetwork-5.56/pyerualjetwork/cuda/loss_functions.py"
    click gMET "https://github.com/hcb06/pyerualjetwork/blob/main/pyerualjetwork-5.56/pyerualjetwork/cuda/metrics.py"
    click gVIS "https://github.com/hcb06/pyerualjetwork/blob/main/pyerualjetwork-5.56/pyerualjetwork/cuda/visualizations.py"
    click SetupPy "https://github.com/hcb06/pyerualjetwork/blob/main/pyerualjetwork-5.56/setup.py"
    click SetupCfg "https://github.com/hcb06/pyerualjetwork/blob/main/pyerualjetwork-5.56/setup.cfg"

    %% Styles
    classDef core fill:#AED6F1,stroke:#1B4F72,stroke-width:1px
    classDef backend fill:#A9DFBF,stroke:#186A3B,stroke-width:1px
    classDef external fill:#F9E79F,stroke:#B9770E,stroke-width:1px
    classDef hardware fill:#D5D8DC,stroke:#616A6B,stroke-width:1px
    classDef datastore fill:#FADBD8,stroke:#922B21,stroke-width:1px
```
