# ctftamu/sl-gps architecture

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

- Interactive diagram: https://gitdiagram.com/ctftamu/sl-gps
- Repository: https://github.com/ctftamu/sl-gps

## Overview

##### Project type and purpose
- This is a Python-based scientific computing library and command-line/GUI application for chemical mechanism reduction via Adaptive Global Pathway Selection (GPS) plus neural network training.
- It integrates:
- a GPS core engine (ported from the original GPS repo)
- Cantera-based chemical simulations (.cti, .inp files)
- TensorFlow-based ANN training and inference
- Data‐processing utilities and plotting (pandas, sklearn, matplotlib)
- A user interface (dialogs, windows under src/slgps/GPS/src/gui)

##### File structure
- Top‐level packaging for pip distribution (pyproject.toml, setup.py, dist/, slgps.egg-info)
- src/slgps/GPS: core GPS algorithm subdivided into
- ck (Chemkin input builders)
- core (GPS logic, graph building, pathway selection)
- ct (Cantera wrappers, mechanism I/O, reactor drivers)
- post (result plotting, painter utilities)
- gui (dialogs and main window for interactive use)
- tools (helper scripts and CSV readers)
- src/slgps: entry-point scripts (main.py, make_data.py, mech_train.py, display_sim_data.py, etc.), model and scaler artifacts (.h5, .pkl), sample data directories, and utilities.py
- tests/: unit tests demonstrating usage and verifying core functionality

##### Extract additional insights from README
- Workflow:
a. Run adaptive GPS 0D ignition simulations → generate raw datasets (npz, CSV)
b. Train ANN (default 16×8 layers) on that dataset → output .h5 neural net weights
c. Use trained network to produce on-the-fly reduced mechanisms for arbitrary conditions
- Dependencies: Cantera 2, TensorFlow 2, pandas, sklearn, numpy, networkx, matplotlib

##### Main components
- GPS Simulation Engine
- Input: detailed mechanism files (chem.cti, chem.inp, therm.dat, trans.dat)
- Uses Cantera reactors via ct module
- Outputs: time histories, species concentrations, reaction rates (raw.npz, CSV)
- Dataset Builder
- Scripts: make_data.py / make_data_parallel.py
- Uses ck module to parse/build input chemistry files
- Aggregates simulation outputs into training datasets
- Neural Network Training
- Script: mech_train.py (spec_train function)
- TensorFlow 2 model (configurable layers)
- Outputs: HDF5 model file (.h5)
- Mechanism Reduction / Prediction
- Script: pred_mech/ modules
- Loads trained .h5 model + input composition/conditions
- Produces reduced chemistry mechanism (chem.cti, chem.inp)
- Post-Processing & Visualization
- post module for plotting results (def_painter, def_plt_tools, dialogs)
- GUI dialogs under src/slgps/GPS/src/gui for interactive analysis
- CLI plotting scripts: sup_plot.py, display_sim_data.py
- Packaging & Distribution
- pyproject.toml, setup.py, wheel/tar in dist/
- Egg-info metadata

##### Relationships and data flows
- Raw Data Outputs → Dataset Builder → Training Data
- Training Data → Neural Network Training → Trained Model (.h5)
- Trained Model + New Conditions → Mechanism Reduction Module → Reduced Mechanism Files
- Reduced Mechanism + Simulation Data → Post-Processing → Plots/GUI Display
- All components depend on core utility modules (tools, core, ck)

##### Important architectural patterns and principles
- Modular layering: separation of concerns between simulation, data preparation, model training, prediction, and presentation.
- Reusable library modules (ck, core, ct, post, tools) imported by both GUI and CLI scripts.
- Plugin-style extensibility: new mechanism sets can be dropped into pred_mech or ct subfolders.
- Clear separation of stateful simulation (Cantera) vs. stateless prediction (ANN model inference).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Dependencies
    subgraph "External Dependencies"
        CAN["Cantera"]:::external
        TF["TensorFlow"]:::external
        PD["pandas/sklearn"]:::external
        NX["networkx/matplotlib"]:::external
    end

    %% Input Mechanism Files
    MECH_FILES[/"chem.cti, chem.inp, therm.dat"/]:::file

    %% GPS Simulation Engine
    subgraph "GPS Simulation Engine"  
        direction TB
        CK["Chemkin Input Builders"]:::sim
        CORE["Core GPS Algorithm"]:::sim
        CT["Cantera Wrappers & Reactor Drivers"]:::sim
    end

    %% Raw Data Outputs
    RAW_DATA[/"raw.npz, raw.csv"/]:::file

    %% Dataset Builder
    subgraph "Dataset Builder"  
        direction TB
        MAKE["make_data.py / make_data_parallel.py"]:::etl
        BUILD_RAW["def_build_raw_npz.py"]:::etl
    end

    %% Neural Network Training
    subgraph "Neural Network Training"
        direction TB
        TRAIN["mech_train.py / mech_train_new.py"]:::ml
        MODEL_CYLINDER[(Training Process)]:::ml
        MODEL_FILE{{"MILD_model_c_100_a_0.001_n_16.h5"}}:::artifact
    end

    %% Mechanism Reduction / Prediction
    subgraph "Mechanism Reduction"
        direction TB
        PRED_SCRIPT["drgep_red_mech.py"]:::etl
        TEMPLATES[/"chem.cti, chem.inp, therm.dat templates"/]:::file
        REDUCED_MECH[/"reduced_chem.cti, reduced_chem.inp"/]:::file
    end

    %% Post-Processing & Visualization
    subgraph "Post-Processing & Visualization"
        direction TB
        POST_UTILS["def_painter.py / def_plt_tools.py"]:::viz
        CLI_PLOTS["display_sim_data.py / sup_plot.py"]:::viz
        GUI["GUI Dialogs & Windows"]:::ui
    end

    %% Packaging & Distribution
    subgraph "Packaging & Distribution"
        PYPROJ[/"pyproject.toml, setup.py"/]:::pkg
        DIST[/"dist/*.whl, dist/*.tar.gz"/]:::pkg
        EGG[/"slgps.egg-info/"/]:::pkg
    end

    %% Data Flows
    MECH_FILES --> CK
    CK --> CORE
    CORE --> CT
    CT --> RAW_DATA
    RAW_DATA --> MAKE
    MAKE --> BUILD_RAW
    BUILD_RAW --> TRAIN
    TRAIN --> MODEL_CYLINDER
    MODEL_CYLINDER --> MODEL_FILE
    MODEL_FILE --> PRED_SCRIPT
    TEMPLATES --> PRED_SCRIPT
    PRED_SCRIPT --> REDUCED_MECH
    REDUCED_MECH --> POST_UTILS
    REDUCED_MECH --> CLI_PLOTS
    POST_UTILS --> GUI
    CLI_PLOTS --> GUI

    %% External Dependencies Links
    CAN --> CT
    TF --> TRAIN
    PD --> MAKE
    PD --> POST_UTILS
    NX --> POST_UTILS

    %% Click events
    click CORE "https://github.com/ctftamu/sl-gps/blob/main/src/slgps/GPS/src/core/def_GPS.py"
    click CORE "https://github.com/ctftamu/sl-gps/blob/main/src/slgps/GPS/src/core/def_GPSA.py"
    click CORE "https://github.com/ctftamu/sl-gps/blob/main/src/slgps/GPS/src/core/def_PFA.py"
    click CORE "https://github.com/ctftamu/sl-gps/blob/main/src/slgps/GPS/src/core/def_build_graph.py"
    click CK "https://github.com/ctftamu/sl-gps/blob/main/src/slgps/GPS/src/ck/def_build_mech_dict.py"
    click CK "https://github.com/ctftamu/sl-gps/blob/main/src/slgps/GPS/src/ck/def_cheminp.py"
    click CK "https://github.com/ctftamu/sl-gps/blob/main/src/slgps/GPS/src/ck/upper_cheminp.py"
    click CT "https://github.com/ctftamu/sl-gps/blob/main/src/slgps/GPS/src/ct/ck2cti_GPS.py"
    click CT "https://github.com/ctftamu/sl-gps/blob/main/src/slgps/GPS/src/ct/def_ct_tools.py"
    click CT "https://github.com/ctftamu/sl-gps/blob/main/src/slgps/GPS/src/ct/psr.py"
    click CT "https://github.com/ctftamu/sl-gps/blob/main/src/slgps/GPS/src/ct/senkin.py"
    click MAKE "https://github.com/ctftamu/sl-gps/blob/main/src/slgps/make_data.py"
    click MAKE "https://github.com/ctftamu/sl-gps/blob/main/src/slgps/make_data_parallel.py"
    click BUILD_RAW "https://github.com/ctftamu/sl-gps/blob/main/src/slgps/GPS/src/ck/def_build_raw_npz.py"
    click TRAIN "https://github.com/ctftamu/sl-gps/blob/main/src/slgps/mech_train.py"
    click TRAIN "https://github.com/ctftamu/sl-gps/blob/main/src/slgps/mech_train_new.py"
    click MODEL_FILE "https://github.com/ctftamu/sl-gps/blob/main/src/slgps/MILD_model_c_100_a_0.001_n_16.h5"
    click PRED_SCRIPT "https://github.com/ctftamu/sl-gps/blob/main/src/slgps/drgep_red_mech.py"
    click TEMPLATES "https://github.com/ctftamu/sl-gps/blob/main/src/slgps/pred_mech/chem.cti"
    click TEMPLATES "https://github.com/ctftamu/sl-gps/blob/main/src/slgps/pred_mech/chem.inp"
    click TEMPLATES "https://github.com/ctftamu/sl-gps/blob/main/src/slgps/pred_mech/therm.dat"
    click POST_UTILS "https://github.com/ctftamu/sl-gps/blob/main/src/slgps/GPS/src/post/def_painter.py"
    click POST_UTILS "https://github.com/ctftamu/sl-gps/blob/main/src/slgps/GPS/src/post/def_plt_tools.py"
    click CLI_PLOTS "https://github.com/ctftamu/sl-gps/blob/main/src/slgps/display_sim_data.py"
    click CLI_PLOTS "https://github.com/ctftamu/sl-gps/blob/main/src/slgps/sup_plot.py"
    click GUI "https://github.com/ctftamu/sl-gps/blob/main/src/slgps/GPS/src/gui/dialog_GPS.py"
    click GUI "https://github.com/ctftamu/sl-gps/blob/main/src/slgps/GPS/src/gui/window_main.py"
    click GUI "https://github.com/ctftamu/sl-gps/blob/main/src/slgps/GPS/src/gui/dialog_post.py"
    click PYPROJ "https://github.com/ctftamu/sl-gps/blob/main/pyproject.toml"
    click PYPROJ "https://github.com/ctftamu/sl-gps/blob/main/setup.py"
    click DIST "https://github.com/ctftamu/sl-gps/blob/main/dist/slgps-2.0.7-py3-none-any.whl"
    click DIST "https://github.com/ctftamu/sl-gps/blob/main/dist/slgps-2.0.7.tar.gz"
    click EGG "https://github.com/ctftamu/sl-gps/tree/main/src/slgps.egg-info/"

    %% Styles
    classDef sim fill:#BDD7EE,stroke:#4F81BD,color:#000;
    classDef etl fill:#D9EAD3,stroke:#6AA84F,color:#000;
    classDef ml fill:#FCE5CD,stroke:#E69138,color:#000;
    classDef artifact fill:#EAD1DC,stroke:#C27BA0,color:#000,shape:hexagon;
    classDef ui fill:#FFF2CC,stroke:#BF9000,color:#000,shape:rounded;
    classDef viz fill:#F4CCCC,stroke:#CC0000,color:#000;
    classDef pkg fill:#D0E0E3,stroke:#0C343D,color:#000;
    classDef file fill:#FFFFFF,stroke:#7F7F7F,color:#000,shape:document;
    classDef external fill:#EDEDED,stroke:#AAAAAA,color:#000;
```
