Quantum Graph Neural Network

Quantum Graph Neural Network (QGNN) with Variational Quantum Circuit (VQC)

Introduction

This Quantum Graph Neural Network (QGNN) combines classical neural networks and quantum circuits to process graph-based data, leveraging quantum computing for tasks like fraud detection and classification. The QGNN includes a Variational Quantum Circuit (VQC) layer, which encodes input features into quantum states, enhancing the model’s ability to capture complex relationships in data.

Architecture and Components

The QGNN consists of both classical and quantum components. The classical layers preprocess and compress the input, while the quantum layer (VQC) performs computations within a quantum circuit, with the final layer generating predictions.

Core Modules and Functionalities

QGNN (Quantum Graph Neural Network)

The QGNN class defines the neural network structure, incorporating both classical and quantum layers to enhance the model’s predictive power. Key components include fully connected layers, batch normalization, dropout, and a quantum encoding layer via the VQC.

Classical Layers:

• fc1: A fully connected layer that compresses input features to match the number of qubits in the quantum circuit.

• batch_norm1: Normalizes input data before it is passed to the quantum circuit, stabilizing training.

• dropout: Prevents overfitting by randomly deactivating a subset of neurons during training.

• fc2: The final fully connected layer that transforms quantum-encoded data for classification or regression tasks.

Quantum Layer (Variational Quantum Circuit):

• Uses a parameterized quantum circuit to encode data into quantum states. It processes input data with RX and RY gates, followed by entangling CZ gates, and generates output probabilities.

VariationalQuantumCircuit (VQC)

The VQC handles the quantum layer, processing input features through parameterized quantum gates. This layer operates on a quantum simulator, utilizing quantum entanglement and rotation gates to represent data in quantum states.

RX and RY Gates: Encode input features by rotating qubits.

CZ Gates: Entangles qubits within each layer to capture correlations.

Forward Pass: Processes input data, binding it to quantum gates and computing the probability of measuring a target quantum state.

Graph Preprocessing

The graph preprocessing module converts transaction data into a graph structure compatible with QGNNs. This step structures data for graph-based learning, where nodes represent transactions and edges represent relationships.

Node Creation: Each transaction is added as a node with features.

Edge Creation: Relationships between transactions are represented as edges, establishing a graph structure for downstream analysis.

Core Functionalities

1. Feature Compression and Classical Processing

The QGNN class begins by compressing input data, preparing it for quantum encoding.

Fully Connected Layer (fc1): Compresses input dimensions to the number of qubits, reducing feature complexity.

Batch Normalization: Normalizes the compressed features, stabilizing training by ensuring consistent data input.

Dropout: Randomly drops neurons during training to reduce overfitting, improving generalization.

2. Quantum Encoding via VQC

The VariationalQuantumCircuit processes compressed features through quantum gates, encoding data into quantum states.

Parameter Binding: Associates input values with RX and RY gate parameters for each qubit.

Layered Encoding: Adds multiple layers of RX, RY, and CZ gates to encode data, creating a complex representation of input features.

Measurement: Measures the probability of each quantum state, particularly the probability of the all-zero state, which serves as the output feature for the QGNN model.

3. Visualization of Neural Network Layers

The QGNN includes functions for visualizing network weights and activations, enabling insights into each layer’s role in the model.

Weight Visualization: Shows weights of fully connected layers, aiding in understanding model adjustments during training.

Activation Visualization: Plots activations of each layer, providing insights into how input data is transformed across layers.

4. Circuit and Measurement Visualization

The VQC supports visualizing the constructed quantum circuit and output histograms, which display the probability distribution across quantum states.

Circuit Diagram: Renders a visual representation of the quantum circuit, showing each gate’s placement and qubit connections.

Histogram Plot: Displays the distribution of measurement results, focusing on the probability of observing the all-zero state as an indicator of the model’s prediction.

Using the QGNN with VQC

Initialization and Configuration

To set up the QGNN, define the model’s parameters, including the number of qubits, layers, and input dimension. The VQC initializes with RX and RY gates for encoding, along with entangling CZ gates for each layer.

Model Configuration: Set parameters for the classical and quantum layers, defining the depth and complexity of the model.

Quantum Circuit Configuration: Specify the number of qubits and layers for the VQC, enabling customized quantum representation.

Training and Evaluation

The QGNN is designed for graph-based data, supporting forward passes and visualization to understand model performance.

Training: The forward function manages data compression, quantum encoding, and prediction generation.

Evaluation: Visualize activations and weights to monitor the learning process and analyze layer contributions.

Prediction and Inference

After training, the QGNN can process new data through its classical and quantum layers to generate predictions.

Feature Compression: Preprocesses input data, passing it through fc1 and the VQC for quantum encoding.

Quantum Encoding and Final Layer: Generates predictions by passing quantum-encoded features through the final layer, outputting a probability score.

Visualization of Model Insights

The system provides visualization for both classical and quantum layers, including weight, activation, and measurement histograms.

Layer Activations and Weights: Visualizes the transformation of input features through each neural network layer.

Quantum Circuit and Histograms: Visualizes quantum circuit operations and measurement results, enhancing interpretability of quantum-based predictions.

Example Workflow

1. Initialize Model: Set up the QGNN with specified input dimensions, number of qubits, and layers.

2. Preprocess Data: Use the preprocess_graph_data function to convert transactional data into graph form.

3. Forward Pass with Visualization: Perform a forward pass through the QGNN, enabling visualization of the quantum circuit for selected samples.

4. Model Interpretation: Visualize layer weights, activations, and quantum state probabilities for deeper insight.

The QGNN with VQC combines quantum and classical computations, allowing for advanced modeling of graph-based data, particularly for tasks requiring sophisticated data relationships.