# pytorch/botorch architecture

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

- Interactive diagram: https://gitdiagram.com/pytorch/botorch
- Repository: https://github.com/pytorch/botorch

## Overview

##### Main Components Overview

a. Core Components:
- Models Layer (botorch/models/)
- Acquisition Functions Layer (botorch/acquisition/)
- Optimization Layer (botorch/optim/)
- Sampling Layer (botorch/sampling/)
- Posteriors Layer (botorch/posteriors/)
- Utilities Layer (botorch/utils/)

b. Integration Components:
- PyTorch Integration
- GPyTorch Integration
- Ax Platform Integration

**Top Level:**
**[External Interfaces] (Ax, PyTorch, GPyTorch)**
- ↑
**[BoTorch Core API]**
- ↑
**[Functional Layers]**
- ↑
**[Foundation Layer]**

##### Component Relationships

a. Primary Data Flow:
**Input Data → Models → Posteriors → Acquisition Functions → Optimization → Recommendations**

b. Support Systems:
**Sampling System ←→ Models**
**Utils ←→ All Components**
**Settings ←→ All Components**

##### Specific Implementation Details

a. Model System:
- SingleTaskGP
- MultiTaskGP
- ModelListGP
- Transforms and Kernels

b. Acquisition Functions:
- Expected Improvement
- Knowledge Gradient
- Upper Confidence Bound
- Multi-objective variants

c. Optimization Components:
- Acquisition Optimizers
- Model Fitting
- Constraint Handling

##### Key Features to Highlight

- Monte Carlo capabilities
- GPU Support
- Auto-differentiation
- Multi-task/Multi-fidelity support
- Modular design

- External[External Interfaces]
- Core[BoTorch Core]
- Models[Models Layer]
- Acquisition[Acquisition Functions]
- Optimization[Optimization Layer]

- External --> Core
- Core --> Models
- Core --> Acquisition
- Core --> Optimization

##### Documentation Integration

References to:
- API Documentation
- Tutorials
- Example Workflows
- Integration Patterns

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef external fill:#FFE873,stroke:#333,stroke-width:2px
    classDef core fill:#4B8BBE,stroke:#333,stroke-width:2px
    classDef models fill:#306998,stroke:#333,stroke-width:2px
    classDef acquisition fill:#FFB86C,stroke:#333,stroke-width:2px
    classDef optimization fill:#50FA7B,stroke:#333,stroke-width:2px
    classDef sampling fill:#BD93F9,stroke:#333,stroke-width:2px
    classDef utils fill:#999999,stroke:#333,stroke-width:2px

    %% External Interfaces
    subgraph External["External Interfaces"]
        PyTorch["PyTorch"]:::external
        GPyTorch["GPyTorch"]:::external
        Ax["Ax Platform"]:::external
    end

    %% Core Layer
    subgraph Core["BoTorch Core API"]
        CoreAPI["Core API"]:::core
    end

    %% Functional Layers
    subgraph Functional["Functional Layers"]
        %% Models
        Models["Models Layer"]:::models
        ModelKernels["Kernels"]:::models
        ModelTransforms["Transforms"]:::models
        ModelLikelihoods["Likelihoods"]:::models

        %% Acquisition
        AcqFunctions["Acquisition Functions"]:::acquisition
        MultiObjAcq["Multi-objective Acquisition"]:::acquisition

        %% Optimization
        Optimization["Optimization Layer"]:::optimization
        OptClosures["Optimization Closures"]:::optimization

        %% Sampling & Posteriors
        Sampling["Sampling Layer"]:::sampling
        PathSampling["Pathwise Sampling"]:::sampling
        Posteriors["Posteriors Layer"]:::sampling

        %% Utils
        Utils["Utilities Layer"]:::utils
        MultiObjUtils["Multi-objective Utils"]:::utils
        TestFunctions["Test Functions"]:::utils
    end

    %% Relationships
    PyTorch & GPyTorch & Ax --> CoreAPI
    CoreAPI --> Models & AcqFunctions & Optimization & Sampling & Posteriors & Utils

    Models --> ModelKernels & ModelTransforms & ModelLikelihoods
    AcqFunctions --> MultiObjAcq
    Optimization --> OptClosures
    Sampling --> PathSampling
    Utils --> MultiObjUtils & TestFunctions

    %% Click Events
    click Models "https://github.com/pytorch/botorch/tree/main/botorch/models/"
    click AcqFunctions "https://github.com/pytorch/botorch/tree/main/botorch/acquisition/"
    click Optimization "https://github.com/pytorch/botorch/tree/main/botorch/optim/"
    click Sampling "https://github.com/pytorch/botorch/tree/main/botorch/sampling/"
    click Posteriors "https://github.com/pytorch/botorch/tree/main/botorch/posteriors/"
    click Utils "https://github.com/pytorch/botorch/tree/main/botorch/utils/"
    click MultiObjAcq "https://github.com/pytorch/botorch/tree/main/botorch/acquisition/multi_objective/"
    click ModelKernels "https://github.com/pytorch/botorch/tree/main/botorch/models/kernels/"
    click ModelTransforms "https://github.com/pytorch/botorch/tree/main/botorch/models/transforms/"
    click ModelLikelihoods "https://github.com/pytorch/botorch/tree/main/botorch/models/likelihoods/"
    click MultiObjUtils "https://github.com/pytorch/botorch/tree/main/botorch/utils/multi_objective/"
    click OptClosures "https://github.com/pytorch/botorch/tree/main/botorch/optim/closures/"
    click PathSampling "https://github.com/pytorch/botorch/tree/main/botorch/sampling/pathwise/"
    click TestFunctions "https://github.com/pytorch/botorch/tree/main/botorch/test_functions/"
```
