# hkuds/opengraph architecture

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

- Interactive diagram: https://gitdiagram.com/hkuds/opengraph
- Repository: https://github.com/hkuds/opengraph

## Overview

##### Project type and purpose
- This is a research‐oriented graph‐ML pipeline that supports both synthetic graph generation and downstream tasks (link prediction, node classification).
- It ingests multiple public graph datasets (cora, citeseer, amazon-book, etc.), generates embeddings, estimates instance counts, and runs training/evaluation for two core tasks.

##### File structure
- Top‐level directories:
- datasets: raw and preprocessed adjacency, feature, label, mask, and few‐shot matrices for multiple benchmarks
- graph_generation: code to create synthetic graphs/embeddings and utilities
- link_prediction, node_classification: two parallel pipelines for model training & evaluation
- Models: stores or documents trained model artifacts
- History: stores pretraining history snapshots
- Shared utilities under Exp_Utils and Utils subdirectories (emailer, timelogging)
- Configuration/parameter files: each pipeline has params.py
- Entrypoints: main.py in link_prediction and node_classification

##### README
- (Empty here): rely on file names, directory roles, and code patterns

a. Main components
- Data Store: “datasets” directory (raw graph inputs, few‐shot splits)
- Preprocessing Modules: graph_generation/make_adjs.py, instance_number_estimation, embedding_generation, human_item_generation, itemCollecting
- Synthetic Graph Repository: graph_generation/gen_results (stores generated adjacency, embeddings, interaction matrices)
- Training Pipelines:
– Link Prediction Pipeline: link_prediction/data_handler → link_prediction/model → link_prediction/main
– Node Classification Pipeline: node_classification/data_handler → node_classification/model → node_classification/main
- Model Artifacts Store: Models directory, History directory (pretraining states)
- Shared Utilities: TimeLogger, Emailer (for logging, notifications)
b. Relationships and interactions
- Data Store feeds Preprocessing Modules
- Preprocessing outputs both to Synthetic Graph Repository and intermediates back to Data Store
- Training Pipelines pull from both Data Store (real graphs) and Gen_Results (synthetic graphs)
- Training outputs models to Models and History
- Utilities wrap around all modules for logging and monitoring
c. Architectural patterns/design principles
- Modular pipeline: split into clear stages (ingest → preprocess → generate → train/evaluate)
- Separation of concerns: graph generation logic isolated from downstream task code
- Reusability: shared utils for logging/emailing; params files for configuration
- Data‐centric: file‐based data store for reproducibility, few‐shot splits, masks
d. Key technologies/frameworks
- Python scripts orchestrating experiments
- Pickle (.pkl) for data serialization
- Custom machine learning code (no deep integration with frameworks visible here)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Storage
    DataStore["Datasets\n(raw & preprocessed)"]:::storage
    SyntheticRepo["Synthetic Graph Repository\ngen_results/"]:::storage
    ModelStore["Models\n(model artifacts)"]:::storage
    HistoryStore["History\n(pretraining snapshots)"]:::storage

    %% Preprocessing Modules
    subgraph "Preprocessing Modules"
        direction TB
        MakeAdjs["make_adjs.py"]:::processing
        InstEst["instance_number_estimation_hierarchical.py"]:::processing
        EmbGen["embedding_generation.py"]:::processing
        HumanItem["human_item_generation_gibbsSampling_embedEstimation.py"]:::processing
        ItemCollecting["itemCollecting_dfsIterator.py"]:::processing
    end

    %% Shared Utilities
    subgraph "Shared Utilities"
        direction TB
        ExpEmailer["Emailer.py"]:::utils
        ExpTimeLogger["TimeLogger.py"]:::utils
        GraphUtils["Utils.py"]:::utils
    end

    %% Link Prediction Pipeline
    subgraph "Link Prediction Pipeline"
        direction TB
        LP_Params["params.py"]:::pipeline
        LP_DataHandler["data_handler.py"]:::pipeline
        LP_Model["model.py"]:::pipeline
        LP_Main["main.py"]:::pipeline
        LP_Logger["TimeLogger.py"]:::utils
    end

    %% Node Classification Pipeline
    subgraph "Node Classification Pipeline"
        direction TB
        NC_Params["params.py"]:::pipeline
        NC_DataHandler["data_handler.py"]:::pipeline
        NC_Model["model.py"]:::pipeline
        NC_Main["main.py"]:::pipeline
        NC_Logger["TimeLogger.py"]:::utils
    end

    %% Data Flow
    DataStore -->|ingests| MakeAdjs
    DataStore -->|ingests| InstEst
    DataStore -->|ingests| EmbGen
    DataStore -->|ingests| HumanItem
    DataStore -->|ingests| ItemCollecting

    MakeAdjs -->|outputs| SyntheticRepo
    InstEst -->|outputs| SyntheticRepo
    EmbGen -->|outputs| SyntheticRepo
    HumanItem -->|outputs| SyntheticRepo
    ItemCollecting -->|outputs| SyntheticRepo

    MakeAdjs -->|updates| DataStore
    InstEst -->|updates| DataStore
    EmbGen -->|updates| DataStore
    HumanItem -->|updates| DataStore
    ItemCollecting -->|updates| DataStore

    %% Pipelines consumption
    DataStore -->|uses real data| LP_DataHandler
    SyntheticRepo -->|uses synthetic| LP_DataHandler
    LP_DataHandler -->|feeds| LP_Model
    LP_Params -->|configures| LP_Main
    LP_Model -->|trained by| LP_Main
    LP_Main -->|saves to| ModelStore
    LP_Main -->|logs to| HistoryStore

    DataStore -->|uses real data| NC_DataHandler
    SyntheticRepo -->|uses synthetic| NC_DataHandler
    NC_DataHandler -->|feeds| NC_Model
    NC_Params -->|configures| NC_Main
    NC_Model -->|trained by| NC_Main
    NC_Main -->|saves to| ModelStore
    NC_Main -->|logs to| HistoryStore

    %% Utilities usage
    ExpTimeLogger -.-> MakeAdjs
    ExpTimeLogger -.-> LP_Main
    ExpTimeLogger -.-> NC_Main
    ExpEmailer -.-> LP_Main
    ExpEmailer -.-> NC_Main
    GraphUtils -.-> MakeAdjs
    GraphUtils -.-> EmbGen
    LP_Logger -.-> LP_Main
    NC_Logger -.-> NC_Main

    %% Click Events
    click DataStore "https://github.com/hkuds/opengraph/tree/main/datasets/"
    click MakeAdjs "https://github.com/hkuds/opengraph/blob/main/graph_generation/make_adjs.py"
    click InstEst "https://github.com/hkuds/opengraph/blob/main/graph_generation/instance_number_estimation_hierarchical.py"
    click EmbGen "https://github.com/hkuds/opengraph/blob/main/graph_generation/embedding_generation.py"
    click HumanItem "https://github.com/hkuds/opengraph/blob/main/graph_generation/human_item_generation_gibbsSampling_embedEstimation.py"
    click ItemCollecting "https://github.com/hkuds/opengraph/blob/main/graph_generation/itemCollecting_dfsIterator.py"
    click ExpEmailer "https://github.com/hkuds/opengraph/blob/main/graph_generation/Exp_Utils/Emailer.py"
    click ExpTimeLogger "https://github.com/hkuds/opengraph/blob/main/graph_generation/Exp_Utils/TimeLogger.py"
    click GraphUtils "https://github.com/hkuds/opengraph/blob/main/graph_generation/Utils.py"
    click SyntheticRepo "https://github.com/hkuds/opengraph/tree/main/graph_generation/gen_results/"
    click LP_Params "https://github.com/hkuds/opengraph/blob/main/link_prediction/params.py"
    click LP_DataHandler "https://github.com/hkuds/opengraph/blob/main/link_prediction/data_handler.py"
    click LP_Model "https://github.com/hkuds/opengraph/blob/main/link_prediction/model.py"
    click LP_Main "https://github.com/hkuds/opengraph/blob/main/link_prediction/main.py"
    click LP_Logger "https://github.com/hkuds/opengraph/blob/main/link_prediction/Utils/TimeLogger.py"
    click NC_Params "https://github.com/hkuds/opengraph/blob/main/node_classification/params.py"
    click NC_DataHandler "https://github.com/hkuds/opengraph/blob/main/node_classification/data_handler.py"
    click NC_Model "https://github.com/hkuds/opengraph/blob/main/node_classification/model.py"
    click NC_Main "https://github.com/hkuds/opengraph/blob/main/node_classification/main.py"
    click NC_Logger "https://github.com/hkuds/opengraph/blob/main/node_classification/Utils/TimeLogger.py"
    click ModelStore "https://github.com/hkuds/opengraph/tree/main/Models/"
    click HistoryStore "https://github.com/hkuds/opengraph/tree/main/History/"

    %% Styles
    classDef storage fill:#D0E6FF,stroke:#0366D6,color:#0366D6
    classDef processing fill:#DFFFE0,stroke:#2E8B57,color:#2E8B57
    classDef pipeline fill:#FFE6C7,stroke:#D2691E,color:#D2691E
    classDef utils fill:#F0F0F0,stroke:#A9A9A9,color:#696969
```
