CQ Simulated Backend (CQ-SimBE)
- CQ-SimBE is an open-source reference implementation of the CQ API, enabling hybrid quantum-classical HPC integration by offloading quantum kernels to a simulated quantum device.
- It employs a two-threaded model using POSIX threads and a shared-memory queue to manage synchronous and asynchronous execution of quantum kernels from C and Fortran codes.
- The backend supports experimental analogue quantum computing extensions and strict API conformance, providing fine-grained control over resource management and error handling.
The CQ Simulated Backend (CQ-SimBE) is an open-source reference implementation of the CQ API, written in C99 and designed for hybrid quantum-classical high-performance computing (HPC) integration. It facilitates runtime offloading of quantum kernels from classical code (in C or Fortran) to a simulated quantum device, leveraging the QuEST statevector simulator for quantum state evolution. CQ-SimBE also serves as a testbed for experimental features such as analogue quantum computing, and enables fine-grained control over classical and quantum resource management within a unified programming interface (Brown et al., 14 Aug 2025).
1. Architectural Design and Execution Model
CQ-SimBE is architected atop QuEST and employs a two-threaded model utilizing POSIX threads. The classical host thread is responsible for core program execution and initiates quantum offload operations. The device thread acts as a simulated quantum accelerator, maintaining a FIFO queue of control operations that are dispatched by the host. Quantum kernels—functions defined in C and registered with the backend—are offloaded via control messages (e.g., integer keys or function pointers) and executed by the device thread in an asynchronous or synchronous manner.
Kernel invocation is managed using a shared-memory queue in the current implementation, with explicit support for message-passing semantics to facilitate future integration with distributed models (e.g., MPI). Resource management is realized through opaque types that encapsulate quantum data (such as qubit
, qureg
, qkern
, and cstate
), and the device thread exposes functions for allocation, initialization, measurement (both synchronized and unsynchronized), and deallocation—all prescribed by the CQ API specification. Kernel registration maps C function pointers to device-side operations, enabling dynamic invocation and runtime task scheduling.
2. CQ API Specification Conformance
CQ-SimBE conforms strictly to the CQ specification, providing a full function suite for quantum resource allocation and kernel execution. API endpoints include:
alloc_qubit
,alloc_qureg
: Allocate quantum resources and register quantum data.free_qubit
,free_qureg
: Release resources.- State-setting operations:
set_qubit
,set_qureg
, and other device-local functions for quantum initialisation. - Measurement: Synchronized
measure
and unsynchronizeddmeasure
operations. - Modular gate set: Functions such as
hadamard()
andcphase()
adhere to OpenQASM conventions.
Kernel execution is provided in both synchronous (s_qrun
) and asynchronous (a_qrun
) modes. Asynchronous execution returns a handle (exec
) for subsequent synchronization (sync_qrun
, wait_qrun
, halt_qrun
), granting the developer fine control over when quantum results are returned to the classical host. This supports advanced workflows in hybrid quantum-classical environments and enables precise data movement between host and device code.
3. Offloading and Hybrid Programming in C and Fortran
To facilitate integration with existing HPC codes, CQ-SimBE supports both C and Fortran interfaces. Kernels are written and registered in C, but Fortran bindings are provided for initializing, registering, and invoking kernels from Fortran code. This dual-language support is critical for incremental migration of legacy codes, allowing HPC developers to offload quantum computations—even when working in traditionally Fortran-dominated applications—to the simulated backend.
Example application workflows use modular kernel decomposition. For instance, a quantum Fourier transform (QFT) circuit is divided into reusable subroutines; the main kernel (zero_init_full_qft
) is registered and offloaded to the device in a manner compatible with both C and Fortran drivers. Fine-grained error handling is available: every API operation returns an integer status, enabling robust failover and debugging.
4. Analogue Quantum Computing Extensions and Experimental Features
CQ-SimBE supports experimental extensions for analogue quantum computing, notably via the cq-analog
module. This subsystem enables Hamiltonian simulation and annealing protocols. Analogue mode is enabled by invoking enable_analog_mode(mode)
(e.g., ISING or XY), establishing context for subsequent analogue operations. The API then supports:
- Channel control:
get_channel
,retarget_channel
to select and assign channels for pulse operations. - Pulse definition:
init_pulse
andfree_pulse
manage the lifecycle of pulse objects, with waveform parameters settable prior to playback. - Pulse playback:
play(channel, pulse)
initiates the analogue operation. - Advanced timing and data collection:
capture
for measurement after pulse execution,delay
for scheduling, andbarrier
for channel synchronization.
A typical analogue workflow sequence involves channel allocation, pulse definition (including phase, detuning, and duration), pulse playback, and data capture over multiple shots (for statistical analysis and calibration):
1 2 3 4 5 6 7 |
enable_analog_mode(ISING); get_channel(&ch, LOCAL, qr, target_qubit); pulse myPulse; init_pulse(&myPulse, 50.0); // Configure waveform parameters play(&ch, &myPulse); int result_array[SHOT_COUNT]; capture(&ch, &myPulse, result_array, SHOT_COUNT); |
This analogue interface allows developers to experiment with protocols relevant to near-term quantum hardware, including Hamiltonian simulation and annealing, and supports hardware-specific features evolving in quantum accelerator research.
5. Demonstrating Use Cases and Error Handling
CQ-SimBE is intended as both a demonstration and utility backend. Example circuits (such as QFT and other quantum algorithms) are decomposed into entry-point kernels and modular routines. These are invoked by the host and executed by the device thread, with results returned for post-processing or direct output (e.g., measurement statistics). The implementation ensures that classical–quantum synchronisation occurs explicitly, as required for co-design with HPC codes that may demand strict control over workflow and data transfer.
All API calls return error codes, and result handling is orchestrated so that classical data movement (from quantum device to host) can be optimally controlled—a key requirement in scientific and engineering workflows in HPC settings.
6. Open Source Distribution and Community Impact
Both the CQ specification and CQ-SimBE reference implementation are distributed under the MIT license and hosted on public repositories, inviting collaboration from the quantum computing and HPC communities. This open approach enables experimentation, extension, and adaptation to emerging requirements. The implementation is explicitly positioned as a flexible testbed for future development, including parameterized kernel support, multi-backend designs, and message-passing integration (e.g., via MPI).
The Fortran interface and overall API conformance are designed to lower adoption barriers for researchers and HPC developers, especially in environments dominated by legacy codes. The framework is intended to instantiate and validate new features and foster incremental integration of quantum accelerators into traditional HPC applications.
7. Relevance and Outlook within Hybrid Quantum-HPC Programming Models
CQ-SimBE validates the practical utility of the CQ specification, showing that quantum kernels can be offloaded, executed, and synchronised within a classical/HPC-centric framework. Its experimental support for analogue quantum computation aligns with the increasing relevance of non-gate-model devices. The architecture models hybrid classical–quantum programming workflows, aligns with best practices in resource management and error handling, and provides the necessary abstraction and control for ongoing research in quantum-accelerated HPC (Brown et al., 14 Aug 2025).
A plausible implication is that CQ-SimBE serves not only as a reference for current usage but also as a blueprint for future research and development in hybrid quantum-classical APIs and simulation backends, as quantum accelerators become more integrated into mainstream HPC workflows.