# mwasifanwar/causal_generative_models architecture

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

- Interactive diagram: https://gitdiagram.com/mwasifanwar/causal_generative_models
- Repository: https://github.com/mwasifanwar/causal_generative_models

## Overview

##### Project type and purpose
- This is a Python-based open-source framework for building and experimenting with causal generative models (e.g., causal flows, causal GANs, causal VAEs).
- It exposes a CLI/entrypoint (`main.py`), a core library for causal abstractions, a suite of ready-made model implementations, utility functions for training/evaluation/visualization, and example scripts.

##### File structure
- Top-level modules:
- core: defines your causal abstractions (graphs, mechanisms, processes)
- models: implements concrete model classes (CausalFlow, CausalGAN, CausalVAE) that build on core
- utils: training utilities, evaluation metrics, and visualization routines
- examples: scripts demonstrating benchmarks, real-world use, and synthetic experiments
- main.py: CLI or demonstration driver
- setup.py & requirements.txt: packaging and dependencies
- Architectural pattern: a layered library/framework
- Core layer → Model layer → Application/CLI layer
- Utilities and examples leverage both core and model layers

##### README (absent)
- No direct architecture details provided; we infer architecture from the code organization itself.

a. Main components
1. Core Module
- causal_graphs.py
- causal_mechanisms.py
- causal_processes.py
2. Models Module
- causal_flows.py
- causal_gan.py
- causal_vae.py
3. Utils Module
- training_utils.py
- evaluation_metrics.py
- visualization.py
4. Examples
- benchmarks.py
- real_world_examples.py
- synthetic_experiments.py
5. Entry point / CLI
- main.py
6. External Dependencies
- Listed in requirements.txt (e.g., PyTorch, NumPy, NetworkX)
b. Relationships and interactions
- main.py imports from models, core, and utils to orchestrate training and evaluation workflows
- Models import core abstractions to define forward/backward passes and data generation
- Utils provide helper functions consumed by both main.py and example scripts
- Examples import main-level workflows or directly use core/models/utils to run experiments
c. Architectural patterns & principles
- Modular layering: clear separation of causal abstractions (core), model definitions (models), helper routines (utils), and executable scripts (examples/main)
- Dependency inversion: high-level scripts depend on interfaces exposed by core/models rather than low-level implementations
- Extensibility: new causal models can be added under models/ and will plug into the existing core and utils
d. Key technologies
- Python 3.x
- Deep-learning framework (likely PyTorch or TensorFlow via requirements.txt)
- Graph library for causal structure (e.g., NetworkX)
- Standard scientific stack (NumPy, SciPy, Matplotlib)

##### Essential details to capture
- Layer boundaries and dependency directions
- Module groupings and how they collaborate
- Entry points and extension points (especially under models)
- Shared utility services
- External framework or library dependencies as a supporting backdrop

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Entry Point
    Main["main.py\n(CLI Entrypoint)"]:::entry

    %% Core Module
    subgraph "Core Module"
        CG["causal_graphs.py\n(defines DAG structures)"]:::core
        CM["causal_mechanisms.py\n(defines mechanisms)"]:::core
        CP["causal_processes.py\n(defines processes)"]:::core
    end

    %% Models Module
    subgraph "Models Module"
        CF["causal_flows.py\n(CausalFlow model)"]:::models
        CGAN["causal_gan.py\n(CausalGAN model)"]:::models
        CVAE["causal_vae.py\n(CausalVAE model)"]:::models
    end

    %% Utils Module
    subgraph "Utils Module"
        TU["training_utils.py\n(training loops)"]:::utils
        EM["evaluation_metrics.py\n(metrics)"]:::utils
        VZ["visualization.py\n(plots & viz)"]:::utils
    end

    %% Examples Module
    subgraph "Examples Module"
        EB["benchmarks.py\n(benchmark scripts)"]:::examples
        ER["real_world_examples.py\n(real-world demos)"]:::examples
        ES["synthetic_experiments.py\n(synthetic tests)"]:::examples
    end

    %% External Dependencies
    ext["requirements.txt\n(external libs)"]:::external

    %% Packaging
    Setup["setup.py\n(packaging script)"]:::external

    %% Relationships
    Main -->|"imports models"| CF
    Main -->|"imports models"| CGAN
    Main -->|"imports models"| CVAE
    Main -->|"imports core"| CG
    Main -->|"imports core"| CM
    Main -->|"imports core"| CP
    Main -->|"imports utils"| TU
    Main -->|"imports utils"| EM
    Main -->|"imports utils"| VZ

    CF -->|"uses abstractions"| CG
    CF -->|"uses abstractions"| CM
    CF -->|"uses abstractions"| CP

    CGAN -->|"uses abstractions"| CG
    CGAN -->|"uses abstractions"| CM
    CGAN -->|"uses abstractions"| CP

    CVAE -->|"uses abstractions"| CG
    CVAE -->|"uses abstractions"| CM
    CVAE -->|"uses abstractions"| CP

    EB -->|"runs experiments on"| CF
    EB -->|"uses utils"| TU
    ER -->|"runs experiments on"| CGAN
    ER -->|"uses utils"| EM
    ES -->|"runs experiments on"| CVAE
    ES -->|"uses utils"| VZ

    ext --> Main
    ext --> CF
    ext --> CGAN
    ext --> CVAE
    ext --> CG
    ext --> CM
    ext --> CP
    ext --> TU
    ext --> EM
    ext --> VZ

    %% Click Events
    click CG "https://github.com/mwasifanwar/causal_generative_models/blob/main/core/causal_graphs.py"
    click CM "https://github.com/mwasifanwar/causal_generative_models/blob/main/core/causal_mechanisms.py"
    click CP "https://github.com/mwasifanwar/causal_generative_models/blob/main/core/causal_processes.py"
    click CF "https://github.com/mwasifanwar/causal_generative_models/blob/main/models/causal_flows.py"
    click CGAN "https://github.com/mwasifanwar/causal_generative_models/blob/main/models/causal_gan.py"
    click CVAE "https://github.com/mwasifanwar/causal_generative_models/blob/main/models/causal_vae.py"
    click TU "https://github.com/mwasifanwar/causal_generative_models/blob/main/utils/training_utils.py"
    click EM "https://github.com/mwasifanwar/causal_generative_models/blob/main/utils/evaluation_metrics.py"
    click VZ "https://github.com/mwasifanwar/causal_generative_models/blob/main/utils/visualization.py"
    click EB "https://github.com/mwasifanwar/causal_generative_models/blob/main/examples/benchmarks.py"
    click ER "https://github.com/mwasifanwar/causal_generative_models/blob/main/examples/real_world_examples.py"
    click ES "https://github.com/mwasifanwar/causal_generative_models/blob/main/examples/synthetic_experiments.py"
    click Main "https://github.com/mwasifanwar/causal_generative_models/blob/main/main.py"
    click ext "https://github.com/mwasifanwar/causal_generative_models/blob/main/requirements.txt"
    click Setup "https://github.com/mwasifanwar/causal_generative_models/blob/main/setup.py"

    %% Styles
    classDef core fill:#add8e6,stroke:#333,stroke-width:1px;
    classDef models fill:#90ee90,stroke:#333,stroke-width:1px;
    classDef utils fill:#ffcc99,stroke:#333,stroke-width:1px;
    classDef examples fill:#dda0dd,stroke:#333,stroke-width:1px;
    classDef entry fill:#d8bfd8,stroke:#333,stroke-width:1px;
    classDef external fill:#d3d3d3,stroke:#333,stroke-width:1px;
```
