qalgora-Q Docs Hub量子文档 ✦ Ask AI✦ 问问文档

Multi-GPU Workflows

○ Planned · Not yet implemented
The capabilities described on this page are planned and not yet implemented or released. They explain future design directions and should not be interpreted as delivered features.
Planned backend — not in the reference build
The multi-GPU (mgpu) and multi-QPU (mqpu) backends are planned; the CPU-only reference build does not include them. This page documents the intended interface.

Scale beyond a single device by pooling GPU memory (mgpu) or running many QPUs in parallel (mqpu).

From CPU to GPU

All code on this page is planned (规划中); the CPU reference build ships none of these backends, so every snippet is commented out as an intended-interface illustration.

# Planned — not in the CPU reference build:
# import qalgora
# qalgora.set_target("gpu")                 # single-GPU statevector

Pooling memory across GPUs (mgpu)

One large statevector would be distributed across the memory of multiple GPUs, letting you reach more qubits than fit on a single card.

# Planned (mgpu) — not in the CPU reference build:
# qalgora.set_target("gpu", option="mgpu")  # one big state, many GPUs
# counts = qalgora.sample(large_kernel)

Parallel virtual QPUs (mqpu)

The mqpu platform would expose each GPU as an independent virtual QPU — here a "virtual QPU" is a simulator worker, not a physical QPU. Work would be sharded across them.

# Planned (mqpu) — not in the CPU reference build:
# qalgora.set_target("gpu", option="mqpu")  # independent virtual QPU per GPU
# energy = qalgora.observe(ansatz, hamiltonian, theta).expectation()

Batching Hamiltonian terms

A large Hamiltonian has many Pauli terms. Under the planned mqpu backend, observe would split the terms across virtual QPUs and sum the partial expectation values — a long chemistry Hamiltonian could be evaluated with less wall-clock time when enough independent devices are available; the speedup is workload- and hardware-dependent.

# Planned — 0..N qubit Hamiltonian with hundreds of terms run across all virtual QPUs:
# energy = qalgora.observe(ansatz, big_hamiltonian, params).expectation()

Circuit batching

Independent circuits (a parameter sweep, a batch of shots, gradient evaluations) would be dispatched asynchronously, one per virtual QPU:

# Planned — one async circuit per virtual QPU:
# futures = [qalgora.observe_async(ansatz, hamiltonian, t, qpu_id=i % n_qpus)
#            for i, t in enumerate(angles)]
# energies = [f.get().expectation() for f in futures]
Choosing a mode (planned · 规划中)
When these backends ship: use mgpu when one circuit is too big for a single GPU; use mqpu when you have many independent circuits or Hamiltonian terms to evaluate at once. They are designed to compose — a multi-node cluster would run mqpu with each virtual QPU itself an mgpu pool.

多 GPU 工作流

○ 规划中
本页所述能力属于规划功能,当前尚未发布或尚未实现。相关内容仅用于说明未来设计方向,不应理解为已交付能力。
规划中的后端 参考实现尚未实现
多 GPU(mgpu)与多 QPU(mqpu)后端均属规划中,CPU-only 的参考实现并未包含。本页仅用于说明预期接口。

通过显存池化(mgpu)或多 QPU 并行(mqpu)突破单卡限制。

从 CPU 切换到 GPU

本页所有代码均属规划中(规划中);CPU 参考实现并未包含这些后端,因此每段代码都以注释形式给出,仅用于说明预期接口。

# 规划中——CPU 参考实现暂未包含:
# import qalgora
# qalgora.set_target("gpu")                 # 单 GPU 态矢量

跨 GPU 显存池化 (mgpu)

将一个大型态矢量分布在多块 GPU 的显存中,使可模拟的量子比特数超出单卡上限。

# 规划中 (mgpu)——CPU 参考实现暂未包含:
# qalgora.set_target("gpu", option="mgpu")  # 一个大态矢量,跨多块 GPU
# counts = qalgora.sample(large_kernel)

并行虚拟 QPU (mqpu)

mqpu 平台会将每块 GPU 作为独立的虚拟 QPU 对外暴露,工作负载分片到各虚拟 QPU 上。这里的“虚拟 QPU”指模拟器工作单元,而非物理 QPU。

# 规划中 (mqpu)——CPU 参考实现暂未包含:
# qalgora.set_target("gpu", option="mqpu")  # 每块 GPU 一个独立虚拟 QPU
# energy = qalgora.observe(ansatz, hamiltonian, theta).expectation()

哈密顿量项批处理

大型哈密顿量包含大量 Pauli 项。在规划中的 mqpu 后端下,observe 会将这些项分片到各虚拟 QPU 并汇总部分期望值——当有足够多独立设备时,可降低含大量项的化学哈密顿量的墙钟时间;加速比取决于工作负载与硬件。

# 规划中——含数百项的 0..N 比特哈密顿量,各项跨所有虚拟 QPU 运行:
# energy = qalgora.observe(ansatz, big_hamiltonian, params).expectation()

电路批处理

独立电路(参数扫描、一批采样、梯度求值)会异步分发,每个虚拟 QPU 承接一个:

# 规划中——每个虚拟 QPU 承接一个异步电路:
# futures = [qalgora.observe_async(ansatz, hamiltonian, t, qpu_id=i % n_qpus)
#            for i, t in enumerate(angles)]
# energies = [f.get().expectation() for f in futures]
如何选择模式(规划中)
这些后端发布后:当单个电路超出单卡显存时选 mgpu;需要同时求值多个独立电路或哈密顿量项时选 mqpu。两者设计为可组合使用:多节点集群会在 mqpu 模式下运行,每个虚拟 QPU 本身即为一个 mgpu 显存池。