Pulse Operations API#

These are the operations a kernel calls: channel access, scheduling, phase and frequency changes, and waveform constructors and arithmetic. They are used as bare names inside a @pulse.kernel function, without importing them. See Operations and Waveforms for what each operation does.

Channel Access#

cudaq_pulse.ops.get_drive_line(qudit, *others)[source]#

The drive line of a qudit.

A qudit has one drive line for the whole program: later calls, also from called kernels, return it as it now is, so pulses on it play in sequence. Its tone is line.tone.

On a control system that declares a broadcast drive line, DriveLine([0, 1, 2], broadcast=True), the line of any of its qudits is that one line, whose one tone reaches all of them, and a drive on it drives every one. get_drive_line(a, b, c), with all the line’s qudits, gives the same line and says what it reaches.

Parameters:
  • qudit (Any) – The qudit whose drive line to use.

  • others (Any) – The other qudits of a broadcast drive line, when the line is named by all its qudits.

Return type:

Line

cudaq_pulse.ops.get_readout_line(qudit)[source]#

The readout line of a qudit.

Like the drive line, a qudit has one readout line for the whole program. Its tone is line.tone, at the frequency its readout gives (a DispersiveReadout’s frequency_hz), else at its 0-1 frequency.

Parameters:

qudit (Any) – The qudit whose readout line to use.

Return type:

Line

Scheduling#

cudaq_pulse.ops.drive(line, waveform, *, tone=None)[source]#

Play a waveform on a drive line.

Parameters:
  • line (Line) – Drive line from get_drive_line().

  • waveform (Waveform) – Waveform envelope to play (e.g. from gaussian()).

  • tone (Tone | None) – The tone to play it at; by default the line’s own, line.tone. Another transition’s, line.tones[(1, 2)], or another line’s tone retunes the drive.

Return type:

None

cudaq_pulse.ops.readout(line, waveform, *, tone=None)[source]#

Acquire a measurement through a readout line.

Parameters:
  • line (Line) – Readout line from get_readout_line().

  • waveform (Waveform) – Readout waveform envelope.

  • tone (Tone | None) – The tone to play it at; by default the line’s own, line.tone.

Returns:

Measurement result handle.

Return type:

MeasurementResult

cudaq_pulse.ops.wait(target, duration, bounds=None)[source]#

Insert an idle delay on a line.

Parameters:
  • target (Line) – Drive or readout line.

  • duration (Numeric) – Wait duration: an int number of clock cycles, or a time (20 * pulse.ns) that is a whole number of them; a plain float is an error. It may be computed from float kernel parameters with +, -, * and /; the kernel then compiles once, and each call rounds the length to the nearest cycle (ties up) and schedules with it. When it is computed from the answer of a classical call, the wait is a variable region: every line syncs before it, and everything after it shifts with its length, which is known only when the program runs; an answer in nanoseconds is f.result() * pulse.ns, converted with one multiply by a constant.

  • bounds (tuple[int | Time, int | Time | None] | None) – (lowest, highest), each in clock cycles or a time; highest may be None. A call whose parameter-derived length falls outside them raises ValueError; a length from an answer is rounded and clamped to them. Without bounds the length must not be negative. Scheduling without the length puts the wait at lowest.

Return type:

None

cudaq_pulse.ops.sync(*targets)[source]#

Synchronize multiple lines to a common time point.

All lines are padded to the latest time among them before subsequent operations proceed. When their controllers start operations only every few program cycles, they meet at the next time that is a whole number of every line’s timesteps.

Parameters:

targets (Line) – Two or more drive/readout lines to synchronize.

Return type:

None

Phase and Frequency#

cudaq_pulse.ops.shift_phase(tone, phase)[source]#

Advance a tone’s frame phase: a virtual Z rotation by phase.

Following McKay et al., PRA 96, 022330 (2017), a pulse played after it turns about an axis rotated by -phase.

Example:

@pulse.kernel
def k(qudit):
    drive_line = get_drive_line(qudit)
    shift_phase(drive_line.tone, math.pi / 2)
    drive(drive_line, gaussian(40, 0.3, 10))
Parameters:
  • tone (Tone) – Tone handle, such as line.tone.

  • phase (int | float | Parameter) – Phase increment in radians.

Return type:

Tone

cudaq_pulse.ops.set_phase(tone, phase)[source]#

Set the frame phase of a tone, with the sign of shift_phase.

Example:

@pulse.kernel
def k(qudit):
    drive_line = get_drive_line(qudit)
    set_phase(drive_line.tone, math.pi / 2)
    drive(drive_line, gaussian(40, 0.3, 10))
Parameters:
  • tone (Tone) – Tone handle.

  • phase (int | float | Parameter) – Absolute phase in radians.

Return type:

Tone

cudaq_pulse.ops.shift_frequency(tone, frequency)[source]#

Add a relative frequency offset to a tone.

Example:

@pulse.kernel
def k(qudit):
    drive_line = get_drive_line(qudit)
    shift_frequency(drive_line.tone, 2e6)  # 2 MHz above
    drive(drive_line, gaussian(40, 0.3, 10))
Parameters:
  • tone (Tone) – Tone handle.

  • frequency (int | float | Parameter) – Frequency offset in Hz.

Return type:

Tone

cudaq_pulse.ops.set_frequency(tone, frequency)[source]#

Set the absolute frequency of a tone.

Example:

@pulse.kernel
def k(qudit):
    drive_line = get_drive_line(qudit)
    set_frequency(drive_line.tone, 5.0e9)  # 5 GHz, whatever the tone was at
    drive(drive_line, gaussian(40, 0.3, 10))
Parameters:
  • tone (Tone) – Tone handle.

  • frequency (int | float | Parameter) – Absolute frequency in Hz.

Return type:

Tone

Waveform Constructors#

Four waveforms and the spectra of their samples Four waveforms and the spectra of their samples

square(40, 0.3), gaussian_square(40, 0.3, 4, 20), gaussian(40, 0.3, 10) and cosine(40, 0.3) as sample_waveform samples them at a 2 GHz clock, and the spectrum of those samples relative to its peak. The shaded band holds 99% of the spectrum’s energy up to half the clock. It says where the energy is, not how high the spectrum stays outside it: this gaussian has the narrowest band, but, cut off at its ends, it keeps a skirt that the cosine does not.#

Four waveforms, square(40, 0.3), gaussian_square(40, 0.3, 4, 20), gaussian(40, 0.3, 10) and cosine(40, 0.3), each 20 ns long with amplitude 0.3, above the spectrum of their samples from -60 to 0 dB within 500 MHz of the tone. A shaded band marks where 99% of each spectrum's energy up to half the clock lies: square ±427 MHz, gaussian_square ±105 MHz, gaussian ±59 MHz, cosine ±70 MHz. Outside its band the gaussian's spectrum still peaks at -41 dB between 400 and 500 MHz, and the cosine's is below -60 dB from 332 MHz on.

cudaq_pulse.ops.gaussian(duration, amplitude, sigma)[source]#

Create a Gaussian envelope waveform.

The envelope is amplitude * exp(-(t - duration / 2)**2 / (2 * sigma**2)) at time t from the start of the pulse. It is cut off at the ends of duration, with no offset subtracted: with duration = 4 * sigma it starts and ends at about 14% of amplitude.

Parameters:
  • duration (int | float | Parameter) – Pulse duration: an int number of clock cycles, or a time (20 * pulse.ns).

  • amplitude (int | float | Parameter) – Peak amplitude, with no limit but the controller’s (Controller.max_amplitude).

  • sigma (int | float | Parameter) – Standard deviation in clock cycles, or a time.

Returns:

Waveform value for use with drive() or waveform arithmetic.

Return type:

Waveform

cudaq_pulse.ops.square(duration, amplitude)[source]#

Create a flat-top (square) envelope waveform.

Parameters:
  • duration (int | float | Parameter) – Pulse duration: an int number of clock cycles, or a time (20 * pulse.ns).

  • amplitude (int | float | Parameter | complex | Sequence[float]) – Constant amplitude: a real number, a complex number re + im*1j, or [re, im], with no limit but the controller’s (Controller.max_amplitude).

Returns:

Waveform value.

Return type:

Waveform

cudaq_pulse.ops.drag(duration, amplitude, sigma, beta)[source]#

Create a DRAG (Derivative Removal by Adiabatic Gate) waveform.

The envelope is G(t) + i beta dG/dt with G the Gaussian (Motzoi et al., PRL 103, 110501 (2009)). Leakage to the second excited level of a transmon with anharmonicity alpha is smallest near beta = -1 / alpha, with alpha in radians per clock cycle.

Parameters:
  • duration (int | float | Parameter) – Pulse duration: an int number of clock cycles, or a time (20 * pulse.ns).

  • amplitude (int | float | Parameter) – Peak amplitude, with no limit but the controller’s (Controller.max_amplitude).

  • sigma (int | float | Parameter) – Gaussian standard deviation in clock cycles, or a time.

  • beta (int | float | Parameter) – DRAG coefficient in clock cycles, or a time.

Returns:

Waveform value.

Return type:

Waveform

cudaq_pulse.ops.cosine(duration, amplitude)[source]#

Create a raised-cosine envelope waveform.

The envelope is amplitude * (1 - cos(2 * pi * t / duration)) / 2 at time t from the start of the pulse. It starts at 0, peaks at amplitude in the middle, and returns to 0 at the end.

Parameters:
  • duration (int | float | Parameter) – Pulse duration: an int number of clock cycles, or a time (20 * pulse.ns).

  • amplitude (int | float | Parameter) – Peak amplitude, with no limit but the controller’s (Controller.max_amplitude).

Returns:

Waveform value.

Return type:

Waveform

cudaq_pulse.ops.tanh_ramp(duration, amplitude, sigma)[source]#

Create a hyperbolic-tangent ramp waveform.

The envelope is amplitude * (1 + tanh((t - duration / 2) / sigma)) / 2 at time t from the start of the pulse. It passes amplitude / 2 at the midpoint t = duration / 2, rising from amplitude * (1 - tanh(duration / (2 * sigma))) / 2 at the start to amplitude * (1 + tanh(duration / (2 * sigma))) / 2 at the end: with duration = 4 * sigma, about 2% and 98% of amplitude.

Parameters:
  • duration (int | float | Parameter) – Pulse duration: an int number of clock cycles, or a time (20 * pulse.ns).

  • amplitude (int | float | Parameter) – Peak amplitude, with no limit but the controller’s (Controller.max_amplitude).

  • sigma (int | float | Parameter) – Rise/fall steepness in clock cycles, or a time.

Returns:

Waveform value.

Return type:

Waveform

cudaq_pulse.ops.gaussian_square(duration, amplitude, sigma, width)[source]#

Create a Gaussian-square (flat-top Gaussian) waveform.

A square pulse with Gaussian rise and fall edges.

The envelope is a Gaussian rise, a flat top of width, and a Gaussian fall. With edge = (duration - width) / 2 the length of each edge, it is amplitude * exp(-(t - edge)**2 / (2 * sigma**2)) for t < edge, amplitude for edge <= t < duration - edge, and amplitude * exp(-(t - (duration - edge))**2 / (2 * sigma**2)) after that. It starts and ends at amplitude * exp(-edge**2 / (2 * sigma**2)).

Parameters:
  • duration (int | float | Parameter) – Total pulse duration: an int number of clock cycles, or a time (20 * pulse.ns).

  • amplitude (int | float | Parameter) – Peak amplitude, with no limit but the controller’s (Controller.max_amplitude).

  • sigma (int | float | Parameter) – Gaussian edge standard deviation in clock cycles, or a time.

  • width (int | float | Parameter) – Flat-top width: an int number of clock cycles, or a time.

Returns:

Waveform value.

Return type:

Waveform

cudaq_pulse.ops.custom(duration, envelope_fn)[source]#

Create a waveform by sampling a Python function while the kernel is traced.

envelope_fn is called once per sample of the lines it plays on, at the middle of each: t = 0.5, 1.5, ..., duration - 0.5, in clock cycles from the start of the pulse, when a line plays one sample per clock cycle. A controller with its own clock or several samples per cycle plays at its own rate, and the envelope is sampled at that rate instead (every 2 clock cycles at half the clock: t = 1, 3, ...). Each value is held until the next, like custom_samples of the values (which is what the kernel’s IR records), so the waveform compiles, schedules and simulates like the built-in envelopes. A function that matches a built-in envelope, such as lambda t: a * math.exp(-((t - duration / 2) ** 2) / (2 * sigma**2)) for gaussian(duration, a, sigma), gives the same waveform up to that sampling.

The duration must be known while tracing (an int or a time, as an argument or a constant) and at most 252 samples (250 at a controller’s own rate); play a longer envelope as consecutive drives. The function must return real numbers that do not depend on kernel parameters: scale the waveform by a parameter with wf_scale(custom(duration, f), amplitude). Define the function outside the kernel: a lambda or def in a kernel body raises CompilationError.

Parameters:
  • duration (int | Time) – Pulse duration: an int number of clock cycles, or a time (20 * pulse.ns).

  • envelope_fn (Callable[[float], float]) – A function f(t) -> float of the time in clock cycles.

Returns:

Waveform value.

Return type:

Waveform

cudaq_pulse.ops.custom_samples(samples, sample_rate_ghz=None)[source]#

Create a waveform from pre-computed sample data.

Each sample is held until the next. The samples are made for one rate, and play only on lines at that rate: by default one per clock cycle of the quantum system (QuantumSystem.clock_ghz), or sample_rate_ghz. A line plays its controller’s rate, its sample_rate_ghz; samples made for another rate are a CompilationError, never a change in how long they last. Resample them for the line, or use custom, which samples at the line’s rate.

Parameters:
  • samples (Sequence[float]) – Non-empty array-like of real envelope sample values.

  • sample_rate_ghz (float | None) – The rate the samples were made for, in GHz; they must last a whole number of clock cycles.

Returns:

Waveform value.

Return type:

Waveform

Waveform Arithmetic#

cudaq_pulse.ops.wf_add(left, right)[source]#

Add two waveforms element-wise.

Parameters:
  • left (Waveform) – First waveform.

  • right (Waveform) – Second waveform (must have same duration as left).

Returns:

Combined waveform left + right.

Return type:

Waveform

cudaq_pulse.ops.wf_sub(left, right)[source]#

Subtract two waveforms element-wise.

Parameters:
  • left (Waveform) – First waveform.

  • right (Waveform) – Second waveform.

Returns:

Difference waveform left - right.

Return type:

Waveform

cudaq_pulse.ops.wf_mul(left, right)[source]#

Multiply two waveforms element-wise.

Parameters:
  • left (Waveform) – First waveform.

  • right (Waveform) – Second waveform.

Returns:

Product waveform left * right.

Return type:

Waveform

cudaq_pulse.ops.wf_scale(waveform, scalar, /)[source]#

Scale a waveform by a constant factor.

Parameters:
  • waveform (Waveform) – Waveform to scale.

  • scalar (int | float | Parameter) – Real scaling factor.

Returns:

Scaled waveform scalar * waveform.

Return type:

Waveform

cudaq_pulse.ops.wf_neg(waveform)[source]#

Negate a waveform (flip sign of all samples).

Parameters:

waveform (Waveform) – Waveform to negate.

Returns:

Negated waveform -waveform.

Return type:

Waveform