Getting Started#

Note

CUDA-Q Pulse is a research preview: expect bugs and incompatible changes between releases. It is not a supported CUDA-Q product feature. “Stability” in What Runs Today says what may change.

Installation#

CUDA-Q Pulse requires Python 3.12 or newer and does not depend on CUDA-Q. Its wheels contain a statically linked MLIR, so pip is the only installer needed. Install it from PyPI; pip picks the wheel for your platform:

python -m venv .venv
source .venv/bin/activate

# The compiler, on Linux and macOS
pip install cudaq-pulse

Then check what was installed and whether it works:

python -m cudaq_pulse.doctor

cudaq-pulse-opt, the MLIR driver, comes along automatically: it is in cudaq-pulse-tools, a wheel of its own, one per platform for every Python, which cudaq-pulse requires at the same version. The other dependencies come from PyPI too. Each release on the GitHub releases page also carries the wheels and the source distribution.

The wheels are for Linux (x86_64 and aarch64, glibc 2.28 or newer) and for macOS 11 or newer on arm64, with Python 3.12 or newer. Every installation can trace, compile, transform and inspect kernels, and has the cudaq-pulse-opt MLIR driver on PATH. If something does not work, run python -m cudaq_pulse.doctor first.

Simulation is installed too: on a CPU with every installation, and on an NVIDIA GPU with one more extra. Install for GPU simulation has the extras, the platform table and the doctor’s GPU options.

Hello World#

Define a pulse kernel, compile it for a quantum system, and read the timed program: what each line of the control electronics does, and when.

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]

# lower() compiles the call and schedules it; nothing runs.
scheduled = rabi.lower(qubit, 0.16)
print("length:", scheduled.duration)
for event in scheduled.schedule:
    print(f"{event.kind:8} line {event.line}  cycles {event.start} to {event.end}")

Output

length: 332 ns
drive    line 0  cycles 0 to 64
readout  line 1  cycles 64 to 664
Timeline of one call of the Rabi kernel on D1: a 32 ns Gaussian drive pulse, then, where sync puts it, a 300 ns square readout pulse on the readout line. Timeline of one call of the Rabi kernel on D1: a 32 ns Gaussian drive pulse, then, where sync puts it, a 300 ns square readout pulse on the readout line.

The same schedule as a timeline, in nanoseconds: the drive from 0 to 32 ns, then the readout from 32 to 332 ns.#

At amplitude 0.16 this drive pulse is close to a π pulse, the pulse that takes the qubit from one state to the other; Your First Pulse Program shows it by simulating the kernel.

This is the kernel of Your First Pulse Program, which explains it line by line. scheduled.mlir() is the same program as MLIR, and scheduled.metrics.total_ms how long it took to compile.

The pulse lasts 32 ns, 64 cycles of the quantum system’s 2 GHz clock. A duration is an int number of cycles or a time with units; see Durations: cycles or times. Every drive and readout has its line and its start and end in clock cycles: this timed program is what a controller backend turns into the instructions of your sequencers, and From a Kernel to Your Control Electronics goes from here to a control system of your own.

The same program can be simulated: a call of the kernel, rabi(qubit, 0.16), compiles it and simulates one shot on the CPU. Simulate a kernel continues from this kernel.

The Compiler Pipeline#

CUDA-Q Pulse is a Python-first compiler pipeline:

  1. Write a kernel in Python – the @pulse.kernel DSL (get_drive_line, drive, gaussian, wait, sync, …).

  2. Compile to MLIR – kernel.lower(*args) compiles and schedules a call without running it, and returns the compiled module, whose .mlir() is the scheduled Pulse dialect; pulse.compile(kernel) compiles ahead of the call. Calling the kernel compiles it on first use and simulates one shot. See Compile and Inspect a Program.

  3. Extend the pipeline – check a compiled module’s schedule in Python, or load your own MLIR passes into cudaq-pulse-opt as plugins. See Write Your Own Passes.

  4. Hand it to your control electronics – compiling for a control system (pulse.compile(kernel, control_system=...)) checks the scheduled program against each controller’s limits, and a controller backend turns it into the controller’s own instructions. See From a Kernel to Your Control Electronics.

  5. Or simulate it – pulse.simulate(kernel, *args) evolves the same program on a CPU or a GPU. See Simulation.

For how the compiler works inside, from bytecode tracing to scheduling and lowering, see Compilation Pipeline.

IDE Setup#

None is needed. Pylance (in VS Code and VS Code-based editors), pyright and basedpyright know the operations used by bare name inside @pulse.kernel functions, with completion, hover documentation and checked arguments, as soon as cudaq-pulse is installed. See Set Up Your Editor.

Doctor Options#

The doctor takes at most one of --allow-no-gpu, --expect-no-device, --setup-editor or --system, and none is needed for the check above. --json goes with --system; --project and --yes go with --setup-editor.

Doctor options#

Option

What it does

See

--allow-no-gpu, --expect-no-device

For GPU simulation.

Install for GPU simulation

--setup-editor

Show the mypy and ruff configuration the kernel language needs, and write it when confirmed (pyright-based editors need none).

Set Up Your Editor

--system FILE

Check the system file FILE as pulse.QuantumSystem.load(FILE) does: every problem, its controllers and links, and whether their backends are installed.

Describe a Quantum System

--json

With --system, print the report as JSON.

Describe a Quantum System

--project PROJECT

Project directory for --setup-editor (default: the current directory).

Set Up Your Editor

--yes

With --setup-editor, write without asking.

Set Up Your Editor

Running the Tests#

The test suite lives in the source repository rather than the wheel, and it imports whichever cudaq_pulse is installed, so it checks the installation you actually have:

git clone https://github.com/NVIDIA/cudaq-pulse.git
cd cudaq-pulse
pip install --group test        # pytest, hypothesis, lit (pip 25.1+)

pytest tests -m "not gpu"       # any installation
pytest tests                    # GPU installations: also runs the GPU suite

“Run the GPU tests” in Simulation says what the GPU suite covers.

Building from Source#

Contributors build with CMake against a pinned, checksum-verified MLIR toolchain that a script downloads; nothing else is compiled from source. The complete workflow, including GPU builds, linting, benchmarks, and building this documentation, is described in CONTRIBUTING.md at the repository root. In short:

uv sync
python3 tools/fetch-mlir-toolchain.py   # optional; configuring fetches it too
cmake --preset dev
cmake --build --preset check        # builds, then runs check-pulse

To build this documentation, run cmake --preset docs and cmake --build --preset docs; the HTML is written to build/docs/docs/html.

Where to go next#

The next page is Your First Pulse Program: it explains the kernel above line by line and simulates it. After it, choose what you are doing in the table on the landing page.