# doubleml/doubleml-for-py architecture

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

- Interactive diagram: https://gitdiagram.com/doubleml/doubleml-for-py
- Repository: https://github.com/doubleml/doubleml-for-py

## Overview

##### Project type and purpose
- This is an open-source Python library (package) implementing the double/debiased machine learning framework of Chernozhukov et al. (2018).
- Its purpose is to provide a flexible, object-oriented API for estimating treatment effects and structural parameters, with support for partially linear regression (PLR), partially linear IV (PLIV), interactive regression (IRM), and interactive IV (IIVM) models.

##### File structure
- Top-level artifacts:
- `doubleml/` — main code base, broken down by submodules:
– `data/` — data classes (`BaseData`, `ClusterData`, `PanelData`) + utils
– `datasets.py` — built-in data generators for demos
– `did/` — Difference-in-Differences models + tests
– `irm/` — Interactive regression models + tests
– `plm/` — Partially linear models (PLR, PLIV) + tests
– `rdd/` — Regression discontinuity designs + tests
– `utils/` — shared utilities (checks, plots, resampling, learners) + tests
– `double_ml.py` & `double_ml_framework.py` — core `DoubleML` abstract class and main orchestration
- `doc/` — Sphinx documentation, templates, auto-generated API docs
- `tests/` & module-specific `tests/` — pytest suites
- `pyproject.toml`, `pytest.ini`, CI workflows, linting & packaging configs

##### README for additional insights
- Core components: abstract `DoubleML` base class + four concrete model classes (`DoubleMLPLR`, `DoubleMLPLIV`, `DoubleMLIRM`, `DoubleMLIIVM`).
- Workflow methods: `.fit()`, `.bootstrap()`, `.confint()`, `.p_adjust()`, `.tune()`.
- Built on scikit-learn, numpy, pandas, scipy, statsmodels, joblib.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User/API Layer
    subgraph "User/API Layer"
        API["DoubleML API"]:::core
    end
    click API "https://github.com/doubleml/doubleml-for-py/blob/main/doubleml/double_ml.py"
    click API "https://github.com/doubleml/doubleml-for-py/blob/main/doubleml/double_ml_framework.py"

    %% Data Layer
    subgraph "Data Layer"
        DataWrapper["DataWrapper\n(BaseData, ClusterData, PanelData)"]:::data
        Datasets["Datasets (DGP generators)"]:::data
    end
    click DataWrapper "https://github.com/doubleml/doubleml-for-py/tree/main/doubleml/data/"
    click Datasets "https://github.com/doubleml/doubleml-for-py/blob/main/doubleml/datasets.py"

    %% Core Orchestration
    subgraph "Core Orchestration"
        BaseClass["DoubleMLBase"]:::core
        ScoreMixins["Score & Resampling Mixins"]:::core
    end
    click BaseClass "https://github.com/doubleml/doubleml-for-py/blob/main/doubleml/double_ml_framework.py"
    click BaseClass "https://github.com/doubleml/doubleml-for-py/blob/main/doubleml/double_ml.py"
    click ScoreMixins "https://github.com/doubleml/doubleml-for-py/blob/main/doubleml/double_ml_score_mixins.py"

    %% Model Implementations
    subgraph "Model Implementations"
        subgraph "PLM"
            PLR["DoubleMLPLR"]:::model
            PLIV["DoubleMLPLIV"]:::model
        end
        subgraph "IRM & IVM"
            IRM["DoubleMLIRM"]:::model
            IIVM["DoubleMLIIVM"]:::model
            APO["APO"]:::model
            APOS["APOS"]:::model
            PQ["PQ"]:::model
            QTE["QTE"]:::model
            CVAR["CVaR"]:::model
            LPQ["LPQ"]:::model
            SSM["SSM"]:::model
        end
        subgraph "DiD"
            DID["DiD Models"]:::model
        end
        subgraph "RDD"
            RDD["RDD Models"]:::model
        end
    end
    click PLR "https://github.com/doubleml/doubleml-for-py/blob/main/doubleml/plm/plr.py"
    click PLIV "https://github.com/doubleml/doubleml-for-py/blob/main/doubleml/plm/pliv.py"
    click IRM "https://github.com/doubleml/doubleml-for-py/blob/main/doubleml/irm/irm.py"
    click IIVM "https://github.com/doubleml/doubleml-for-py/blob/main/doubleml/irm/iivm.py"
    click APO "https://github.com/doubleml/doubleml-for-py/blob/main/doubleml/irm/apo.py"
    click APOS "https://github.com/doubleml/doubleml-for-py/blob/main/doubleml/irm/apos.py"
    click PQ "https://github.com/doubleml/doubleml-for-py/blob/main/doubleml/irm/pq.py"
    click QTE "https://github.com/doubleml/doubleml-for-py/blob/main/doubleml/irm/qte.py"
    click CVAR "https://github.com/doubleml/doubleml-for-py/blob/main/doubleml/irm/cvar.py"
    click LPQ "https://github.com/doubleml/doubleml-for-py/blob/main/doubleml/irm/lpq.py"
    click SSM "https://github.com/doubleml/doubleml-for-py/blob/main/doubleml/irm/ssm.py"
    click DID "https://github.com/doubleml/doubleml-for-py/blob/main/doubleml/did/did.py"
    click RDD "https://github.com/doubleml/doubleml-for-py/blob/main/doubleml/rdd/rdd.py"

    %% ML Backend
    subgraph "Machine-Learning Backend"
        SKL["scikit-learn Estimators"]:::external
        Joblib["joblib Parallelism"]:::external
    end

    %% Utilities
    subgraph "Utilities"
        Checks["Data Checks"]:::util
        Plots["Plotting"]:::util
        Sensitivity["Sensitivity Analysis"]:::util
        Gain["Gain Statistics"]:::util
        Policy["Policy Trees"]:::util
    end
    click Checks "https://github.com/doubleml/doubleml-for-py/blob/main/doubleml/utils/_checks.py"
    click Plots "https://github.com/doubleml/doubleml-for-py/blob/main/doubleml/utils/_plots.py"
    click Sensitivity "https://github.com/doubleml/doubleml-for-py/blob/main/doubleml/utils/_sensitivity.py"
    click Gain "https://github.com/doubleml/doubleml-for-py/blob/main/doubleml/utils/gain_statistics.py"
    click Policy "https://github.com/doubleml/doubleml-for-py/blob/main/doubleml/utils/policytree.py"

    %% Output & Inference
    Output["Output & Inference\n(fit, bootstrap, confint, p_adjust)"]:::core

    %% Documentation & Testing
    subgraph "Docs / Testing / CI"
        Docs["Documentation (Sphinx)"]:::docs
        Tests["Pytest Suites"]:::docs
        CI["CI Pipelines"]:::docs
    end

    %% Connections
    API -->|"ingest data"| DataWrapper
    API -->|"generate DGP"| Datasets
    DataWrapper -->|".__init__"| BaseClass
    Datasets -->|".__init__"| BaseClass
    BaseClass -->|"instantiate"| ScoreMixins
    BaseClass -->|"inherit"| PLR
    BaseClass -->|"inherit"| PLIV
    BaseClass -->|"inherit"| IRM
    BaseClass -->|"inherit"| IIVM
    PLR -->|"uses"| ScoreMixins
    PLIV -->|"uses"| ScoreMixins
    IRM -->|"uses"| ScoreMixins
    IIVM -->|"uses"| ScoreMixins
    ScoreMixins -->|"cross-fit splits"| SKL
    SKL -->|"predictions"| ScoreMixins
    ScoreMixins -->|"orthogonal scores"| BaseClass
    BaseClass -->|"compute estimates"| Output
    Checks -->|invoked| BaseClass
    Plots -->|optional| Output
    Sensitivity -->|optional| Output
    Gain -->|optional| Output
    Policy -->|optional| Output
    Output -->|document results| Docs
    API -->|calls tests| Tests
    Tests -->|run on| BaseClass
    Tests -->|run on| PLR
    CI -->|runs| Tests

    %% Styles
    classDef core fill:#D0E1FF,stroke:#2E6BA0,color:#000;
    classDef data fill:#E0F8D0,stroke:#3A8A00,color:#000;
    classDef model fill:#D0FFD8,stroke:#008A29,color:#000;
    classDef external fill:#FFE8B0,stroke:#D27F00,color:#000;
    classDef util fill:#F0E0FF,stroke:#7A3AB0,color:#000;
    classDef docs fill:#E8E8E8,stroke:#666,color:#000;
```
