# quantum-flytrap/quantum-tensors architecture

> Architecture diagram of the GitHub repository quantum-flytrap/quantum-tensors, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/quantum-flytrap/quantum-tensors
- Repository: https://github.com/quantum-flytrap/quantum-tensors

## Overview

##### Main Components

a) Core Mathematical Components:
- Complex Numbers Module (Complex.ts)
- Vector Operations Module (Vector.ts, VectorEntry.ts)
- Operator Module (Operator.ts, OperatorEntry.ts)
- Mathematical Helpers (helpers.ts)

b) Quantum Physics Components:
- Quantum Gates (Gates.ts)
- Quantum Circuits (Circuit.ts)
- Quantum Measurements (Measurement.ts)
- Quantum States (Basis.ts, Bell.ts)
- Photon Handling (Photons.ts)
- Entanglement Management (Entanglement.ts)

c) Simulation Layer:
- Main Simulation Engine (Simulation.ts)
- Constants and Configuration (Constants.ts)
- Frame Management (Frame.ts)

**┌─────────────────────────────────────────┐**
- Client Applications          │
- (Quantum Game 2, BraKetVue, etc.)     │
- ┘
- ↑
**┌─────────────────────────────────────────┐**
- Public API Interface            │
- (index.ts)                   │
- ┘
- ↑
**┌─────────────────────────────────────────┐**
- Simulation Layer                │
- (Simulation.ts, Frame.ts)             │
- ┘
- ↑
**┌─────────────────────────────────────────┐**
- Quantum Physics Components         │
- (Gates, Circuits, Measurements, etc.)  │
- ┘
- ↑
**┌─────────────────────────────────────────┐**
- Core Mathematical Components       │
- (Complex, Vector, Operator, etc.)     │
- ┘

##### Important Details to Highlight

a) Sparse tensor operations:
- How Vector and Operator classes interact
- Named tensor dimensions feature

b) Test coverage relationship:
- A side panel showing test files corresponding to each component

c) Integration points:
- How the library connects with external applications
- Npm package interface

##### Implementation Notes

- Clear hierarchical relationships
- Export to vector formats
- Easy maintenance and updates

##### Key Relationships

- How Complex.ts underlies all quantum operations
- The relationship between Circuit.ts and Gates.ts
- How Simulation.ts orchestrates all components
- The role of interfaces.ts in type definitions
- The connection between Measurement.ts and Operator.ts

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Client Applications"
        QG2["Quantum Game 2"]:::external
        BKV["BraKetVue"]:::external
    end

    subgraph "Public API Interface"
        API["Main API Entry Point"]:::api
        INT["Interface Definitions"]:::api
    end

    subgraph "Simulation Layer"
        SIM["Simulation Engine"]:::simulation
        FRAME["Frame Management"]:::simulation
        CONST["Constants & Config"]:::simulation
    end

    subgraph "Quantum Physics Components"
        GATES["Quantum Gates"]:::quantum
        CIRC["Quantum Circuits"]:::quantum
        MEAS["Quantum Measurements"]:::quantum
        BASIS["Quantum States - Basis"]:::quantum
        BELL["Quantum States - Bell"]:::quantum
        PHOT["Photon Handling"]:::quantum
        ENT["Entanglement Management"]:::quantum
    end

    subgraph "Core Mathematical Components"
        COMP["Complex Numbers"]:::math
        VEC["Vector Operations"]:::math
        VECENT["Vector Entry"]:::math
        OP["Operator"]:::math
        OPENT["Operator Entry"]:::math
        HELP["Mathematical Helpers"]:::math
    end

    subgraph "Testing Infrastructure"
        CTEST["Core Math Tests"]:::test
        QTEST["Quantum Physics Tests"]:::test
        STEST["Simulation Tests"]:::test
    end

    subgraph "Performance"
        BENCH["Benchmarking Tools"]:::perf
    end

    %% Relationships
    QG2 & BKV --> API
    API --> INT
    API --> SIM
    INT --> SIM

    SIM --> FRAME
    SIM --> CONST
    SIM --> GATES
    SIM --> CIRC
    SIM --> MEAS

    GATES --> COMP
    GATES --> VEC
    GATES --> OP

    CIRC --> GATES
    MEAS --> OP
    BASIS & BELL --> VEC
    PHOT --> COMP
    ENT --> MEAS

    VEC --> VECENT
    OP --> OPENT
    VEC & OP --> HELP
    VECENT & OPENT --> COMP

    CTEST -.-> COMP & VEC & OP
    QTEST -.-> GATES & CIRC & MEAS
    STEST -.-> SIM
    BENCH -.-> SIM

    %% Click Events
    click API "https://github.com/Quantum-Flytrap/quantum-tensors/blob/master/src/index.ts"
    click INT "https://github.com/Quantum-Flytrap/quantum-tensors/blob/master/src/interfaces.ts"
    click SIM "https://github.com/Quantum-Flytrap/quantum-tensors/blob/master/src/Simulation.ts"
    click FRAME "https://github.com/Quantum-Flytrap/quantum-tensors/blob/master/src/Frame.ts"
    click CONST "https://github.com/Quantum-Flytrap/quantum-tensors/blob/master/src/Constants.ts"
    click GATES "https://github.com/Quantum-Flytrap/quantum-tensors/blob/master/src/Gates.ts"
    click CIRC "https://github.com/Quantum-Flytrap/quantum-tensors/blob/master/src/Circuit.ts"
    click MEAS "https://github.com/Quantum-Flytrap/quantum-tensors/blob/master/src/Measurement.ts"
    click BASIS "https://github.com/Quantum-Flytrap/quantum-tensors/blob/master/src/Basis.ts"
    click BELL "https://github.com/Quantum-Flytrap/quantum-tensors/blob/master/src/Bell.ts"
    click PHOT "https://github.com/Quantum-Flytrap/quantum-tensors/blob/master/src/Photons.ts"
    click ENT "https://github.com/Quantum-Flytrap/quantum-tensors/blob/master/src/Entanglement.ts"
    click COMP "https://github.com/Quantum-Flytrap/quantum-tensors/blob/master/src/Complex.ts"
    click VEC "https://github.com/Quantum-Flytrap/quantum-tensors/blob/master/src/Vector.ts"
    click VECENT "https://github.com/Quantum-Flytrap/quantum-tensors/blob/master/src/VectorEntry.ts"
    click OP "https://github.com/Quantum-Flytrap/quantum-tensors/blob/master/src/Operator.ts"
    click OPENT "https://github.com/Quantum-Flytrap/quantum-tensors/blob/master/src/OperatorEntry.ts"
    click HELP "https://github.com/Quantum-Flytrap/quantum-tensors/blob/master/src/helpers.ts"
    click CTEST "https://github.com/Quantum-Flytrap/quantum-tensors/tree/master/tests"
    click QTEST "https://github.com/Quantum-Flytrap/quantum-tensors/tree/master/tests"
    click STEST "https://github.com/Quantum-Flytrap/quantum-tensors/tree/master/tests"
    click BENCH "https://github.com/Quantum-Flytrap/quantum-tensors/tree/master/benchmarks"

    %% Styles
    classDef external fill:#gray,stroke:#333,stroke-width:2px
    classDef api fill:#purple,stroke:#333,stroke-width:2px
    classDef simulation fill:#orange,stroke:#333,stroke-width:2px
    classDef quantum fill:#green,stroke:#333,stroke-width:2px
    classDef math fill:#blue,stroke:#333,stroke-width:2px
    classDef test fill:#yellow,stroke:#333,stroke-width:2px
    classDef perf fill:#red,stroke:#333,stroke-width:2px
```
