This repository contains the main codebase for the AcceleratedQC project, including the catalyst
component, quantum kernels, and a submodule reference to the official LLVM project.
catalyst/
— Main project code and scriptsKernels/
— Quantum computing kernels (Hadamard, etc.)llvm-project/
— LLVM project (added as a submodule)
The project includes a functional Hadamard kernel integration that enables FPGA-accelerated quantum computing through PennyLane. This integration provides:
- Real Quantum Transformations: Produces correct quantum superposition states
- FPGA Acceleration: Uses AMD/Xilinx AI Engine for high-performance operations
- CPU Fallback: Automatic fallback when FPGA hardware unavailable
- PennyLane Integration: Integration with quantum computing framework
- Multi-qubit Support: Handles 1, 2, 3+ qubit systems
# Single Qubit Hadamard
Input: |0⟩ = [1, 0]
Output: |+⟩ = [0.70710678+0j, 0.70710678+0j]
# Two Qubit Hadamard
Input: |00⟩ = [1, 0, 0, 0]
Output: |++⟩ = [0.5+0j, 0.5+0j, 0.5+0j, 0.5+0j]
Clone this repository and initialize submodules:
git clone --recurse-submodules https://github.com/MPSLab-ASU/AcceleratedQC.git
cd AcceleratedQC
If you already cloned without --recurse-submodules
, run:
git submodule update --init --recursive
Navigate to the catalyst
directory and install Python dependencies:
cd catalyst
pip install -r requirements.txt
If you need to build LLVM from source, follow the instructions in llvm-project/README.md
.
- Python Environment: Python 3.8+ with PennyLane
- C++ Compiler: Clang/GCC for building the custom device
- XRT (Optional): For FPGA acceleration (set
XILINX_XRT
environment variable) - Vitis (Optional): For AIE tools (set
XILINX_VITIS
environment variable)
Navigate to the custom device directory and build the integration:
cd catalyst/runtime/lib/backend/custom_device
./build.sh
This will:
- Check for XRT/Vitis availability
- Compile the custom device with kernel integration
- Create the shared library
librtd_custom_device.so
Expected Output:
Building Custom Device with Hadamard Kernel Integration...
✓ Custom device library built successfully
Run the basic test to verify the integration:
python3 circuit.py
Expected Output:
Warning: FPGA bitstream not found at libadf.xclbin
Falling back to CPU implementation
✓ Loaded C++ library: /path/to/librtd_custom_device.so
Testing CustomDevice with real Hadamard kernel...
After Hadamard on qubit 0: [0.70710678+0j, 0.70710678+0j]
Circuit result: (0.7071067811865475+0j)
Expected for 1 qubit: [0.70710678+0j, 0.70710678+0j]
Results match expected: True
Execute the comprehensive test suite:
python3 test_hadamard_output.py
Expected Output:
REAL HADAMARD KERNEL OUTPUT DEMONSTRATION
============================================================
SINGLE QUBIT HADAMARD TRANSFORMATION
Input state: |0⟩ = [1, 0]
Expected output: |+⟩ = [0.70710678, 0.70710678]
Actual output: [0.70710678+0j, 0.70710678+0j]
Matches expected: True
TWO QUBIT HADAMARD TRANSFORMATION
Input state: |00⟩ = [1, 0, 0, 0]
Expected output: |++⟩ = [0.5, 0.5, 0.5, 0.5]
Actual output: [0.5+0j, 0.5+0j, 0.5+0j, 0.5+0j]
Matches expected: True
Create your own quantum circuits using the custom device:
import pennylane as qml
from pennylane import numpy as np
# Create custom device
dev = CustomDevice(wires=2, use_fpga=True)
# Define quantum circuit
@qml.qnode(dev)
def circuit():
qml.Hadamard(wires=0)
qml.Hadamard(wires=1)
return qml.state()
# Execute circuit
result = circuit()
print(f"Quantum state: {result}")
The Hadamard integration uses a multi-layer architecture:
┌─────────────────┐
│ PennyLane │ ← Python quantum computing interface
├─────────────────┤
│ Custom Device │ ← C++ device implementation
├─────────────────┤
│ Kernel Wrapper │ ← C++/Python interface
├─────────────────┤
│ FPGA Kernel │ ← XRT-based FPGA communication
└─────────────────┘
- Python Layer (
circuit.py
): PennyLane device interface - C++ Layer (
CustomDevice.cpp
): Device implementation with FPGA/CPU switching - Kernel Layer (
HadamardKernelWrapper.cpp
): Interface to FPGA kernel - Hardware Layer (
Kernels/src/
): XRT-based FPGA communication
-
Build Failures:
# Check if LLVM is properly built cd catalyst/runtime make clean && make runtime
-
Library Not Found:
# Verify shared library exists ls -la catalyst/runtime/build/lib/librtd_custom_device.so
-
FPGA Kernel Unavailable:
- This is expected if XRT is not installed
- System will automatically fall back to CPU implementation
- Check environment variables:
echo $XILINX_XRT
-
Python Import Errors:
# Install PennyLane if not available pip install pennylane
The system provides verbose output showing:
- FPGA vs CPU mode selection
- Kernel execution status
- State vector transformations
- Error messages and fallback information
To enable FPGA acceleration:
-
Install XRT:
export XILINX_XRT=/path/to/xrt
-
Compile FPGA Bitstream:
cd Kernels # Follow FPGA compilation instructions
-
Test with FPGA:
python3 circuit.py # Will use FPGA if available
Extend the system to support additional quantum gates:
- Add New Gates: Modify
CustomDevice.cpp
to support new operations - Update Kernel: Add corresponding FPGA kernel implementations
- Test Integration: Create test cases for new functionality
- CPU Mode: Optimized C++ implementation with O(2^n) complexity
- FPGA Mode: Parallel FPGA implementation with hardware acceleration
- Memory Usage: State vector scales as O(2^n) for n qubits
- Precision: Machine precision (typically 1e-15 for double precision)
- Fork the repository
- Create a feature branch:
git checkout -b feature/new-gate
- Implement your changes
- Add tests: Create comprehensive test cases
- Submit a pull request
- Integration Details: See
catalyst/runtime/lib/backend/custom_device/README.md
- Worklog: See
catalyst/runtime/lib/backend/custom_device/worklog2.txt
- Kernel Documentation: See
Kernels/README.md