GPU Simulation Reference#

This is the reference page for GPU simulation: installation, errors, the lowering and what is unsupported. Simulating on a GPU is the tutorial, which runs one program on the CPU and then on a GPU.

Warning

GPU simulation is a research preview. It is not production software and carries no API, numerical, compatibility, or stability guarantee.

CUDA-Q Pulse contains an experimental lowering and runtime path intended to connect compiled kernels to NVIDIA cuDensityMat. This path remains active research and should not be treated as a production simulator.

The physical model that CPU and GPU simulation share, and how a program that measures is simulated (Measurement and Feedback), are in “What is modeled” in Simulation.

Installation#

Install cudaq-pulse from PyPI with one CUDA extra, never both, as in Install for GPU simulation:

# CUDA 12 libraries: NVIDIA driver 525.60.13 or newer
pip install "cudaq-pulse[cu12]"

# CUDA 13 libraries instead: NVIDIA driver 580 or newer
# pip install "cudaq-pulse[cu13]"

The Linux wheels include a cuDensityMat runtime library for each of CUDA 12 and CUDA 13. The cu12 and cu13 extras install cuDensityMat and the CUDA libraries for that major from PyPI; gpu is an alias for cu12. The two extras write the same files, so an environment may contain only one of them. macOS wheels have no GPU runtime; they compile and simulate on the CPU (backend="cpu").

Execution needs an NVIDIA GPU with compute capability 7.0 or newer and a Linux driver new enough for the installed CUDA major. No CUDA toolkit is used.

Driver requirements#

Extra

Minimum NVIDIA driver

[cu12] (or [gpu])

525.60.13

[cu13]

580

CUDA-Q Pulse picks the runtime that matches the installed extra. To choose it explicitly, set CUDAQ_PULSE_CUDA to 12 or 13. CUDM_RUNTIME_LIB points at a specific runtime library instead, for development builds.

Troubleshooting#

Run the diagnostics first:

python -m cudaq_pulse.doctor

It prints the version, the wheel platform, whether CPU simulation works, whether the GPU runtime is built in, which CUDA extra is installed, each library it loads with its path or the load error, and the driver version and device count. Without a CUDA extra, GPU simulation is not set up, and the doctor passes on CPU simulation alone:

CPU simulation (NumPy reference): ok
GPU runtime built in: no
CUDA extra installed: none
GPU simulation: not set up (GpuSupportNotBuiltError)
  ...
  To enable GPU simulation, on Linux with an NVIDIA GPU: pip install "cudaq-pulse[cu12]" (NVIDIA driver 525.60.13 or newer) or pip install "cudaq-pulse[cu13]" (NVIDIA driver 580 or newer).
Result: OK, compilation and CPU simulation work; GPU simulation is not set up.

Once a CUDA extra is installed, or CUDAQ_PULSE_CUDA or CUDM_RUNTIME_LIB is set, GPU simulation must work too: the doctor exits non-zero when the driver is too old for the extra, both extras are installed, or a library does not load, and its output names the reason. --allow-no-gpu also passes when an extra is installed but no device or driver is usable.

From Python, the same check is:

from cudaq_pulse.runtime import require_gpu_runtime

require_gpu_runtime()   # returns the loaded runtime or raises

Source builds enable the runtime with -DCUDAQ_PULSE_ENABLE_GPU=ON, which makes CUDA and cuDensityMat required: configuration fails instead of producing a compiler-only build. See CONTRIBUTING.md for the commands.

GPU Runtime Errors#

Every execution path calls require_gpu_runtime() first. It either returns a runtime backed by a usable GPU device or raises one of three errors, all subclasses of cudaq_pulse.runtime.GpuRuntimeError:

GpuSupportNotBuiltError

This installation was built without the GPU runtime: a macOS wheel or a source build configured without CUDAQ_PULSE_ENABLE_GPU. CPU simulation still works. For GPU simulation, reinstall a Linux wheel, or rebuild with GPU support.

GpuRuntimeLoadError

The runtime is built in but its libraries failed to load, usually because no CUDA extra is installed or both cu12 and cu13 are. The message names the library that failed and any CUDA libraries that are not installed as Python packages.

GpuDeviceUnavailableError

The libraries loaded, but no NVIDIA driver or device is available, or the driver is older than the installed CUDA major requires. The message names the driver version needed.

Compilation, transformation, and IR inspection never require the runtime, so they work in every installation.

Pipeline Overview#

The public execution path is:

  1. kernel.lower(*args) verifies, optimizes and schedules the kernel for the quantum system of its qudit handles.

  2. pulse.simulate(scheduled, backend="gpu") annotates the module with the quantum system’s calibration (drive scales, couplings, residual ZZ, T1/T2) and the native pipeline lowers it Pulse -> QOp -> CuDensityMat -> LLVM IR.

  3. MLIR’s ExecutionEngine compiles the LLVM IR in process and executes it against the cuDensityMat runtime library; no external compiler or LLVM tool is involved.

Float arguments stay symbolic through the Pulse -> QOp lowering; the GPU runtime takes constants, so the GPU path substitutes the call’s values into a private copy of the module first.

MLIR Lowering#

To inspect the lowered LLVM IR:

import cudaq_pulse as pulse

@pulse.kernel
def my_kernel(qubit):
    drive_line = get_drive_line(qubit)
    duration = 20 * pulse.ns
    sigma = 5 * pulse.ns
    drive(drive_line, gaussian(duration, 0.3, sigma))

qs = pulse.quantum_system("transmon_surface17")
llvm_ir = my_kernel.lower(qs.qudits[0]).mlir("llvm")
print(llvm_ir)

The lowering passes through three dialect conversions:

Pulse -> QOp

Converts supported drive operations and waveforms into backend-agnostic Hamiltonian and Lindblad operator algebra. A drive in a retained loop becomes one pulse-train coefficient. A program that measures is lowered one interval at a time along a chosen outcome for each measurement; see Measurement and Feedback.

QOp -> CuDensityMat

Maps operator algebra to cuDensityMat API calls (state creation, operator construction, time evolution).

CuDensityMat -> LLVM

Lowers cuDensityMat operations to LLVM IR with runtime library calls.

GPU Simulation#

To simulate on a GPU (requires cuDensityMat runtime):

import math
import cudaq_pulse as pulse
from cudaq_pulse.quantum_systems import MicrowaveDrive, PhysicalQudit

qs = pulse.quantum_system(
    name="one-qubit-demo",
    qudits={
        0: PhysicalQudit(
            index=0,
            frequency_hz=5.0e9,
            anharmonicity_hz=-200.0e6,
            t1_us=50.0,
            t2_star_us=30.0,
            drive=MicrowaveDrive(amplitude_scale_rad_per_ns=1.0),
        )
    },
)

@pulse.kernel
def x_gate(qubit, duration):
    drive_line = get_drive_line(qubit)
    drive(drive_line, square(duration, math.pi / 20.0))

pi_time = 20 * pulse.ns
scheduled = x_gate.lower(qs.qudits[0], pi_time)
result = pulse.simulate(scheduled, backend="gpu", t_end=20.0, dt_ns=0.1, integrator="rk4")
print(result.density_matrix)

t_end and dt_ns are in nanoseconds; t_end defaults to the end of the schedule. dt_ns defaults to 0.05 ns, or to 20 steps per period of the fastest frequency the simulation holds, rounded to a whole fraction of a clock cycle: a coupling between the program’s qudits turns at their detuning (0.024 ns for a pair 2.1 GHz apart, where 0.05 ns drifts by about 3e-5 per microsecond), and a qudit’s levels at the spread of their energies in its frame (0.015 ns for a transmon with 6 levels and a 330 MHz anharmonicity, whose levels spread over 3.3 GHz). A dt_ns you pass that takes fewer than 20 steps per period of the fastest frequency the simulation holds warns with a cudaq_pulse.PulseWarning naming that frequency and a step that resolves it: with three or more levels, a qudit’s coherence of levels 0 and 2 turns at its anharmonicity, which a 0.5 ns step (10 steps per period at 200 MHz) damps by about 15 % over a 200 ns shaped pulse. A step so coarse that the integrator diverges, about two steps per period or fewer (1 ns for 4 levels at a 184 MHz anharmonicity, which spread over 552 MHz), raises a cudaq_pulse.ExecutionError naming the same and a step that resolves it, rather than returning a state that is not finite. The integrator argument selects the time-evolution scheme used by the cuDensityMat runtime path:

  • rk1, rk2, rk4 – fixed-step explicit Runge-Kutta methods.

  • magnus – a fixed-step Magnus expansion evaluated as a truncated Taylor series of the propagator; preserves structure well for smoothly varying drives.

  • crank_nicolson – a fixed-step implicit predictor-corrector scheme that is more stable for stiff dynamics.

All five schemes reuse the same boundary-safe sampling that keeps piecewise constant pulse segments from being sampled across a discontinuity.

Where no drive plays for at least 1024 steps (a wait, a CZ slot without flux pulses, the latency of a classical call), the integrator does not step through it: the stretch is propagated exactly on the host, decay, couplings and residual ZZ included, and the GPU runs the drives before and after it with the steps they have in the whole program. Couplings of detuned qudits turn in the qudits’ frames; the propagation uses the frame that turns with them, where the idle Lindbladian is constant. This applies to registers of up to 40 levels with decay, and to any register without it; larger ones are stepped throughout.

Unsupported Execution Features#

The simulation lowering fails explicitly for observables, systems with no simulation model, products of two float arguments, arbitrary Python waveform callbacks, and waveform-algebra nodes. Built-in waveforms and custom_samples are supported. The callback runtime holds 1024 time-dependent coefficients per evolution: four per coupling between detuned qudits and, with the default operator lowering, two per driven qudit, whose pulses share one per quadrature. The banded and dense lowerings (CUDAQ_PULSE_GPU_OPERATORS, a development aid) take two per drive op instead; a drive repeated by a loop needs only one pair. A single evolution cannot contain a measurement: a program that measures is lowered and evolved one interval at a time (see Measurement and Feedback).

The GPU test suite (pytest tests -m gpu, or the check-pulse-gpu target in a source build) covers single-qubit drives, T1 decay, idle evolution, two-qubit coupling, frame and I/Q modulation, an eight-qubit ladder register, closed-system physics validation, quantum-algorithm building blocks, integrator parity across rk4/magnus/crank_nicolson, and the public lowering and JIT path. Source builds also run a cuDensityMat link check as part of check-pulse. Selecting the GPU tests where the runtime is unusable is an error, not a skip. These tests provide research regression coverage; they do not establish production numerical accuracy.

The returned state representation is experimental and may change with the lowering and runtime implementation.