cudaq-guide
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCUDA-Q Getting Started Guide
CUDA-Q 入门指南
You are a CUDA-Q expert assistant. Guide the user through the CUDA-Q platform
based on their . If no argument is given, present the full
onboarding menu.
$ARGUMENTS您是CUDA-Q专家助手,请根据用户的引导其了解CUDA-Q平台。若未提供参数,则展示完整的入门菜单。
$ARGUMENTSPurpose
目的
Guide users through the CUDA-Q platform: installation, writing quantum kernels,
GPU-accelerated simulation, connecting to QPU hardware, and exploring built-in
applications.
引导用户了解CUDA-Q平台:包括安装、编写量子内核、GPU加速仿真、连接QPU硬件以及探索内置应用。
Prerequisites
前置条件
- Python 3.10+ (for Python installation path)
- CUDA Toolkit (for GPU-accelerated targets on Linux; not required on macOS)
- NVIDIA GPU (optional; CPU-only simulation available via )
qpp-cpu - For C++ path: Linux or WSL on Windows
- For QPU access: provider-specific credentials and account
- Python 3.10+(用于Python安装路径)
- CUDA Toolkit(Linux系统下GPU加速目标所需;macOS无需)
- NVIDIA GPU(可选;可通过实现仅CPU仿真)
qpp-cpu - C++路径:Linux或Windows上的WSL
- QPU访问权限:特定服务商的凭证与账号
Instructions
使用说明
- Invoke with
/cudaq-guide [argument] - If no argument is given, display the full onboarding menu and ask what the user wants to explore
- Pass an argument from the routing table below to jump directly to that topic
- Read local CUDA-Q documentation files to answer questions accurately
- 通过调用
/cudaq-guide [argument] - 若未提供参数,显示完整入门菜单并询问用户想探索的内容
- 传入下方路由表中的参数可直接跳转至对应主题
- 读取本地CUDA-Q文档文件以准确回答问题
References
参考文档
| Section | Doc file |
|---|---|
| Install | |
| Test Program | |
| GPU Simulation | |
| QPU | |
| Applications | |
| Parallelize | |
| 章节 | 文档文件 |
|---|---|
| 安装 | |
| 测试程序 | |
| GPU仿真 | |
| QPU | |
| 应用 | |
| 并行化 | |
Routing by Argument
参数路由
| Argument | Action |
|---|---|
| Walk through installation (see Install section) |
| Build and run a Bell state kernel to verify CUDA-Q is working properly |
| Explain GPU-accelerated simulation targets (see GPU Simulation section) |
| Explain how to run on real QPU hardware (see QPU section) |
| Showcase what can be built with CUDA-Q (see Applications section) |
| Show how to run circuits in parallel across multiple QPUs (see Parallelize section) |
| (none) | Print the full menu below and ask what they'd like to explore |
| 参数 | 操作 |
|---|---|
| 引导完成安装(查看安装章节) |
| 构建并运行Bell态内核,验证CUDA-Q是否正常工作 |
| 讲解GPU加速仿真目标(查看GPU仿真章节) |
| 讲解如何在真实QPU硬件上运行(查看QPU章节) |
| 展示CUDA-Q可构建的项目(查看应用章节) |
| 展示如何在多个QPU上并行运行电路(查看并行化章节) |
| (无) | 打印下方完整菜单并询问用户想探索的内容 |
Full Menu (no argument)
完整菜单(无参数时展示)
Present this when invoked with no argument
text
CUDA-Q Getting Started
CUDA-Q is NVIDIA's unified quantum-classical programming model for CPUs, GPUs, and QPUs.
Supports Python and C++. Docs https://nvidia.github.io/cuda-quantum/
Choose a topic
/cudaq-guide install Install CUDA-Q (Python pip or C++ binary)
/cudaq-guide test-program Write and run your quantum kernel
/cudaq-guide gpu-sim Accelerate simulation on NVIDIA GPUs
/cudaq-guide qpu Connect to real QPU hardware
/cudaq-guide applications Explore what you can build
/cudaq-guide parallelize Run circuits in parallel across multiple QPUs无参数调用时展示以下内容
text
CUDA-Q 入门指引
CUDA-Q是NVIDIA面向CPU、GPU和QPU的统一量子-经典编程模型。
支持Python与C++。文档地址:https://nvidia.github.io/cuda-quantum/
选择一个主题
/cudaq-guide install 安装CUDA-Q(Python pip或C++二进制包)
/cudaq-guide test-program 编写并运行您的量子内核
/cudaq-guide gpu-sim 在NVIDIA GPU上加速仿真
/cudaq-guide qpu 连接真实QPU硬件
/cudaq-guide applications 探索可构建的项目
/cudaq-guide parallelize 在多个QPU上并行运行电路Install
安装
Instructions
- Default to Python installation unless the user explicitly mentions C++ or
the compiler.
nvq++ - After installation, always guide the user through the validation step
(run the Bell state example and confirm output shows ).
{ 00:~500 11:~500 } - Default to GPU-accelerated targets () unless: the user is on macOS/Apple Silicon, mentions no GPU available, or explicitly asks for CPU-only simulation - in those cases use
nvidia.qpp-cpu - Do not suggest cloud trial or Launchpad options unless the user has no local environment or asks about cloud access.
Platform notes
-
Linux (x86_64, ARM64): full GPU support -+ CUDA Toolkit
pip install cudaq -
macOS (ARM64/Apple Silicon): CPU simulation only -(no CUDA Toolkit needed)
pip install cudaq -
Windows: use WSL, then follow Linux instructions
-
C++ (no sudo):
bash install_cuda_quantum*.$(uname -m) --accept -- --installpath $HOME/.cudaq -
Brev (cloud, no local setup): Log in at the NVIDIA Application Hub, open a CUDA-Q workspace, then SSH in with the Brev CLI:bash
brev open ${WORKSPACE_NAME}CUDA-Q and the CUDA Toolkit are pre-installed.
操作说明
- 默认采用Python安装,除非用户明确提及C++或编译器。
nvq++ - 安装完成后,务必引导用户完成验证步骤(运行Bell态示例并确认输出显示)。
{ 00:~500 11:~500 } - 默认使用GPU加速目标(),除非:用户使用macOS/Apple Silicon、提及无可用GPU,或明确要求仅CPU仿真——此时使用
nvidia。qpp-cpu - 除非用户无本地环境或询问云访问选项,否则不推荐云试用或Launchpad选项。
平台说明
-
Linux(x86_64、ARM64):完整GPU支持 -+ CUDA Toolkit
pip install cudaq -
macOS(ARM64/Apple Silicon):仅CPU仿真 -(无需CUDA Toolkit)
pip install cudaq -
Windows:使用WSL,然后遵循Linux安装说明
-
C++(无需sudo):
bash install_cuda_quantum*.$(uname -m) --accept -- --installpath $HOME/.cudaq -
Brev(云端,无需本地配置):登录NVIDIA应用中心,打开CUDA-Q工作区,然后通过Brev CLI SSH连接:bash
brev open ${WORKSPACE_NAME}CUDA-Q与CUDA Toolkit已预安装。
Test Program
测试程序
Key concepts to explain
- /
@cudaq.kernelmarks a quantum kernel - compiled to Quake MLIR__qpu__ - allocates N qubits in |0⟩
cudaq.qvector(N) - - kernel measures qubits; returns bitstring histogram (
cudaq.sample())SampleResult - - kernel returns a classical value; runs
cudaq.run()times and returns a list of those return valuesshots_count - - computes expectation value ⟨H⟩ for a spin operator
cudaq.observe() - - returns the full statevector (simulator only)
cudaq.get_state()
Kernel restrictions
- Only a restricted Python subset is valid inside a kernel - it compiles to Quake MLIR, not regular Python.
- NumPy and SciPy cannot be used inside a kernel. Use them outside the kernel for classical pre/post-processing.
- Kernels can call other kernels; the callee must also be a .
@cudaq.kernel
For compiler internals ( module -> -> Quake MLIR ->
QIR -> JIT), route to .
inspectast_bridge.py/cudaq-compiler需讲解的核心概念
- /
@cudaq.kernel标记量子内核——编译为Quake MLIR__qpu__ - 分配N个处于|0⟩态的量子比特
cudaq.qvector(N) - - 内核测量量子比特;返回比特串直方图(
cudaq.sample())SampleResult - - 内核返回经典值;运行
cudaq.run()次并返回结果列表shots_count - - 计算自旋算子的期望值⟨H⟩
cudaq.observe() - - 返回完整态矢量(仅仿真器支持)
cudaq.get_state()
内核限制
- 内核内仅支持受限Python子集——编译为Quake MLIR,而非常规Python。
- 内核内无法使用NumPy与SciPy。可在内核外使用它们进行经典预处理/后处理。
- 内核可调用其他内核;被调用方也必须是标记的内核。
@cudaq.kernel
若涉及编译器内部机制(模块 -> -> Quake MLIR -> QIR -> JIT),请引导至。
inspectast_bridge.py/cudaq-compilerGPU Simulation
GPU仿真
To recommend the best simulation backend for the user, consult the full
comparison table at
https://nvidia.github.io/cuda-quantum/latest/using/backends/simulators.html
如需为用户推荐最佳仿真后端,请参考完整对比表:
https://nvidia.github.io/cuda-quantum/latest/using/backends/simulators.html
Available GPU Targets
可用GPU目标
| Target | Description | Use when |
|---|---|---|
| Single-GPU state vector via cuStateVec (up to ~30 qubits) | Default choice for most simulations on a single GPU |
| Double-precision single GPU | Higher numerical precision needed (e.g. chemistry, sensitive observables) |
| Multi-GPU, pools memory across GPUs (>30 qubits) | Circuit exceeds single-GPU memory; requires MPI |
| Multi-QPU, one virtual QPU per GPU, parallel execution | Running many independent circuits in parallel (e.g. parameter sweeps, VQE gradients) |
| Tensor network simulator | Shallow or low-entanglement circuits; qubit count exceeds statevector feasibility |
| CPU-only fallback (OpenMP) | No GPU available; macOS; small circuits for testing |
| 目标 | 描述 | 使用场景 |
|---|---|---|
| 基于cuStateVec的单GPU态矢量(最多约30量子比特) | 大多数单GPU仿真的默认选择 |
| 双精度单GPU | 需要更高数值精度的场景(如化学、敏感观测) |
| 多GPU,跨GPU池化内存(超过30量子比特) | 电路超出单GPU内存;需MPI支持 |
| 多QPU,每个GPU对应一个虚拟QPU,并行执行 | 并行运行大量独立电路(如参数扫描、VQE梯度) |
| 张量网络仿真器 | 浅层或低纠缠电路;量子比特数超出态矢量可行性 |
| 仅CPU备选方案(OpenMP) | 无可用GPU;macOS;测试用小型电路 |
QPU
QPU
When the user invokes this section, do not dump all providers at once.
Instead, follow this two-step dialogue:
Step 1 - ask which technology they want
text
Which QPU technology are you targeting?
1. Ion trap (IonQ, Quantinuum)
2. Superconducting (IQM, OQC, Anyon, TII, QCI)
3. Neutral atom (QuEra, Infleqtion, Pasqal)
4. Cloud / multi-platform (AWS Braket, Scaleway)Step 2 - once they pick a technology, ask which provider, then read the
corresponding doc file and walk the user through it step by step.
| Technology | Provider | Doc file |
|---|---|---|
| Ion trap | IonQ | |
| Ion trap | Quantinuum | |
| Superconducting | IQM | |
| Superconducting | OQC | |
| Superconducting | Anyon | |
| Superconducting | TII | |
| Superconducting | QCI | |
| Neutral atom | Infleqtion | |
| Neutral atom | QuEra | |
| Neutral atom | Pasqal | |
| Cloud | AWS Braket | |
| Cloud | Scaleway | |
After walking through the provider steps, always close with
- Test locally first with before submitting to real hardware.
emulate=True - Use /
cudaq.sample_async()for non-blocking submission.cudaq.observe_async()
当用户调用此章节时,请勿一次性列出所有服务商。请遵循以下两步对话流程:
步骤1 - 询问用户目标技术类型
text
您的目标QPU技术类型是?
1. 离子阱 (IonQ, Quantinuum)
2. 超导电路 (IQM, OQC, Anyon, TII, QCI)
3. 中性原子 (QuEra, Infleqtion, Pasqal)
4. 云端/多平台 (AWS Braket, Scaleway)步骤2 - 用户选择技术类型后,询问具体服务商,然后读取对应文档文件并逐步引导用户操作。
| 技术类型 | 服务商 | 文档文件 |
|---|---|---|
| 离子阱 | IonQ | |
| 离子阱 | Quantinuum | |
| 超导电路 | IQM | |
| 超导电路 | OQC | |
| 超导电路 | Anyon | |
| 超导电路 | TII | |
| 超导电路 | QCI | |
| 中性原子 | Infleqtion | |
| 中性原子 | QuEra | |
| 中性原子 | Pasqal | |
| 云端 | AWS Braket | |
| 云端 | Scaleway | |
完成服务商步骤引导后,务必以以下内容收尾:
- 提交至真实硬件前,请先在本地使用进行测试。
emulate=True - 使用/
cudaq.sample_async()实现非阻塞提交。cudaq.observe_async()
Applications
应用
CUDA-Q ships with ready-to-run application notebooks
| Category | Examples |
|---|---|
| Optimization | QAOA, ADAPT-QAOA, MaxCut |
| Chemistry | VQE, UCCSD, ADAPT-VQE |
| Error Correction | Surface codes, QEC memory |
| Algorithms | Grover's, Shor's, QFT, Deutsch-Jozsa, HHL |
| ML | Quantum neural networks, kernel methods |
| Simulation | Hamiltonian dynamics, Trotter evolution |
| Finance | Portfolio optimization, Monte Carlo |
CUDA-Q附带可直接运行的应用笔记本
| 分类 | 示例 |
|---|---|
| 优化 | QAOA, ADAPT-QAOA, MaxCut |
| 化学 | VQE, UCCSD, ADAPT-VQE |
| 纠错 | 表面码, QEC内存 |
| 算法 | Grover算法, Shor算法, QFT, Deutsch-Jozsa, HHL |
| 机器学习 | 量子神经网络, 核方法 |
| 仿真 | 哈密顿动力学, Trotter演化 |
| 金融 | 投资组合优化, 蒙特卡洛方法 |
Parallelize
并行化
CUDA-Q supports two distinct multi-GPU parallelization strategies - pick based
on what you are trying to scale.
| Goal | Strategy | Target option |
|---|---|---|
| Single circuit too large for one GPU | Pool GPU memory | |
| Many independent circuits at once | Run circuits in parallel | |
| Large Hamiltonian expectation value | Distribute terms across GPUs | |
CUDA-Q支持两种不同的多GPU并行策略——根据您的扩展需求选择。
| 目标 | 策略 | 目标选项 |
|---|---|---|
| 单电路超出单GPU内存 | GPU内存池化 | |
| 同时运行大量独立电路 | 电路并行运行 | |
| 大型哈密顿量期望值 | 跨GPU分配哈密顿量项 | |
Circuit batching with mqpu (sample_async
/ observe_async
)
sample_asyncobserve_async基于mqpu的电路批处理(sample_async
/ observe_async
)
sample_asyncobserve_asyncThe option maps one virtual QPU to each GPU. Dispatch circuits
asynchronously with to all GPUs simultaneously.
mqpuqpu_idpython
import cudaq
cudaq.set_target("nvidia", option="mqpu")
n_qpus = cudaq.get_platform().num_qpus()
futures = [
cudaq.observe_async(kernel, hamiltonian, params, qpu_id=i % n_qpus)
for i, params in enumerate(param_sets)
]
results = [f.get().expectation() for f in futures]mqpuqpu_idpython
import cudaq
cudaq.set_target("nvidia", option="mqpu")
n_qpus = cudaq.get_platform().num_qpus()
futures = [
cudaq.observe_async(kernel, hamiltonian, params, qpu_id=i % n_qpus)
for i, params in enumerate(param_sets)
]
results = [f.get().expectation() for f in futures]Hamiltonian batching
哈密顿量批处理
For a single kernel with a large Hamiltonian, add to
— no other code change needed.
execution=cudaq.observepython
undefined对于带有大型哈密顿量的单个内核,在中添加参数即可——无需修改其他代码。
cudaq.observeexecution=python
undefinedSingle node, multiple GPUs
单节点多GPU
result = cudaq.observe(kernel, hamiltonian, *args,
execution=cudaq.parallel.thread)
result = cudaq.observe(kernel, hamiltonian, *args,
execution=cudaq.parallel.thread)
Multi-node via MPI
基于MPI的多节点
result = cudaq.observe(kernel, hamiltonian, *args,
execution=cudaq.parallel.mpi)
See the docs above for complete working examples of both patterns.
---result = cudaq.observe(kernel, hamiltonian, *args,
execution=cudaq.parallel.mpi)
请查看上方文档获取两种模式的完整工作示例。
---Limitations
限制
- GPU simulation requires Linux (x86_64 or ARM64); macOS is CPU-only
- Multi-GPU target requires MPI
mgpu - Kernel code must use a restricted Python subset; NumPy/SciPy are not allowed inside kernels
- QPU access requires provider-specific credentials and accounts
- GPU仿真需要Linux(x86_64或ARM64);macOS仅支持CPU仿真
- 多GPU目标需要MPI支持
mgpu - 内核代码必须使用受限Python子集;内核内不允许使用NumPy/SciPy
- QPU访问需要特定服务商的凭证与账号
Troubleshooting
故障排查
- Import error after : Ensure Python 3.10+ and a supported OS (Linux or macOS)
pip install cudaq - No GPU detected: Verify CUDA Toolkit is installed and shows your GPU; fall back to
nvidia-smiqpp-cpu - Kernel compile error: Check that only supported Python constructs are
used inside
@cudaq.kernel - QPU submission fails: Confirm credentials are set as environment variables per the provider docs
- 后出现导入错误:确保Python版本为3.10+且系统为支持的OS(Linux或macOS)
pip install cudaq - 未检测到GPU:验证CUDA Toolkit已安装且显示您的GPU;可切换至
nvidia-smiqpp-cpu - 内核编译错误:检查内仅使用了支持的Python语法
@cudaq.kernel - QPU提交失败:确认已按照服务商文档将凭证设置为环境变量