Examples#

The examples in the examples/ directory cover pulse-level programming from single-qubit Rabi oscillations to multi-qubit error-correction cycles, and from a kernel to the instructions a controller executes. Every example except transmon/transmon_surface17_evolve_gpu.py runs on a CPU-only machine, Linux or macOS, and the test suite runs each of them. Numbers 11 and 15 were removed and are not reused.

New here? Start with Getting Started, then Your First Pulse Program. The tutorials explain the same ideas step by step, and each one ends by naming the examples that take it further.

All examples use the canonical import convention:

import cudaq_pulse as pulse

Run an example from a clone of the repository:

# From a clone of the repository, with cudaq-pulse installed.
python examples/01_single_qubit_rabi.py

The examples are in the groups of the tutorials: “Start”, for everyone, then the six use cases of the landing page; each example is listed once. A card’s last line gives the example’s level and what it needs. There, simulates means the example also evolves the program with the NumPy reference (pulse.simulate); the others compile kernels and print their MLIR, schedules or metrics. Most examples run on the built-in chip that The transmon_surface17 Quantum System describes.

Start#

For everyone who writes kernels: the kernel language itself. This group comes before the six use cases and is not one of them. Run first: 05_waveform_gallery.py.

05_waveform_gallery.py

All 8 waveform constructors and 5 algebraic combinators

Source: 05_waveform_gallery.py

06_phase_frequency_control.py

Phase and frequency manipulation primitives on tone channels

Source: 06_phase_frequency_control.py

07_multi_qubit_sync.py

Multi-qubit programs with sync and registers of qudit handles

Source: 07_multi_qubit_sync.py

16_visualization.py

Schedule timelines; matplotlib plots with the [viz] extra

Source: 16_visualization.py

02_two_qubit_cross_resonance.py

Two-qubit CNOT via echoed cross-resonance driving

Source: 02_two_qubit_cross_resonance.py

17_ghz_state_prep.py

N-qubit GHZ state preparation using echoed cross-resonance CNOTs

Source: 17_ghz_state_prep.py

See also Write a Pulse Kernel and Operations and Waveforms.

Bring up control electronics#

For people who own the FPGA or AWG stack and write the backend that feeds it. Run first: controller_backend/sequencer_backend.py.

controller_backend/sequencer_backend.py

A generic FPGA-style sequencer backend: it turns a scheduled program into a per-channel instruction list with a waveform table, measurement feedback and run-time waits; the tutorial From a Kernel to Your Control Electronics shows it a piece at a time

Source: controller_backend/sequencer_backend.py

controller_backend/text_backend.py

A small backend that plays a program as text, registered in the running process; From Kernel to Controller shows it a piece at a time

Source: controller_backend/text_backend.py

controller_backend/toy_controller/__init__.py

A toy controller backend: its limits, emit and run

Source: controller_backend/toy_controller/__init__.py

controller_backend/pyproject.toml

The toy controller’s distribution, registering it in the cudaq_pulse.backends entry-point group

Source: controller_backend/pyproject.toml

isa_lowering/toy_isa.py

A lowering to a toy controller instruction set, its controllers described as data: the timestep, a waveform table, oscillators, a shared feedline, feedback branches within and across controllers, a decoder call, and emulated toy controllers

Source: isa_lowering/toy_isa.py

23_define_a_qpu.py

Define a QPU: two controllers loaded from an installed description with the installation’s wiring, a “feedback” link that takes a readout of one and answers the other, the compile-time checks against the control system, and the QPU saved and loaded as one system file

Source: 23_define_a_qpu.py

30_control_systems_compared.py

One QPU under five control systems, each defined in the file: the length of an active reset and of one surface-code round, the reset’s ground-state population and a data qubit’s idle error, side by side; the tutorial One QPU, Several Control Systems builds it step by step

Source: 30_control_systems_compared.py

29_waveform_envelopes.py

The samples each built-in envelope plays, from cudaq_pulse.controller.sample_waveform of the controller export, printed and plotted; the operations guide’s waveform explorer is the interactive version

Source: 29_waveform_envelopes.py

transmon/transmon_surface17_multiplexed_readout.py

One readout feedline shared by the four X-check ancillas: the tones it plays at once, and each readout’s tone slot in the controller export

Source: transmon/transmon_surface17_multiplexed_readout.py

See also Describe Your Control System, Write and Validate a Backend, and Lowering to Your Controller’s Instruction Set and Getting More out of Your Controller’s Instruction Set (experimental).

Calibrate a device#

For people who tune up and characterize qubits. Run first: 01_single_qubit_rabi.py.

01_single_qubit_rabi.py

Rabi oscillation: an amplitude sweep that compiles once

Source: 01_single_qubit_rabi.py

03_t1_t2_dissipator.py

T1 decay against its prediction; Ramsey and Hahn-echo kernels

Source: 03_t1_t2_dissipator.py

04_hahn_echo.py

Canonical Hahn spin-echo sequence (pi/2 - tau - pi - tau - pi/2) and its CPMG extension

Source: 04_hahn_echo.py

13_dynamical_decoupling.py

XY4, Uhrig, and CPMG dynamical decoupling sequences

Source: 13_dynamical_decoupling.py

14_randomized_benchmarking.py

Randomized benchmarking: random Cliffords and their inverse

Source: 14_randomized_benchmarking.py

20_adaptive_calibration.py

Adaptive calibration with variable waits, tracking a drifting quantum system

Source: 20_adaptive_calibration.py

21_calibration_protocol.py

A millisecond calibration chain run on the controller: readout errors, Ramsey frequency, pi and pi/2 amplitudes, and T1 by the analytical decay estimator and adaptive tracking, each step’s answer setting the next step’s pulses; the frequency binary search; and what each estimator costs the controller, after Marciniak et al., “Millisecond-Scale Calibration and Benchmarking of Superconducting Qubits”, arXiv:2602.11912 (2026), and Berritta et al., “Real-time adaptive tracking of fluctuating relaxation rates in superconducting qubits”, arXiv:2506.09576 (2025)

Source: 21_calibration_protocol.py

24_pipelined_calibration.py

Closed-loop calibration with a compile pipeline: the kernel is compiled once, worker processes bind and export the pickled program, and the next batch is ready when the QPU finishes the last

Source: 24_pipelined_calibration.py

25_precompiled_branches.py

Every next program of an adaptive experiment compiled ahead in worker processes and looked up by the check’s outcome, against compiling on demand

Source: 25_precompiled_branches.py

26_drift_following.py

Following a drifting qudit: a background process recompiles when the quantum system fingerprint changes, and the host swaps programs in between batches

Source: 26_drift_following.py

Examples 24 to 26 send compiled programs between processes, which works because programs pickle; their worker processes use the spawn start method.

Run feedback and error correction#

For people who close the loop during a shot: branches on readouts, calls to decoders and estimators. Run first: 08_readout_and_branching.py.

08_readout_and_branching.py

Readout channels and measurement-conditioned branching

Source: 08_readout_and_branching.py

19_classical_calls.py

Classical calls at QPU runtime: real-time decoding with feed-forward, call slack and hidden latency

Source: 19_classical_calls.py

transmon/transmon_surface17_surface_code_cycle.py

Timeline of one error correction cycle from the 17-qubit lattice and CZ schedule

Source: transmon/transmon_surface17_surface_code_cycle.py

27_realtime_decoding.py

Real-time QEC decoding with a deadline and a fallback table: the syndrome extracted with cross-resonance pulses on a five-transmon chain, and a decoder configured in CUDA-Q QEC, called with CUDA-Q QEC’s own functions

Source: 27_realtime_decoding.py

28_t_state_injection.py

T-state preparation with the virtual-Z pulse.gates.T, tomography, a herald on the controller repeated until it succeeds, and injection into a three-qubit repetition code with cross-resonance CNOTs on a custom chain

Source: 28_t_state_injection.py

Describe a QPU#

For people with a device of their own. Run first: 23_define_a_qpu.py, which is listed under “Bring up control electronics” because the QPU it defines is the built-in chip with a control system of two controllers.

22_runtime_qudits.py

One compile for every qudit of a quantum system: the qudit is bound at each call, and a frequency the kernel needs, read from the quantum system on the host, is an ordinary float parameter

Source: 22_runtime_qudits.py

See also 23_define_a_qpu.py and transmon/transmon_surface17_multiplexed_readout.py under “Bring up control electronics”: they attach controllers and lines to a quantum system, and the first saves the QPU as one system file.

Simulation#

For people who run programs without control electronics. Run first: transmon/transmon_surface17_rabi.py.

transmon/transmon_surface17_rabi.py

Rabi oscillation on the 17-qubit transmon_surface17 quantum system, lowered to the operator (QOp) dialect the simulator consumes

Source: transmon/transmon_surface17_rabi.py

transmon/transmon_surface17_evolve_gpu.py

pulse.simulate(..., backend="gpu") on the 17-qubit transmon_surface17 quantum system

Source: transmon/transmon_surface17_evolve_gpu.py

transmon/transmon_surface17_full_pipeline.py

Each stage of the native lowering: Pulse MLIR, QOp, and LLVM IR

Source: transmon/transmon_surface17_full_pipeline.py

Examples in the other groups simulate too, each to check what its program does: 30_control_systems_compared.py, 01_single_qubit_rabi.py, 03_t1_t2_dissipator.py, 14_randomized_benchmarking.py, 20_adaptive_calibration.py, 21_calibration_protocol.py, 24_pipelined_calibration.py, 25_precompiled_branches.py, 26_drift_following.py, 08_readout_and_branching.py, 19_classical_calls.py, 27_realtime_decoding.py and 28_t_state_injection.py.

See also Simulation.

Extend the compiler#

For people who read or change what the compiler does with a kernel. Run first: 09_compilation_pipeline.py.

09_compilation_pipeline.py

pulse.compile() and lower() walkthrough of the compiler stages

Source: 09_compilation_pipeline.py

10_scheduling_comparison.py

Side-by-side ASAP, ALAP, and RCP scheduling on a 4-qubit kernel

Source: 10_scheduling_comparison.py

18_per_kernel_schedules.py

Per-kernel ASAP and ALAP policies in a stabilizer cycle with dynamical decoupling, compared with one flat schedule

Source: 18_per_kernel_schedules.py

12_error_detection.py

pulse-verify diagnostics for intentionally malformed Pulse MLIR

Source: 12_error_detection.py

custom_passes/python_pass.py

A schedule check written in Python over ScheduledKernel.schedule

Source: custom_passes/python_pass.py

custom_passes/cpp/DriveCount.cpp

An MLIR pass plugin loaded with cudaq-pulse-opt --load-pass-plugin

Source: custom_passes/cpp/DriveCount.cpp

See also Write Your Own Passes.

Challenges#

For anyone who wants to practice on a problem with a score. The challenges/ folder has starter problems you can solve and score locally:

  • Find the pi pulse: Halve the length of a calibrated X pulse.

  • Mystery qubit: Measure the T1 of a qubit from shots alone.

  • Benchmark it yourself: Find a pulse’s error by randomized benchmarking.

  • Schedule golf: Make a five-qubit program finish sooner without changing what it does.

  • Fix the kernel: Find the five mistakes in a kernel, by what it plays.

  • Reset one qubit: Bring a qubit in an unknown state to its ground state, in time.