Combining Classical GPU Code with Quantum
◐ Design-level API
This page documents qalgora-Q API design, architecture, or adaptation workflows. Code examples illustrate intended usage and are not guaranteed to run in the current reference implementation.Planned backend — not in the reference build
The GPU backend is a planned capability: no public GPU package or benchmark has shipped yet. The reference build is a CPU-only NumPy simulator. The code below documents the intended interface.qalgora-Q sits alongside your GPU compute, so classical pre/post-processing and quantum kernels compose in one workflow.
GPU pre-processing, then a kernel
import qalgora
import cupy as cp
# classical feature computation on the GPU
data = cp.random.rand(1024, 1024)
features = cp.linalg.svd(data, compute_uv=False)[:8]
# feed the result straight into a quantum kernel
angles = (features / features.max() * 3.14159).get().tolist()
counts = qalgora.sample(encode_kernel, angles, shots_count=1000)Specification API — not in the open reference build yet
This example shows a qalgora-Q specification API (or a third-party library) that the open reference build does not bundle today. It documents the intended interface; to run code now, use the reference build’s supported core API.How data moves between device and host
- The example above still copies the GPU result back to the host before passing it into the quantum kernel; a zero-copy GPU-tensor interface is a planned backend capability.
samplereturns a counts distribution; if you instead useobserve, the expectation value can come back as a plain Python float or array.
One device, one program
This is the intended promise of the hybrid model — classical acceleration and quantum execution in
a single workflow, not two separate stacks. GPU classical acceleration is an optional,
planned capability; the open reference build is CPU-only.
经典 GPU 代码与量子计算的融合
◐ 设计接口
本页描述的是 qalgora-Q 的接口设计、架构设计或适配工作流。相关代码用于说明预期用法,当前参考实现不保证可以直接运行。规划中的后端 参考实现尚未实现
GPU 后端属于规划中能力,目前尚无公开的 GPU 软件包或基准。参考实现是 CPU-only 的 NumPy 模拟器。以下代码仅用于说明预期接口。qalgora-Q 与 GPU 计算相邻协作:经典的预处理、后处理与量子内核可在同一工作流中衔接。
GPU 预处理后调用量子内核
import qalgora
import cupy as cp
# classical feature computation on the GPU
data = cp.random.rand(1024, 1024)
features = cp.linalg.svd(data, compute_uv=False)[:8]
# feed the result straight into a quantum kernel
angles = (features / features.max() * 3.14159).get().tolist()
counts = qalgora.sample(encode_kernel, angles, shots_count=1000)规范接口 · 参考实现暂未包含
此示例展示的是 qalgora-Q 规范中的接口(或第三方库),开放参考实现目前尚未内置,仅用于说明预期用法;如需立即运行,请使用参考实现已支持的核心 API。数据在设备与主机间的流动
- 当前示意代码仍将 GPU 结果拷回主机后传入量子内核;零拷贝 GPU 张量接口属于规划中的后端能力。
- 采样(sample)返回计数分布;若使用 observe,期望值可返回为普通 Python 浮点数或数组。
一套设备 一份程序
这正是混合模型的预期承诺——经典加速与量子执行融于单一工作流,而非两套独立技术栈。GPU 经典加速为可选的规划中能力,开放参考实现为 CPU-only。