# dan-lb/quantum_kernel_discovery_ad_hep architecture

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

- Interactive diagram: https://gitdiagram.com/dan-lb/quantum_kernel_discovery_ad_hep
- Repository: https://github.com/dan-lb/quantum_kernel_discovery_ad_hep

## Overview

##### Project Type & Purpose
- This project is a specialized scientific/quantum computing pipeline for anomaly detection using quantum kernel discovery techniques.
- Its purpose is to provide a means for comparing quantum-based kernels against classical methods (e.g., OC-SVM), and includes capabilities for kernel evaluation, optimization, and visualization.
- The repository indicates multiple operational modes (“CUSTOM”, “FIXED”, “CLASSICAL”) to test and compare different kernel configurations.

##### High-Level Components
- Entry/Execution Controller:
- Main entry point: The main.py file in the project’s root orchestrates the pipeline.
- Additional scripts (create_plot.py, prepare_plot_scores.py, plot.py) are responsible for post-run visualization and reporting.
- Core Quantum Kernel Module (darqk/core):
- Contains abstractions for quantum kernels: ansatz definitions, kernel creation logic (kernel_factory.py), kernel type, and operations.
- Kernel Core Implementation:
- Found in darqk/core_implementation (e.g., pennylane_kernel.py) – this module provides the actual implementation using specific quantum frameworks (PennyLane).
- Evaluator Module (darqk/evaluator):
- Multiple evaluators exist to measure kernel performance such as centered_kernel_alignment, covering number, Haar evaluation, spectral bias and others.
- A significant portion is dedicated to latent_ad_qml which includes custom algorithms like kernel machines (qsvm, one_class_svm) and autoencoder scripts.
- Optimizer Module (darqk/optimizer):
- Provides different strategies for enhancing the kernel’s performance. These include Bayesian optimization, greedy methods, metaheuristic, and reinforcement learning optimizers.
- Contains environment setups for “tight” and “wide” kernel environments.
- Tests:
- darqk/tests helps ensure that the kernel implementations and evaluations function as expected.
- Environment & Dependency Management:
- Files like environment.yml and requirements.txt indicate how external libraries (e.g., quantum computing libraries, PennyLane, etc.) should be integrated.

##### Detailed Architectural Relationships & Data Flow
- The main.py script serves as the central orchestrator. It parses command line modes and parameters (e.g., latent_dim, n_op, final_train/test) and directs the workflow.
- Starting from main.py, data acquired either from the provided external dataset or prepared locally is fed into the pipeline.
- Kernel Discovery and Construction:
- darqk/core modules abstract how kernels are built.
- The kernel_factory and operational components decide the kernel configuration and instantiate either a quantum or classical kernel.
- The core_implementation (pennylane_kernel) ties these abstractions to a concrete quantum framework.
- Evaluation Phase:
- The evaluator modules (grouped under darqk/evaluator) analyze kernel performance using numerous metrics.
- Specific latent_ad_qml evaluators incorporate both classical algorithms and quantum algorithms (like kmeans, kmedians, qsvm) enabling rigorous performance benchmarks.
- Optimization Phase:
- Optimizer modules (darqk/optimizer) interact with the kernel module to refine parameters based on different optimization strategies.
- These components may exchange data (performance metrics, error signals) back to the kernel updater.
- Visualization & Reporting:
- After evaluation/optimization, scripts for preparing plots (prepare_plot_scores.py) and for final visualizations (create_plot.py) are invoked to generate result graphs.
- Dependencies include external plotting libraries, and the visual output serves as both model comparison and debugging information.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Data Source
    D["Dataset"]:::external

    %% Entry/Execution Controller
    A["Main Controller (main.py)"]:::control

    %% Kernel Construction Group
    subgraph "Kernel Construction"
        B["Core Quantum Kernel Module (darqk/core)"]:::core
    end

    %% Kernel Core Implementation
    E["Kernel Core Implementation (pennylane_kernel.py)"]:::core

    %% Evaluator Suite
    subgraph "Evaluator Suite"
        F["Evaluator Module (darqk/evaluator)"]:::evaluator
    end

    %% Optimizer Suite
    subgraph "Optimizer Suite"
        G["Optimizer Module (darqk/optimizer)"]:::optimizer
    end

    %% Visualization & Reporting
    subgraph "Visualization"
        H["create_plot.py"]:::viz
        I["prepare_plot_scores.py"]:::viz
        J["plot.py"]:::viz
    end

    %% Tests
    K["Tests (darqk/tests)"]:::tests

    %% Environment & Dependency Management
    L["environment.yml"]:::env
    M["requirements.txt"]:::env

    %% Data Flow Connections
    D -->|"providesData"| A
    A -->|"initiates"| B
    B -->|"buildsKernel"| E
    E -->|"suppliesKernel"| F
    E -->|"feedsKernel"| G
    F -->|"metricsTo"| G
    G -- "feedbackLoop" --> F
    F -->|"outputsResults"| H
    F -->|"outputsResults"| I
    G -->|"outputsResults"| J
    A -->|"executesTests"| K

    %% Environment dependencies applied across modules
    L --> A
    M --> A
    L --> B
    M --> B
    L --> E
    M --> E
    L --> F
    M --> F
    L --> G
    M --> G

    %% Styles and Colors
    classDef control fill:#f9c,stroke:#333,stroke-width:2px;
    classDef core fill:#9f9,stroke:#333,stroke-width:2px;
    classDef evaluator fill:#ff9,stroke:#333,stroke-width:2px;
    classDef optimizer fill:#9ff,stroke:#333,stroke-width:2px;
    classDef viz fill:#fc9,stroke:#333,stroke-width:2px;
    classDef tests fill:#f99,stroke:#333,stroke-width:2px;
    classDef env fill:#ccf,stroke:#333,stroke-width:2px;
    classDef external fill:#eee,stroke:#333,stroke-width:2px;

    %% Click Events for Components
    click A "https://github.com/dan-lb/quantum_kernel_discovery_ad_hep/blob/main/main/main.py"
    click B "https://github.com/dan-lb/quantum_kernel_discovery_ad_hep/tree/main/main/darqk/core"
    click E "https://github.com/dan-lb/quantum_kernel_discovery_ad_hep/blob/main/main/darqk/core_implementation/pennylane_kernel.py"
    click F "https://github.com/dan-lb/quantum_kernel_discovery_ad_hep/tree/main/main/darqk/evaluator"
    click G "https://github.com/dan-lb/quantum_kernel_discovery_ad_hep/tree/main/main/darqk/optimizer"
    click H "https://github.com/dan-lb/quantum_kernel_discovery_ad_hep/blob/main/main/create_plot.py"
    click I "https://github.com/dan-lb/quantum_kernel_discovery_ad_hep/blob/main/main/prepare_plot_scores.py"
    click J "https://github.com/dan-lb/quantum_kernel_discovery_ad_hep/blob/main/main/plot.py"
    click K "https://github.com/dan-lb/quantum_kernel_discovery_ad_hep/tree/main/main/darqk/tests"
    click L "https://github.com/dan-lb/quantum_kernel_discovery_ad_hep/blob/main/environment.yml"
    click M "https://github.com/dan-lb/quantum_kernel_discovery_ad_hep/blob/main/requirements.txt"
```
