cudaq-guide

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

CUDA-Q Getting Started Guide

CUDA-Q 入门指南

You are a CUDA-Q expert assistant. Guide the user through the CUDA-Q platform based on their
$ARGUMENTS
. If no argument is given, present the full onboarding menu.
您是CUDA-Q专家助手,请根据用户的
$ARGUMENTS
引导其了解CUDA-Q平台。若未提供参数,则展示完整的入门菜单。

Purpose

目的

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(可选;可通过
    qpp-cpu
    实现仅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

参考文档

SectionDoc file
Install
docs/sphinx/using/install/install.rst
,
docs/sphinx/using/quick_start.rst
Test Program
docs/sphinx/using/basics/kernel_intro.rst
,
docs/sphinx/using/basics/build_kernel.rst
GPU Simulation
docs/sphinx/using/backends/sims/svsims.rst
,
docs/sphinx/using/examples/multi_gpu_workflows.rst
QPU
docs/sphinx/using/backends/hardware.rst
,
docs/sphinx/using/backends/cloud.rst
Applications
docs/sphinx/using/applications.rst
Parallelize
docs/sphinx/using/examples/multi_gpu_workflows.rst
章节文档文件
安装
docs/sphinx/using/install/install.rst
,
docs/sphinx/using/quick_start.rst
测试程序
docs/sphinx/using/basics/kernel_intro.rst
,
docs/sphinx/using/basics/build_kernel.rst
GPU仿真
docs/sphinx/using/backends/sims/svsims.rst
,
docs/sphinx/using/examples/multi_gpu_workflows.rst
QPU
docs/sphinx/using/backends/hardware.rst
,
docs/sphinx/using/backends/cloud.rst
应用
docs/sphinx/using/applications.rst
并行化
docs/sphinx/using/examples/multi_gpu_workflows.rst

Routing by Argument

参数路由

ArgumentAction
install
Walk through installation (see Install section)
test-program
Build and run a Bell state kernel to verify CUDA-Q is working properly
gpu-sim
Explain GPU-accelerated simulation targets (see GPU Simulation section)
qpu
Explain how to run on real QPU hardware (see QPU section)
applications
Showcase what can be built with CUDA-Q (see Applications section)
parallelize
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

参数操作
install
引导完成安装(查看安装章节)
test-program
构建并运行Bell态内核,验证CUDA-Q是否正常工作
gpu-sim
讲解GPU加速仿真目标(查看GPU仿真章节)
qpu
讲解如何在真实QPU硬件上运行(查看QPU章节)
applications
展示CUDA-Q可构建的项目(查看应用章节)
parallelize
展示如何在多个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
    nvq++
    compiler.
  • 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 (
    nvidia
    ) unless: the user is on macOS/Apple Silicon, mentions no GPU available, or explicitly asks for CPU-only simulation - in those cases use
    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 -
    pip install cudaq
    + CUDA Toolkit
  • macOS (ARM64/Apple Silicon): CPU simulation only -
    pip install cudaq
    (no CUDA Toolkit needed)
  • 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加速目标(
    nvidia
    ),除非:用户使用macOS/Apple Silicon、提及无可用GPU,或明确要求仅CPU仿真——此时使用
    qpp-cpu
  • 除非用户无本地环境或询问云访问选项,否则不推荐云试用或Launchpad选项。
平台说明
  • Linux(x86_64、ARM64):完整GPU支持 -
    pip install cudaq
    + CUDA Toolkit
  • macOS(ARM64/Apple Silicon):仅CPU仿真 -
    pip install cudaq
    (无需CUDA Toolkit)
  • 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.kernel
    /
    __qpu__
    marks a quantum kernel - compiled to Quake MLIR
  • cudaq.qvector(N)
    allocates N qubits in |0⟩
  • cudaq.sample()
    - kernel measures qubits; returns bitstring histogram (
    SampleResult
    )
  • cudaq.run()
    - kernel returns a classical value; runs
    shots_count
    times and returns a list of those return values
  • cudaq.observe()
    - computes expectation value ⟨H⟩ for a spin operator
  • cudaq.get_state()
    - returns the full statevector (simulator only)
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 (
inspect
module ->
ast_bridge.py
-> Quake MLIR -> QIR -> JIT), route to
/cudaq-compiler
.

需讲解的核心概念
  • @cudaq.kernel
    /
    __qpu__
    标记量子内核——编译为Quake MLIR
  • cudaq.qvector(N)
    分配N个处于|0⟩态的量子比特
  • cudaq.sample()
    - 内核测量量子比特;返回比特串直方图(
    SampleResult
  • cudaq.run()
    - 内核返回经典值;运行
    shots_count
    次并返回结果列表
  • cudaq.observe()
    - 计算自旋算子的期望值⟨H⟩
  • cudaq.get_state()
    - 返回完整态矢量(仅仿真器支持)
内核限制
  • 内核内仅支持受限Python子集——编译为Quake MLIR,而非常规Python。
  • 内核内无法使用NumPy与SciPy。可在内核外使用它们进行经典预处理/后处理。
  • 内核可调用其他内核;被调用方也必须是
    @cudaq.kernel
    标记的内核。
若涉及编译器内部机制(
inspect
模块 ->
ast_bridge.py
-> Quake MLIR -> QIR -> JIT),请引导至
/cudaq-compiler

GPU 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目标

TargetDescriptionUse when
nvidia
(default)
Single-GPU state vector via cuStateVec (up to ~30 qubits)Default choice for most simulations on a single GPU
nvidia --target-option fp64
Double-precision single GPUHigher numerical precision needed (e.g. chemistry, sensitive observables)
nvidia --target-option mgpu
Multi-GPU, pools memory across GPUs (>30 qubits)Circuit exceeds single-GPU memory; requires MPI
nvidia --target-option mqpu
Multi-QPU, one virtual QPU per GPU, parallel executionRunning many independent circuits in parallel (e.g. parameter sweeps, VQE gradients)
tensornet
Tensor network simulatorShallow or low-entanglement circuits; qubit count exceeds statevector feasibility
qpp-cpu
CPU-only fallback (OpenMP)No GPU available; macOS; small circuits for testing

目标描述使用场景
nvidia
(默认)
基于cuStateVec的单GPU态矢量(最多约30量子比特)大多数单GPU仿真的默认选择
nvidia --target-option fp64
双精度单GPU需要更高数值精度的场景(如化学、敏感观测)
nvidia --target-option mgpu
多GPU,跨GPU池化内存(超过30量子比特)电路超出单GPU内存;需MPI支持
nvidia --target-option mqpu
多QPU,每个GPU对应一个虚拟QPU,并行执行并行运行大量独立电路(如参数扫描、VQE梯度)
tensornet
张量网络仿真器浅层或低纠缠电路;量子比特数超出态矢量可行性
qpp-cpu
仅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.
TechnologyProviderDoc file
Ion trapIonQ
docs/sphinx/using/backends/hardware/iontrap.rst
(IonQ section)
Ion trapQuantinuum
docs/sphinx/using/backends/hardware/iontrap.rst
(Quantinuum section)
SuperconductingIQM
docs/sphinx/using/backends/hardware/superconducting.rst
(IQM section)
SuperconductingOQC
docs/sphinx/using/backends/hardware/superconducting.rst
(OQC section)
SuperconductingAnyon
docs/sphinx/using/backends/hardware/superconducting.rst
(Anyon section)
SuperconductingTII
docs/sphinx/using/backends/hardware/superconducting.rst
(TII section)
SuperconductingQCI
docs/sphinx/using/backends/hardware/superconducting.rst
(QCI section)
Neutral atomInfleqtion
docs/sphinx/using/backends/hardware/neutralatom.rst
(Infleqtion section)
Neutral atomQuEra
docs/sphinx/using/backends/hardware/neutralatom.rst
(QuEra section)
Neutral atomPasqal
docs/sphinx/using/backends/hardware/neutralatom.rst
(Pasqal section)
CloudAWS Braket
docs/sphinx/using/backends/cloud/braket.rst
CloudScaleway
docs/sphinx/using/backends/cloud/scaleway.rst
After walking through the provider steps, always close with
  • Test locally first with
    emulate=True
    before submitting to real hardware.
  • Use
    cudaq.sample_async()
    /
    cudaq.observe_async()
    for non-blocking submission.

当用户调用此章节时,请勿一次性列出所有服务商。请遵循以下两步对话流程:
步骤1 - 询问用户目标技术类型
text
您的目标QPU技术类型是?
  1. 离子阱       (IonQ, Quantinuum)
  2. 超导电路      (IQM, OQC, Anyon, TII, QCI)
  3. 中性原子      (QuEra, Infleqtion, Pasqal)
  4. 云端/多平台    (AWS Braket, Scaleway)
步骤2 - 用户选择技术类型后,询问具体服务商,然后读取对应文档文件并逐步引导用户操作。
技术类型服务商文档文件
离子阱IonQ
docs/sphinx/using/backends/hardware/iontrap.rst
(IonQ章节)
离子阱Quantinuum
docs/sphinx/using/backends/hardware/iontrap.rst
(Quantinuum章节)
超导电路IQM
docs/sphinx/using/backends/hardware/superconducting.rst
(IQM章节)
超导电路OQC
docs/sphinx/using/backends/hardware/superconducting.rst
(OQC章节)
超导电路Anyon
docs/sphinx/using/backends/hardware/superconducting.rst
(Anyon章节)
超导电路TII
docs/sphinx/using/backends/hardware/superconducting.rst
(TII章节)
超导电路QCI
docs/sphinx/using/backends/hardware/superconducting.rst
(QCI章节)
中性原子Infleqtion
docs/sphinx/using/backends/hardware/neutralatom.rst
(Infleqtion章节)
中性原子QuEra
docs/sphinx/using/backends/hardware/neutralatom.rst
(QuEra章节)
中性原子Pasqal
docs/sphinx/using/backends/hardware/neutralatom.rst
(Pasqal章节)
云端AWS Braket
docs/sphinx/using/backends/cloud/braket.rst
云端Scaleway
docs/sphinx/using/backends/cloud/scaleway.rst
完成服务商步骤引导后,务必以以下内容收尾:
  • 提交至真实硬件前,请先在本地使用
    emulate=True
    进行测试。
  • 使用
    cudaq.sample_async()
    /
    cudaq.observe_async()
    实现非阻塞提交。

Applications

应用

CUDA-Q ships with ready-to-run application notebooks
CategoryExamples
OptimizationQAOA, ADAPT-QAOA, MaxCut
ChemistryVQE, UCCSD, ADAPT-VQE
Error CorrectionSurface codes, QEC memory
AlgorithmsGrover's, Shor's, QFT, Deutsch-Jozsa, HHL
MLQuantum neural networks, kernel methods
SimulationHamiltonian dynamics, Trotter evolution
FinancePortfolio 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.
GoalStrategyTarget option
Single circuit too large for one GPUPool GPU memory
nvidia --target-option mgpu
Many independent circuits at onceRun circuits in parallel
nvidia --target-option mqpu
Large Hamiltonian expectation valueDistribute terms across GPUs
mqpu
+
execution=cudaq.parallel.thread
CUDA-Q支持两种不同的多GPU并行策略——根据您的扩展需求选择。
目标策略目标选项
单电路超出单GPU内存GPU内存池化
nvidia --target-option mgpu
同时运行大量独立电路电路并行运行
nvidia --target-option mqpu
大型哈密顿量期望值跨GPU分配哈密顿量项
mqpu
+
execution=cudaq.parallel.thread

Circuit batching with mqpu (
sample_async
/
observe_async
)

基于mqpu的电路批处理(
sample_async
/
observe_async

The
mqpu
option maps one virtual QPU to each GPU. Dispatch circuits asynchronously with
qpu_id
to all GPUs simultaneously.
python
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]
mqpu
选项将每个GPU映射为一个虚拟QPU。通过
qpu_id
异步将电路分发至所有GPU。
python
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
execution=
to
cudaq.observe
— no other code change needed.
python
undefined
对于带有大型哈密顿量的单个内核,在
cudaq.observe
中添加
execution=
参数即可——无需修改其他代码。
python
undefined

Single 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
    mgpu
    target requires MPI
  • 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
    mgpu
    目标需要MPI支持
  • 内核代码必须使用受限Python子集;内核内不允许使用NumPy/SciPy
  • QPU访问需要特定服务商的凭证与账号

Troubleshooting

故障排查

  • Import error after
    pip install cudaq
    : Ensure Python 3.10+ and a supported OS (Linux or macOS)
  • No GPU detected: Verify CUDA Toolkit is installed and
    nvidia-smi
    shows your GPU; fall back to
    qpp-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
  • pip install cudaq
    后出现导入错误:确保Python版本为3.10+且系统为支持的OS(Linux或macOS)
  • 未检测到GPU:验证CUDA Toolkit已安装且
    nvidia-smi
    显示您的GPU;可切换至
    qpp-cpu
  • 内核编译错误:检查
    @cudaq.kernel
    内仅使用了支持的Python语法
  • QPU提交失败:确认已按照服务商文档将凭证设置为环境变量