# daxfohl/cirq architecture

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

- Interactive diagram: https://gitdiagram.com/daxfohl/cirq
- Repository: https://github.com/daxfohl/cirq

## Overview

##### Main Components
The system should be divided into these key components:

a. Core Framework (cirq-core):
- Circuit Management
- Operations & Gates
- Qubits & Devices
- Simulators
- Transformers
- Protocols

b. Hardware Providers:
- Google (cirq-google)
- IonQ (cirq-ionq)
- Pasqal (cirq-pasqal)
- Rigetti (cirq-rigetti)
- AQT (cirq-aqt)

c. Visualization Layer (cirq-web):
- Circuit Visualization
- Bloch Sphere Visualization
- Web Components

##### Component Relationships

**[User Code/Applications]**
- ↓
**[Cirq Core Framework]**
- ↙     ↓     ↘
**[Simulators] [Hardware Providers] [Visualization]**
- ↓           ↓                    ↓
**[Local      [Remote Quantum      [Interactive**
**Execution]   Execution]           Displays]**

##### Detailed Layer Breakdown

Core Framework Layer:
**┌─ Circuit Layer ─────┐    ┌─ Operations Layer ──┐**
- Circuit Building  │←→  │ - Gates            │
- Moment Management│    │ - Measurements     │
- ┬─┘    └────────┬───────────┘
- ↓              ↓
- ┌─ Transformation Layer ─┐
- Optimization        │
- Decomposition       │
- Routing            │
- ┬───────────┘
- ↓
- ┌─ Execution Layer ────┐
- Simulators        │
- Hardware Bridge   │
- ┘

##### Key Design Elements

- Blue: Core components
- Green: Hardware interfaces
- Orange: Visualization components
- Purple: Simulation components

b. Interface Boundaries:
- Clear separation between core library and hardware providers
- Protocol boundaries for quantum operations
- Serialization/deserialization points

c. Data Flow:
- Circuit creation → Transformation → Execution
- Results collection and processing
- Visualization pipeline

##### Implementation Details

Technical aspects:
**┌─ Protocol Layer ────┐    ┌─ Serialization ────┐**
- Unitary          │←→  │ - JSON             │
- Measurement      │    │ - Protocol Buffers │
- Channel          │    │                    │
- ┬─┘    └────────┬───────────┘
- ↓              ↓
- ┌─ Hardware Abstraction Layer ┐
- Device Specifications     │
- Noise Models              │
- ┬─┘
- ↓
- ┌─ Backend Providers ─┐
- Google           │
- IonQ             │
- Others           │
- ┬─┘

## Diagram (Mermaid)

```mermaid
graph TB
    %% Main Layers
    subgraph User["User Layer"]
        UC["User Code/Applications"]
    end

    subgraph Core["Core Framework"]
        direction TB
        CM["Circuit Management"]:::core
        OG["Operations & Gates"]:::core
        QD["Qubits & Devices"]:::core
        SM["Simulators"]:::core
        TR["Transformers"]:::core
        PR["Protocols"]:::core
    end

    subgraph Hardware["Hardware Providers"]
        direction TB
        GP["Google Provider"]:::hardware
        IP["IonQ Provider"]:::hardware
        PP["Pasqal Provider"]:::hardware
        RP["Rigetti Provider"]:::hardware
        AP["AQT Provider"]:::hardware
    end

    subgraph Viz["Visualization Layer"]
        direction TB
        CV["Circuit Visualization"]:::viz
        BS["Bloch Sphere Visualization"]:::viz
        WC["Web Components"]:::viz
    end

    %% Relationships
    UC --> CM
    UC --> OG
    
    CM <--> OG
    CM --> TR
    OG --> TR
    QD --> TR
    
    TR --> SM
    TR --> PR
    
    PR --> GP
    PR --> IP
    PR --> PP
    PR --> RP
    PR --> AP
    
    CM --> CV
    QD --> BS
    CV --> WC
    BS --> WC

    %% Click Events
    click CM "https://github.com/daxfohl/Cirq/tree/main/cirq-core/cirq/circuits/"
    click OG "https://github.com/daxfohl/Cirq/tree/main/cirq-core/cirq/ops/"
    click QD "https://github.com/daxfohl/Cirq/tree/main/cirq-core/cirq/devices/"
    click SM "https://github.com/daxfohl/Cirq/tree/main/cirq-core/cirq/sim/"
    click TR "https://github.com/daxfohl/Cirq/tree/main/cirq-core/cirq/transformers/"
    click PR "https://github.com/daxfohl/Cirq/tree/main/cirq-core/cirq/protocols/"
    click GP "https://github.com/daxfohl/Cirq/tree/main/cirq-google/"
    click IP "https://github.com/daxfohl/Cirq/tree/main/cirq-ionq/"
    click PP "https://github.com/daxfohl/Cirq/tree/main/cirq-pasqal/"
    click RP "https://github.com/daxfohl/Cirq/tree/main/cirq-rigetti/"
    click AP "https://github.com/daxfohl/Cirq/tree/main/cirq-aqt/"
    click CV "https://github.com/daxfohl/Cirq/tree/main/cirq-web/cirq_web/circuits/"
    click BS "https://github.com/daxfohl/Cirq/tree/main/cirq-web/cirq_web/bloch_sphere/"

    %% Styles
    classDef core fill:#3498db,stroke:#2980b9,color:white
    classDef hardware fill:#2ecc71,stroke:#27ae60,color:white
    classDef viz fill:#e67e22,stroke:#d35400,color:white
    
    %% Legend
    subgraph Legend
        L1["Core Components"]:::core
        L2["Hardware Interfaces"]:::hardware
        L3["Visualization"]:::viz
    end
```
