# fc-tud/material-optimization architecture

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

- Interactive diagram: https://gitdiagram.com/fc-tud/material-optimization
- Repository: https://github.com/fc-tud/material-optimization

## Overview

##### Project Type and Purpose
- The project is a research-oriented, full-stack machine learning system that trains various models (using approaches like AutoML, PyTorch, etc.) and then employs optimization routines to improve material design metrics.
- The README clarifies that the repository supports model training (with a generic train.py script) and a couple of use-case–specific optimization workflows (opti_sim_pan.py and opti_sim_trc.py) based on configurations found in config.py.
- The project integrates components such as experiment scripts, model binaries, result saving, and plotting utilities—all meant to replicate experiments described in the paper.

##### File Structure Highlights and Architectural Patterns
- Data: The project has a well-defined data layer in the data directory:
- Data is separated into “run” (for training) and “storage” (holding multiple datasets for different simulation cases like SIM-PAN-50, SIM-PAN-100, etc.).
- Environment Configurations: The envs folder has several YAML files for conda environments used with different frameworks (autosklearn, PyTorch, etc.).
- auto_ml (containing wrappers for autosklearn, XGBoost, etc.)
- pytorch models including custom architectures (e.g., ffnn_mtl)
- domain specific implementations such as sim_pan and sim_trc. The latter also includes an exeDir indicating potential external simulation executables.
- Helpers exist to provide common functionality like data handling or quantile regression.
- Optimization: The src/optimization directory contains key files that define constant parameters, various optimizers (ng_optimizer, sci_kit_optimizer), and use-case specific scripts for sim_pan and sim_trc optimization.
- Scripts: The scripts folder includes standalone scripts (both Python scripts and notebooks) to run the workflows: training, model evaluation, database creation, plotting, and optimization.
- Model Artifacts and Results: The ml_models_bin and results directories house output model files and experimental results respectively.

A. Data Layer:
- Data ingestion and storage system. Include nodes for:
- Raw datasets (from data/storage).
- Runtime data for training (data/run).
- How the data is accessed by the training scripts and pre-processing helpers within the models folder.

B. Model Training & Experimentation:
- Entry point (train.py) which reads configurations (config.py) and calls routines defined in src/models.
- Subdivide the training module into components:
▪ AutoML (using modules in src/models/auto_ml),
▪ PyTorch (in src/models/pytorch),
▪ Domain-specific models (SimPAN and SimTRC in src/models/sim_pan and src/models/sim_trc).
- That after training, models are serialized/pickled and stored in ml_models_bin.

C. Optimization Pipeline:
- Differentiate between the two use cases:
▪ SimPAN optimization (via opti_sim_pan.py and src/optimization/use_case_sim_pan.py),
▪ SimTRC optimization (via opti_sim_trc.py and src/optimization/use_case_sim_trc.py).
- That these scripts use the previously trained models (i.e., loading model.pkl from ml_models_bin) and run optimization algorithms (ng_optimizer, sci_kit_optimizer, etc.).
- External executables (e.g., in src/models/sim_trc/exeDir) might be depicted as “External Simulation Tools” that are executed as part of the workflow.

D. Result Storage & Visualization:
- A “Results Module”:
- Where results and logs are stored (results folder and workdir directories as mentioned in the README).
- Elements for the plotting and evaluation scripts/notebooks (e.g., evaluate_opti_pan.ipynb, plot_sim_trc_f_over_dis.ipynb).
- That visualization depends on outputs from both training and optimization.

E. Supporting Infrastructure:
- Environment Setup: Represent the environment configurations (envs folder with multiple YAMLs) to underline dependency management.
- Configurations: A separate node for config.py that serves as the central configuration for training and optimization.
- Scripts & Database Creation: Include a component to cover additional utility scripts (scripts/create_pan_database.py, scripts/create_trc_database.py) that help set up or manage experiments.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Layer
    subgraph "Data Layer"
        DS["Raw Data: data/storage"]:::data
        DR["Runtime Data: data/run"]:::data
    end

    %% Environment and Global Configurations
    subgraph "Configuration and Environment"
        ENV["Environment Configs: envs"]:::config
        CFG["Global Config: config.py"]:::config
    end

    %% Training Module
    subgraph "Training Module"
        TENT["Training Entry: scripts/train.py"]:::training
        AUTO["AutoML Module: src/models/auto_ml"]:::training
        PT["PyTorch Module: src/models/pytorch"]:::training
        SIMPAN["SimPAN Module: src/models/sim_pan"]:::training
        SIMTRC["SimTRC Module: src/models/sim_trc"]:::training
    end

    %% Model Artifacts Storage
    MST["Model Storage: ml_models_bin"]:::data

    %% Optimization Module
    subgraph "Optimization Module"
        OPTI_PAN["SimPAN Optimization: scripts/opti_sim_pan.py"]:::optimization
        OPTI_TRC["SimTRC Optimization: scripts/opti_sim_trc.py"]:::optimization
        OPT_CORE["Optimization Routines: src/optimization"]:::optimization
        EXT_SIM["External Sim Tools: src/models/sim_trc/exeDir"]:::external
    end

    %% Results and Visualization
    subgraph "Results Module"
        RES["Results Storage: results"]:::results
        VIS["Visualization: evaluation & plotting notebooks"]:::results
    end

    %% Experiment Setup and Database Creation
    subgraph "Experiment Setup"
        DB_PAN["Database Creation: scripts/create_pan_database.py"]:::script
        DB_TRC["Database Creation: scripts/create_trc_database.py"]:::script
    end

    %% Data Flow Connections
    DS -->|"feeds"| TENT
    DR -->|"feeds"| TENT

    ENV -->|"configures"| TENT
    CFG -->|"configures"| TENT

    TENT -->|"calls"| AUTO
    TENT -->|"calls"| PT
    TENT -->|"calls"| SIMPAN
    TENT -->|"calls"| SIMTRC

    AUTO -->|"produces models"| MST
    PT -->|"produces models"| MST
    SIMPAN -->|"produces models"| MST
    SIMTRC -->|"produces models"| MST

    MST -->|"supplies models"| OPT_CORE
    MST -->|"supplies models"| OPTI_PAN
    MST -->|"supplies models"| OPTI_TRC
    CFG -->|"guides"| OPT_CORE
    CFG -->|"guides"| OPTI_PAN
    CFG -->|"guides"| OPTI_TRC

    EXT_SIM -->|"integrates with"| OPT_CORE

    OPTI_PAN -->|"outputs"| RES
    OPTI_TRC -->|"outputs"| RES
    OPT_CORE -->|"outputs"| RES

    MST -->|"supports"| VIS
    OPTI_PAN -->|"supports"| VIS
    OPTI_TRC -->|"supports"| VIS

    %% Experiment Setup connections
    DB_PAN -->|"initiates"| MST
    DB_TRC -->|"initiates"| MST

    %% Click Events
    click DS "https://github.com/fc-tud/material-optimization/tree/main/data/storage"
    click DR "https://github.com/fc-tud/material-optimization/tree/main/data/run"
    click ENV "https://github.com/fc-tud/material-optimization/tree/main/envs"
    click CFG "https://github.com/fc-tud/material-optimization/blob/main/config.py"
    click TENT "https://github.com/fc-tud/material-optimization/blob/main/scripts/train.py"
    click AUTO "https://github.com/fc-tud/material-optimization/tree/main/src/models/auto_ml"
    click PT "https://github.com/fc-tud/material-optimization/tree/main/src/models/pytorch"
    click SIMPAN "https://github.com/fc-tud/material-optimization/tree/main/src/models/sim_pan"
    click SIMTRC "https://github.com/fc-tud/material-optimization/tree/main/src/models/sim_trc"
    click EXT_SIM "https://github.com/fc-tud/material-optimization/tree/main/src/models/sim_trc/exeDir"
    click MST "https://github.com/fc-tud/material-optimization/tree/main/ml_models_bin"
    click OPTI_PAN "https://github.com/fc-tud/material-optimization/blob/main/scripts/opti_sim_pan.py"
    click OPTI_TRC "https://github.com/fc-tud/material-optimization/blob/main/scripts/opti_sim_trc.py"
    click OPT_CORE "https://github.com/fc-tud/material-optimization/tree/main/src/optimization"
    click RES "https://github.com/fc-tud/material-optimization/tree/main/results"
    click VIS "https://github.com/fc-tud/material-optimization/blob/main/scripts/evaluate_opti_pan.ipynb"
    click DB_PAN "https://github.com/fc-tud/material-optimization/blob/main/scripts/create_pan_database.py"
    click DB_TRC "https://github.com/fc-tud/material-optimization/blob/main/scripts/create_trc_database.py"

    %% Styles
    classDef data fill:#D6EAF8,stroke:#1B4F72,stroke-width:2px;
    classDef training fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef optimization fill:#A9DFBF,stroke:#1E8449,stroke-width:2px;
    classDef results fill:#F9E79F,stroke:#B9770E,stroke-width:2px;
    classDef config fill:#D5DBDB,stroke:#566573,stroke-width:2px;
    classDef script fill:#E8DAEF,stroke:#884EA0,stroke-width:2px;
    classDef external fill:#FADBD8,stroke:#CB4335,stroke-width:2px;
```
