# antoine311200/bsde-tensor-networks architecture

> Architecture diagram of the GitHub repository antoine311200/bsde-tensor-networks, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-10-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/antoine311200/bsde-tensor-networks
- Repository: https://github.com/antoine311200/bsde-tensor-networks

## Overview

##### Project Type and Purpose
- This is a scientific computing library and pipeline for solving high-dimensional parabolic PDEs via tensor-train methods.
- It provides a core Python package (`src/bsde_solver`) that implements:
- Basis and differential operators (calculus)
- Tensor-train data structures and operations
- Optimization algorithms (ALS, MALS, SALSA)
- Stochastic path generation
- End-to-end pipelines for explicit and implicit discretization
- On top of the core library, there are:
- CLI scripts (`src/scripts`) for running pipelines and benchmarking experiments
- Jupyter notebooks for exploration and visualization
- Automated tests under `src/bsde_solver/tests`

##### High-Level Architecture
- The system is layered:
1. **User Interface Layer**
– Jupyter notebooks (`notebooks/…`)
– Command-line scripts (`src/scripts`)
2. **Pipeline Layer**
– `src/bsde_solver/pipeline.py` (explicit)
– `src/scripts/pipeline_implicit.py` (implicit iterative)
3. **Core Library Layer** (`src/bsde_solver`)
a. **Core Modules**
- calculus: basis, derivative, Hessian
- tensor: core tensor operations, tensor_train, tensor_network
- optimisation: ALS, MALS, solve routines
- stochastic: Monte Carlo path generation
b. **Auxiliary**
- loss functions (`loss.py`)
- utility functions (`utils.py`)
4. **Infrastructure & Configuration**
– `pyproject.toml` (package metadata, dependencies)
– `.gitignore`
- Tests exercise each core submodule and ensure correctness.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interface Layer
    subgraph "User Interface Layer"
        NB["Jupyter Notebooks"]:::ui
        CS["CLI Scripts"]:::ui
        ES["Experiment Scripts"]:::ui
    end

    %% Pipeline Layer
    subgraph "Pipeline Layer"
        EP["Explicit Pipeline"]:::pipeline
        IP["Implicit Pipeline"]:::pipeline
    end

    %% Core Library Layer
    subgraph "Core Library Layer"
        subgraph "Calculus"
            Basis["Basis"]:::core
            Deriv["Derivative"]:::core
            Hess["Hessian"]:::core
        end
        subgraph "Tensor"
            TCore["Core Ops"]:::core
            TTrain["Tensor Train"]:::core
            TNet["Tensor Network"]:::core
        end
        subgraph "Optimisation"
            ALS["ALS"]:::core
            MALS["MALS"]:::core
            Solve["Solve"]:::core
        end
        Stoch["Path Gen"]:::core
        Loss["Loss Fn"]:::core
        Util["Utils"]:::core
        BSDE["BSDE Def"]:::core
    end

    %% Backends
    subgraph "Backends"
        Np["NumPy"]:::ext
        Cp["CuPy"]:::ext
    end

    %% Infrastructure & Configuration
    subgraph "Infrastructure & Configuration"
        PyProj["pyproject.toml"]:::infra
        GIgnore[".gitignore"]:::infra
    end

    %% Connections: UI -> Pipeline
    NB -->|select explicit| EP
    NB -->|select implicit| IP
    CS -->|run explicit| EP
    CS -->|run implicit| IP
    ES -->|benchmark| EP
    ES -->|benchmark| IP

    %% Pipeline to Core
    EP -->|generate paths| Stoch
    IP -->|generate paths| Stoch
    EP -->|setup basis| Basis
    IP -->|setup basis| Basis
    EP -->|init tensors| TCore
    IP -->|init tensors| TCore
    EP -->|orchestrate optimisation| Solve
    IP -->|orchestrate optimisation| Solve
    Solve -->|use ALS| ALS
    Solve -->|use MALS| MALS
    Solve -->|fallback SALSA| MALS
    EP -->|compute loss| Loss
    IP -->|compute loss| Loss
    EP -->|load BSDE def| BSDE
    IP -->|load BSDE def| BSDE
    EP -->|use utils| Util
    IP -->|use utils| Util

    %% Core to Backends
    Basis -->|lin algebra| Np
    Deriv -->|lin algebra| Np
    Hess -->|lin algebra| Np
    TCore -->|lin algebra| Np
    TTrain -->|lin algebra| Np
    TNet -->|lin algebra| Np
    ALS -->|lin algebra| Np
    MALS -->|lin algebra| Np
    Solve -->|lin algebra| Np
    Stoch -->|rand gen| Np
    Basis -->|GPU| Cp
    Deriv -->|GPU| Cp
    Hess -->|GPU| Cp
    TCore -->|GPU| Cp
    TTrain -->|GPU| Cp
    TNet -->|GPU| Cp
    ALS -->|GPU| Cp
    MALS -->|GPU| Cp
    Solve -->|GPU| Cp
    Stoch -->|GPU| Cp

    %% Outputs back to UI
    EP -->|solution| NB
    EP -->|solution| CS
    IP -->|solution| NB
    IP -->|solution| CS

    %% Click Events
    click NB "https://github.com/antoine311200/bsde-tensor-networks/tree/main/notebooks/"
    click CS "https://github.com/antoine311200/bsde-tensor-networks/tree/main/src/scripts/"
    click ES "https://github.com/antoine311200/bsde-tensor-networks/tree/main/src/scripts/experiments/"
    click EP "https://github.com/antoine311200/bsde-tensor-networks/blob/main/src/bsde_solver/pipeline.py"
    click IP "https://github.com/antoine311200/bsde-tensor-networks/blob/main/src/scripts/pipeline_explicit.py"
    click Basis "https://github.com/antoine311200/bsde-tensor-networks/blob/main/src/bsde_solver/core/calculus/basis.py"
    click Deriv "https://github.com/antoine311200/bsde-tensor-networks/blob/main/src/bsde_solver/core/calculus/derivative.py"
    click Hess "https://github.com/antoine311200/bsde-tensor-networks/blob/main/src/bsde_solver/core/calculus/hessian.py"
    click TCore "https://github.com/antoine311200/bsde-tensor-networks/blob/main/src/bsde_solver/core/tensor/tensor_core.py"
    click TTrain "https://github.com/antoine311200/bsde-tensor-networks/blob/main/src/bsde_solver/core/tensor/tensor_train.py"
    click TNet "https://github.com/antoine311200/bsde-tensor-networks/blob/main/src/bsde_solver/core/tensor/tensor_network.py"
    click ALS "https://github.com/antoine311200/bsde-tensor-networks/blob/main/src/bsde_solver/core/optimisation/als.py"
    click MALS "https://github.com/antoine311200/bsde-tensor-networks/blob/main/src/bsde_solver/core/optimisation/mals.py"
    click Solve "https://github.com/antoine311200/bsde-tensor-networks/blob/main/src/bsde_solver/core/optimisation/solve.py"
    click Stoch "https://github.com/antoine311200/bsde-tensor-networks/blob/main/src/bsde_solver/stochastic/path.py"
    click Loss "https://github.com/antoine311200/bsde-tensor-networks/blob/main/src/bsde_solver/loss.py"
    click Util "https://github.com/antoine311200/bsde-tensor-networks/blob/main/src/bsde_solver/utils.py"
    click BSDE "https://github.com/antoine311200/bsde-tensor-networks/blob/main/src/bsde_solver/bsde.py"
    click PyProj "https://github.com/antoine311200/bsde-tensor-networks/blob/main/pyproject.toml"
    click GIgnore "https://github.com/antoine311200/bsde-tensor-networks/blob/main/.gitignore"

    %% Styles
    classDef ui fill:#a8f0a2,stroke:#333,stroke-width:1px
    classDef pipeline fill:#f0c674,stroke:#333,stroke-width:1px
    classDef core fill:#8ecae6,stroke:#333,stroke-width:1px
    classDef ext fill:#dddddd,stroke:#333,stroke-width:1px
    classDef infra fill:#ffe599,stroke:#333,stroke-width:1px
```
