Simulation#

A compiled program can be run without control electronics in two ways. Simulation evolves the quantum system’s model under the program’s pulses, on a CPU or on an NVIDIA GPU. Emulation runs the program’s timing and its classical calls in virtual time, without physics. This section holds what the documentation says about both; the pages about kernels, control systems and compiling do not depend on it.

GPUs matter in two places in CUDA-Q Pulse: a decoder that a program calls in its control loop during a shot (Real-Time Decoding with a Deadline), and density-matrix simulation on an NVIDIA GPU, which is a research preview.

Read first: Your First Pulse Program, the CPU simulation tutorial.

What you can do with a compiled program#

Simulate it (pulse.simulate, with the NumPy reference on any machine or on an NVIDIA GPU), or emulate it in virtual time against its classical services (classical.emulation.emulate). Both take the program that a controller backend takes; see From a Kernel to Your Control Electronics for that path.

What is modeled#

The simulators evolve the quantum system’s model, not a device. The options of pulse.simulate that choose what the model includes (Simulation API has them all):

  • dephasing: dephase at each qudit’s Ramsey T2* ("t2_star", the default) or its Hahn-echo T2 ("t2_echo"), which every simulated qudit must have.

  • readout: "ideal" (the default) reports the measured level. "model" reports through each qubit’s assignment errors, and "model_with_decay" adds relaxation during the readout window.

  • levels: levels per qudit. By default each qudit has the levels its quantum system’s simulation model declares for it (3 for a TransmonModel); an int sets every qudit’s, and a dict by quantum system qudit index sets those it names.

  • shots_count: sample this many per-shot measurement records, a positive int; None (the default) samples none. seed is the seed for sampling the records.

  • backend: "cpu" (the default) for the NumPy reference integrator (RK4), "gpu" for the cuDensityMat runtime.

The two parts below hold for CPU and GPU simulation alike.

Physical Model#

The simulated space holds only the qudits the program uses: those it gets a drive or readout line on, one mode each in increasing order of quantum system index. A pair at qudits 13 and 3 of the 17-qudit transmon_surface17 quantum system is a 3 x 3 problem with three levels, not a 3^14 one. Couplings and residual ZZ between those qudits keep their quantum system values; the other qudits are left out, with their couplings, as classical spectators in their ground state. To simulate an idle qudit, get a line on it. result.qudits lists the quantum system qudit of each mode: result.qudits[i] has result.dims[i] levels and is digit i of the state index, least significant first. An initial_state uses the same layout, and measurements report quantum system qudits.

The native simulation lowering is a transmon model in one rotating frame per qudit, with the levels the quantum system’s simulation model declares for it (three for a TransmonModel) unless levels sets them. Drive envelopes are converted to X/Y Hamiltonian coefficients in radians per nanosecond; tone frequency and phase determine the rotating-frame detuning and quadrature. Drive terms are in the rotating-wave approximation: the counter-rotating terms, which turn at about twice the qudit frequency, are dropped. Against an exact lab-frame evolution of a three-level transmon, that costs about 2e-5 in population for a 40 ns pi pulse and about 3e-4 for a 10 ns one; the integrator’s own error is far smaller. A quantum system may supply amplitude_scale_rad_per_ns explicitly, or pulse infers a scale from the amplitude of the qudit’s X calibration when it publishes one.

The quantum system’s relaxation and dephasing data produce Lindblad collapse operators. A qudit whose thermal_population p is nonzero starts in its thermal mixture (the excited level holds p, and higher levels follow the same Boltzmann ratio p / (1 - p) per level) unless initial_state is given, and relaxes towards it: down at (1 - p) / T1 and up at p / T1, so populations relax at the measured 1 / T1. Qudits dephase at their Ramsey T2*, or at their Hahn-echo T2 with simulate(..., dephasing="t2_echo"). A coupling’s operator comes from the system’s model: for a TransmonModel it is the exchange g (a^dagger b + a b^dagger), with strength_hz = g / 2 pi, in the rotating-wave approximation (the counter-rotating terms a b and a^dagger b^dagger are dropped). In the qudits’ own frames it turns at their detuning, so detuned qudits exchange little and coupled transmons with three or more levels acquire the dispersive ZZ shift. A coupling whose strength_hz is None, not measured yet, is refused by name when the program’s qudits include both of its qudits. A residual_zz entry of rate zeta (E11 - E10 - E01 + E00 = zeta) adds zeta n_a n_b. With three or more levels, a qudit’s drive acts through its ladder operator (X = a + a^dagger, Y = i(a^dagger - a)) and anharmonicity_hz adds (alpha / 2) n (n - 1), so leakage out of the qubit subspace is modeled; with two levels the anharmonicity is calibration metadata only.

Measurement and Feedback#

pulse.simulate() evolves a program that measures, and branches on the results, in intervals between measurements. A readout measures its qudit in the computational basis when it completes: every level k is a separate outcome, and each continues along its own path, on which a branch on that measurement takes the arm the outcome selects. The unnormalized states of all paths sum to the ensemble

\[\rho' = \sum_m U_m P_m \rho P_m^\dagger U_m^\dagger\]

with no sampling error. Requesting shots_count also samples per-shot records of the outcomes from the same branch probabilities.

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 active_reset(qubit):
    drive_line = get_drive_line(qubit)
    readout_line = get_readout_line(qubit)
    readout_time = 500 * pulse.ns
    pi_time = 20 * pulse.ns
    result = readout(readout_line, square(readout_time, 0.05))
    sync(drive_line, readout_line)
    if result:
        drive(drive_line, square(pi_time, math.pi / 20.0))

scheduled = active_reset.lower(qs.qudits[0])
result = pulse.simulate(scheduled, shots_count=1000, backend="cpu")
result.density_matrix   # ensemble state at the end
result.level_population(1)   # P(1) of the one qudit; level_population(1, qudit=q) for one of several
result.level_populations()   # [P(0), P(1), P(2)] for a three-level qudit
result.branches         # [Branch(levels=(0,), probability=0.5, calls=()), ...]
result.records          # one row of outcomes per shot

density_matrix is given in the reference that rotates at each simulated qudit’s own frequency, before the couplings among the simulated qudits dress it. The tone of a coupled qudit’s drive line is at its dressed frequency, which its couplings move (by about g²/detuning for one neighbour). So a phase read from density_matrix drifts against the tone at their difference, while populations are the same in both. To measure a phase as the tone sees it, turn it onto a population with a pulse and read that.

result.postselect(keep) is the result over the branches the test keep accepts, a function of a Branch: its state is their state, normalized, acceptance is the probability of the kept branches, and records holds the shots that took them. A herald or a check is post-selected on its outcome or on a classical call’s answer:

kept = result.postselect(lambda b: b.levels[0] == 0)   # the shots that read 0
kept.acceptance            # their probability, 0 to 1
kept.density_matrix        # their state, of trace 1
kept.level_populations()

backend="cpu" integrates the same lowered operator with a NumPy RK4 reference; backend="gpu" evolves each interval with cuDensityMat, starting from the projected state. By default each qudit has the levels its quantum system’s model declares (three for a transmon); levels=2 simulates qubits, an int sets every qudit’s levels and a dict by quantum system qudit index sets those it names. With three or more levels a transmon includes its anharmonicity.

What is not modeled#

  • Flux lines are not modeled. On the built-in transmon_surface17 system a CZ holds its duration in a schedule and no pulse performs it: a kernel waits for that time on both qudits. So a schedule has the right length, and a simulation of it has no entangling gate from a CZ. The couplings between qudits are simulated, always on, at the strengths the system states.

  • A readout is simulated as a measurement at the end of its pulse. It reports the measured level unless readout="model" sends the outcome through the qudit’s assignment errors.

  • The qudits a program gets no line on are left out, with their couplings, as classical spectators in their ground state.

  • The counter-rotating terms of drives and couplings are dropped.

  • With two levels a qudit’s anharmonicity is calibration metadata only.

  • Emulation runs timing and classical calls without physics.

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. “Unsupported Execution Features” in GPU Simulation Reference has the whole list, and “Calibrated gates” in The transmon_surface17 Quantum System says what the built-in system’s simulation includes.

How large and how long#

No simulation timing or size limit is published yet. What the documentation states about size:

  • The simulated space holds only the qudits the program uses, with three levels each for a transmon by default: a pair of the 17-qudit transmon_surface17 system is a 3 x 3 problem, not a 3^14 one.

  • By default a simulation follows every outcome of every measurement. branches="sampled" follows only the outcomes the shots draw, at most shots_count branches, so a program that measures many times inside one shot does not cost time exponential in its measurements.

  • On a GPU, the callback runtime holds 1024 time-dependent coefficients per evolution, and the GPU test suite covers an eight-qubit ladder register; see “Unsupported Execution Features” in GPU Simulation Reference.

To measure simulation time on your machine, benchmarks/classical/classical_calls.py times the simulation of an active reset with and without a decoder call, among its other parts:

python benchmarks/classical/classical_calls.py

The number below is a statistic of a simulated experiment, not a timing.

Adaptive T1 Estimation#

benchmarks/classical/adaptive_t1_estimates.py runs the adaptive T1 tracker of examples/21_calibration_protocol.py (after Berritta et al., arXiv:2506.09576) 400 times in simulation, on a model qubit with a T1 of 160 us, assignment errors of 0.11 and 0.14 and the paper’s prior, for 50 adaptive shots each, and writes every run’s estimate. benchmarks/classical/adaptive_t1_estimates.json is its output for seed 1:

python benchmarks/classical/adaptive_t1_estimates.py --trajectories 400 --seed 1 \
    --output benchmarks/classical/adaptive_t1_estimates.json
python benchmarks/classical/adaptive_t1_estimates.py \
    --check benchmarks/classical/adaptive_t1_estimates.json

The median estimate is 155 us (bootstrap 95% interval 151 to 160 us), and 68% of runs fall between 123 and 195 us. The paper reports 159 us with a 68% interval of 131 to 202 us on its processor. The file holds no timings, so the same seed and number of runs write the same estimates; --check regenerates them and compares (one run takes about a minute on the host that Performance and Cost describes).

Simulate a kernel#

The kernel here is the kernel of Getting Started: one drive pulse on a qubit of the built-in quantum system, then a readout.

import cudaq_pulse as pulse


@pulse.kernel
def rabi(qudit, amplitude: float):
    drive_line = get_drive_line(qudit)
    readout_line = get_readout_line(qudit)
    flip = gaussian(
        duration=32 * pulse.ns,
        amplitude=amplitude,
        sigma=8 * pulse.ns,
    )

    drive(drive_line, flip)
    # Start the readout after the drive pulse ends.
    sync(drive_line, readout_line)
    return readout(readout_line, square(300 * pulse.ns, 0.05))


system = pulse.quantum_system("transmon_surface17")
qubit = system.qudits[0]

A call of the kernel compiles it and simulates one shot on the CPU, no GPU needed:

outcome = rabi(qubit, 0.16)
print(outcome)   # the readout's outcome, 0 or 1

A call returns what the kernel returns, here the outcome of its readout.

For populations, many shots or other options, pulse.simulate takes the kernel and the same arguments and returns the result:

result = pulse.simulate(rabi, qubit, 0.16)
print(f"P(1) = {result.level_population(1):.3f}")

shots = pulse.simulate(rabi, qubit, 0.16, shots_count=1000, seed=7)
print(int((shots.records == 1).sum()), "of 1000 shots read 1")

Output

P(1) = 0.963
956 of 1000 shots read 1

Your First Pulse Program goes on from here: a sweep of the amplitude, shots, and the schedule drawn.

How simulation lowers a program#

pulse.simulate(kernel, *args) compiles a call and evolves it with the NumPy reference, and pulse.simulate(kernel, *args, backend="gpu") on the GPU, through the native Pulse -> QOp -> CuDensityMat -> LLVM lowering (scheduled.mlir("llvm")). A program compiled already is simulated the same way without compiling it again: pulse.simulate(program, *values) binds the values of its run-time float parameters as program.bind(values) does.

GPU simulation via NVIDIA cuDensityMat is a preview capability; see GPU Simulation Reference. The next section shows each level of the lowering, and Simulation Dialects lists the operations of its two dialects.

The simulation lowering, level by level#

For GPU simulation, three dialect conversion passes lower the IR:

  1. Pulse -> QOp: Converts pulse operations to quantum operator algebra (Hamiltonians, Lindbladians)

  2. QOp -> CuDensityMat: Maps operators to cuDensityMat API calls

  3. CuDensityMat -> LLVM: Final lowering to LLVM IR with runtime library calls

mlir(level) on a scheduled kernel gives the program’s text at the Pulse level or at any of the three levels below it. This block lowers a kernel that drives one qubit and prints each level (a program that measures is lowered along a measurement-outcome path instead, as the next paragraph says, and mlir of a level below Pulse raises for it):

import cudaq_pulse as pulse

@pulse.kernel
def two_pulses(qubit, amplitude: float, duration, sigma):
    drive_line = get_drive_line(qubit)
    drive(drive_line, gaussian(duration, amplitude, sigma))
    wait(drive_line, duration)
    drive(drive_line, gaussian(duration, amplitude, sigma))

qs = pulse.quantum_system("transmon_surface17")
scheduled = two_pulses.lower(qs.qudits[0], 0.16, 32 * pulse.ns, 8 * pulse.ns)
print(scheduled.mlir("pulse"))  # the scheduled Pulse dialect
print(scheduled.mlir("qop"))    # quantum operators: the Hamiltonian and dissipators
print(scheduled.mlir("cudm"))   # cuDensityMat operators and evolution
print(scheduled.mlir("llvm"))   # the LLVM dialect, ready to compile

The simulation lowering supports transmon models with any number of levels in a rotating frame. A program that measures is lowered one interval at a time along a measurement-outcome path, and the intervals are joined by projecting the state. Systems without a simulation model (a quantum system whose model is None or has no simulator) and unspecialized waveforms are rejected instead of silently approximated. See “What is modeled” on this page for the complete model and “Unsupported Execution Features” in GPU Simulation Reference for the limitations.

examples/transmon/transmon_surface17_full_pipeline.py prints each stage of the lowering: the Pulse MLIR, the QOp form and the LLVM IR.

Install for GPU simulation#

pip install cudaq-pulse installs the compiler and CPU simulation (Linux and macOS), as Getting Started shows. For GPU simulation on Linux, also install one CUDA extra, never both:

# 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]"

[gpu] is an alias for [cu12]. Each CUDA extra installs cuDensityMat and the CUDA runtime libraries it needs from PyPI; the two extras write the same files, so install only one of them per environment.

Supported platforms#

Platform

Python

Capabilities

Linux x86_64 and aarch64, glibc 2.28 or newer

3.12+

Compiler and CPU simulation; GPU simulation with [cu12] or [cu13]

macOS 11 or newer, arm64

3.12+

Compiler and CPU simulation

GPU simulation additionally requires an NVIDIA GPU with compute capability 7.0 or newer and a Linux driver of at least 525.60.13 for [cu12] or 580 for [cu13]. The driver is the only system requirement: no CUDA toolkit or cuQuantum SDK installation is needed. See GPU Simulation Reference.

Every installation can trace, compile, transform, inspect and simulate kernels, the last with the NumPy reference, and has the cudaq-pulse-opt MLIR driver on PATH. Only GPU simulation needs the GPU, and it never degrades silently; see GPU Runtime Errors. If something does not work, run python -m cudaq_pulse.doctor first. Without a CUDA extra it ends with Result: OK, compilation and CPU simulation work; GPU simulation is not set up. and names the extra and driver that enable GPU simulation.

Two of the doctor’s options are about GPU simulation; the others are in Getting Started:

Doctor options for GPU simulation#

Option

What it does

See

--allow-no-gpu

Succeed when compilation and CPU simulation work, even if GPU simulation is set up but unavailable because the build has no GPU runtime or no usable device or driver exists.

GPU Simulation Reference

--expect-no-device

Succeed only if every GPU library loads and the sole problem is that no usable GPU device exists.

GPU Simulation Reference

Run the GPU tests#

pytest tests on a GPU installation also runs the GPU suite (see “Running the Tests” in Getting Started). The GPU tests exercise single-qubit drive evolution, T1 decay, two-qubit XX coupling, integrator parity, and the public compile/JIT path. Selecting them on an installation that cannot run them stops pytest immediately and reports which of the three GPU errors applies, rather than skipping them. They are research regression tests, not a production numerical-accuracy qualification.

Where to go next#