# andreichertkov/ttopt architecture

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

- Interactive diagram: https://gitdiagram.com/andreichertkov/ttopt
- Repository: https://github.com/andreichertkov/ttopt

## Overview

##### Project’s Main Components
- Core Optimization Library (ttopt package):
- This is found in the “ttopt” folder, which includes key modules like ttopt.py, ttopt_raw.py, and maxvol.py. These files encapsulate the core algorithm implementations that perform the optimization using the TT-format.
- Demonstration Scripts:
- The “demo” folder contains various example scripts (base.py, qtt.py, qtt_max.py, qtt_100d.py, vect.py, cache.py, tensor.py, tensor_init.py). These serve as interfaces to showcase how to use the core optimization functionalities in different scenarios.
- Legacy/Experimental Code:
- The “computations_old” directory contains previous iterations of experiments and calculation scripts. Although these have been deprecated in recent versions for production, they show the evolution and can be useful if someone wants to understand experimental approaches.
- Packaging and Configuration Components:
- Files such as setup.py, setup.cfg, MANIFEST.in, requirements.txt, and LICENSE.txt facilitate installation, distribution, and dependency management.
- Documentation:
- The top-level README.md provides a high-level description, usage examples, and citation guidelines.

##### Relationships and Interactions
- The demo scripts directly interact with the core optimization library to illustrate different use cases and algorithm variants.
- The core functions (in ttopt and its modules) likely interact with external libraries (e.g., teneva as indicated in the README) to perform tensor operations.
- Legacy components in computations_old, while less central, may still interface with similar core components and provide comparative or complementary experimental demonstrations.
- The packaging/configuration files indicate how the library is structured, built, and distributed, but they don't typically interact at runtime.

##### Architectural Patterns and Design Principles
- Modular Design:
- The project cleanly separates its optimization algorithms (ttopt) from its demonstration scripts (demo) and legacy experiments (computations_old). This clear separation supports both maintainability and extensibility.
- Layered Architecture:
- At the lowest level lies the core math/optimization routines (e.g., low-level tensor manipulation via maxvol, ttopt_raw). The next layer provides higher-level abstraction through the ttopt module, which the demos consume.
- Experimental Isolation:
- The computations_old directory is isolated from the current production code, which reflects a design that evolutionarily separates experimental work from stable releases.

##### Relevant Technologies, Frameworks, and Libraries
- Python 3.7 or higher is required.
- Use of tensor train methods suggests reliance on numerical libraries (likely NumPy, etc.) and possibly other scientific libraries.
- The reference to teneva in the README indicates that integration with or inspiration from another specialized TT-format library exists.

##### Elements
- Core Library Components: ttopt, ttopt_raw, maxvol.
- Demo Scripts: each demo file or a grouped “Demo” module.
- Legacy/Experimental Code: computations_old.
- External Dependencies: teneva and other potential utility libraries.
- From demos to core library methods.
- Visual Differentiation:
- Use annotations to highlight design principles (like “Modular Design” or “Layered Architecture”) where appropriate.

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Core Optimization Library"
        coreTtopt("ttopt.py"):::core
        coreTtoptRaw("ttopt_raw.py"):::core
        coreMaxvol("maxvol.py"):::core
    end

    subgraph "Demonstration Scripts"
        demoBase("base.py"):::demo
        demoQtt("qtt.py"):::demo
        demoQttMax("qtt_max.py"):::demo
        demoQtt100d("qtt_100d.py"):::demo
        demoVect("vect.py"):::demo
        demoCache("cache.py"):::demo
        demoTensor("tensor.py"):::demo
        demoTensorInit("tensor_init.py"):::demo
    end

    subgraph "Legacy/Experimental Code"
        legacy("computations_old/"):::legacy
    end

    subgraph "Packaging & Configuration"
        pkgSetup("setup.py"):::pkg
        pkgSetupCfg("setup.cfg"):::pkg
        pkgManifest("MANIFEST.in"):::pkg
        pkgReq("requirements.txt"):::pkg
        pkgLicense("LICENSE.txt"):::pkg
        pkgReadme("README.md"):::pkg
    end

    subgraph "External Dependencies"
        externalTeneva("teneva"):::external
        externalNumPy("NumPy"):::external
    end

    %% Connections
    demoBase -->|"calls"| coreTtopt
    legacy -->|"experiments"| coreMaxvol
    coreTtopt -->|"uses"| externalTeneva
    coreTtoptRaw -->|"depends"| externalNumPy

    %% Click Events
    click coreTtopt "https://github.com/andreichertkov/ttopt/blob/master/ttopt/ttopt.py"
    click coreTtoptRaw "https://github.com/andreichertkov/ttopt/blob/master/ttopt/ttopt_raw.py"
    click coreMaxvol "https://github.com/andreichertkov/ttopt/blob/master/ttopt/maxvol.py"
    click demoBase "https://github.com/andreichertkov/ttopt/blob/master/demo/base.py"
    click demoQtt "https://github.com/andreichertkov/ttopt/blob/master/demo/qtt.py"
    click demoQttMax "https://github.com/andreichertkov/ttopt/blob/master/demo/qtt_max.py"
    click demoQtt100d "https://github.com/andreichertkov/ttopt/blob/master/demo/qtt_100d.py"
    click demoVect "https://github.com/andreichertkov/ttopt/blob/master/demo/vect.py"
    click demoCache "https://github.com/andreichertkov/ttopt/blob/master/demo/cache.py"
    click demoTensor "https://github.com/andreichertkov/ttopt/blob/master/demo/tensor.py"
    click demoTensorInit "https://github.com/andreichertkov/ttopt/blob/master/demo/tensor_init.py"
    click legacy "https://github.com/andreichertkov/ttopt/tree/master/computations_old/"
    click pkgSetup "https://github.com/andreichertkov/ttopt/blob/master/setup.py"
    click pkgSetupCfg "https://github.com/andreichertkov/ttopt/blob/master/setup.cfg"
    click pkgManifest "https://github.com/andreichertkov/ttopt/blob/master/MANIFEST.in"
    click pkgReq "https://github.com/andreichertkov/ttopt/blob/master/requirements.txt"
    click pkgLicense "https://github.com/andreichertkov/ttopt/blob/master/LICENSE.txt"
    click pkgReadme "https://github.com/andreichertkov/ttopt/blob/master/README.md"

    %% Styles
    classDef core fill:#FFCDD2,stroke:#B71C1C,stroke-width:2px;
    classDef demo fill:#C8E6C9,stroke:#2E7D32,stroke-width:2px;
    classDef legacy fill:#FFF9C4,stroke:#F57F17,stroke-width:2px;
    classDef pkg fill:#BBDEFB,stroke:#0D47A1,stroke-width:2px;
    classDef external fill:#D1C4E9,stroke:#6A1B9A,stroke-width:2px;
```
