Operations and Waveforms#
All operations listed here are used as bare names inside @pulse.kernel
functions. They are intercepted during bytecode tracing and lowered
to MLIR operations in the Pulse dialect.
Channel Access#
- get_drive_line(qudit) Line#
Obtain the drive line of a qudit. The line is passed to
drive(),wait()andsync(); its tone,line.tone, is passed to the phase and frequency ops, as inshift_phase(line.tone, math.pi). A line is one value: it is not unpacked or iterated.line.tonedrives the qudit’s default transition, which its quantum system’s model declares (levels 0 and 1 unless the model says otherwise).line.tonesmaps each transition the model lists, as a(lower, upper)pair of levels, to its tone, soline.tones[(1, 2)]is the tone of the 1-2 transition; the default transition’s entry isline.toneitself. A transition the model does not list raises aKeyErrorthat names the ones it does. The mapping is read-only.A qudit has one drive line for the whole program. The first call acquires it; every later call, in the kernel or in a kernel it calls, returns the line in its current state. Pulses on it play one after another, and phase and frequency changes carry over:
x90(q); x90(q), wherex90callsget_drive_line(q)itself, plays two pulses in sequence. A loop whose body acquires the line of a qudit that exists before the loop acquires it once, before the loop, and stays rolled.
- get_readout_line(qudit) Line#
Obtain the readout line of a qudit: the same one value per qudit for the whole program, with its tone in
line.tone. A readout line has only its own tone, so itsline.tonesholds that one entry.
Scheduling Operations#
- drive(line, waveform, *, tone=None)#
Play a waveform envelope on a drive line, at the line’s own tone or, given
tone=, at another one, such asdrive(control, cr, tone=target.tone)for a cross-resonance pulse.
- readout(line, waveform, *, tone=None)#
Acquire a measurement through a readout line, at its own tone unless
tone=gives another.
- wait(line, duration, bounds=None)#
Insert an idle delay of duration on a line: an
intnumber of clock cycles or a time, such aswait(line, 10 * pulse.ns)(see Durations: cycles or times). A duration computed fromfloatparameters stays a runtime value, rounded to the nearest cycle on each call; bounds,(lowest, highest)in cycles or as times, limits it. See Wait lengths.
- sync(line1, line2, ...)#
Synchronize two or more lines to a common time point. All lines are padded to the latest time among them.
Phase and Frequency Control#
These operations modify the rotating frame of a tone channel.
- shift_phase(tone, phase)#
Advance the tone’s frame phase by phase (radians): a virtual Z rotation by phase, in the convention of McKay et al., PRA 96, 022330 (2017). A pulse played after it turns about an axis rotated by
-phase, soshift_phase(t, pi / 2)followed by an X90 pulse is an X90 about the -Y axis. It takes no time, andPass.FOLD_PHASESfolds it into the next drive. See Phase frames and virtual Z gates.
- set_phase(tone, phase)#
Set the tone’s frame phase (radians), with the same sign as
shift_phase.
- shift_frequency(tone, frequency)#
Add a relative frequency offset (Hz) to the tone.
- set_frequency(tone, frequency)#
Set the absolute frequency (Hz) of the tone. The phase carries over continuously.
In the qudit’s frame, which rotates at the frequency its 0-1 drive tone
plays at (its dressed_frequency_hz), a tone at
w_tone drives with H = (A/2)(E a^dagger + E^* a) and
E(t) = envelope(t) exp(-i theta(t)), where the frame phase
theta(t) = theta_0 + (w_tone - w_q) t: a tone above the qudit runs ahead of
its frame. The 1-2 transition of a transmon is driven resonantly by a tone at
w_q + alpha.
A frame over three X90 pulses: shift_phase(tone, pi / 2) after the
first, and shift_frequency(tone, 2.5e6) and a 100 ns wait after the
second. A phase shift is a step and a frequency shift a slope; each
pulse takes the phase the frame has when it starts. Dashed blue is a
pulse’s Q quadrature.#
The phase of a drive tone's frame against time, above the three X90 pulses that take it. A shift_phase of π/2 at 40 ns is a step; a shift_frequency of +2.5 MHz at 80 ns makes the phase rise steadily from there. The phase each pulse starts with: 0 for the pulse from 0 ns, π/2 for the pulse from 40 ns, π for the pulse from 180 ns. Each pulse's small Q quadrature is drawn dashed.
Phase frames and virtual Z gates#
A Z rotation needs no pulse: advancing a tone’s frame phase by phi
turns every later pulse at that tone about an axis rotated by -phi,
which is the same as applying Rz(phi) = exp(-i phi Z / 2) to the qudit
before those pulses. The phase gates pulse.gates.Z, S and T are
these virtual Z rotations, by pi, pi / 2 and pi / 4 (each equal to its gate
up to a global phase). get_calibration gives each as a VirtualZ, and
drive(line, it) plays it as shift_phase(line.tone, phase_rad): it
takes no time and adds no error.
import cudaq_pulse as pulse
@pulse.kernel
def t_state(q):
d = get_drive_line(q)
drive(d, d.get_calibration(pulse.gates.Y90)) # |0> to |+>
drive(d, d.get_calibration(pulse.gates.T)) # |+> to |T>, a frame change
The sign convention is that of McKay et al., PRA 96, 022330 (2017): a
positive phase is a positive rotation about +Z, so T takes |+> to
(|0> + e^{i pi/4} |1>) / sqrt(2). There are no inverse gates; a
calibration’s replace gives one, t.replace(phase_rad=-t.phase_rad).
The frame is bookkeeping on the control side, so it changes what later pulses
do, never the state itself. simulate returns the state in the frame: a
virtual Z after the last pulse leaves density_matrix as it was, and the
state in the logical basis is Rz(phi) applied to it, for phi the
phase the qudit’s tone has accumulated. Two consequences:
A readout cannot see a virtual Z played just before it: a Z rotation leaves the populations a readout measures as they were.
A pulse played after it, such as a tomography rotation before a readout, sees the frame and measures the logical state.
A virtual Z shifts the frame of one tone. A pulse played on another line at
that tone, such as a cross-resonance drive at the target’s tone, sees the
shift; a pulse at another tone, such as the 1-2 tone, does not. A phase gate
of another transition, get_calibration(pulse.gates.S, transition=(1, 2)),
is played at that tone: drive(d, s12, tone=d.tones[(1, 2)]).
Waveform Constructors#
Each constructor returns a waveform value that can be passed to
drive() or combined with waveform arithmetic. A duration or width is
an int number of clock cycles or a time such as 20 * pulse.ns;
sigma and beta take clock cycles, fractional too, or times. See
Durations: cycles or times.
Function |
Description |
|---|---|
Gaussian envelope with standard deviation sigma:
|
|
Constant-amplitude (flat-top) envelope |
|
DRAG pulse for leakage suppression: |
|
Raised-cosine envelope:
|
|
Hyperbolic tangent ramp:
|
|
Flat-top pulse with Gaussian rise/fall edges: with
|
|
A Python function |
|
Waveform from a non-empty sequence of at most 252 real-valued samples,
made for one sample per clock cycle or for |
For gaussian_square, width is the flat-top width;
duration - width must be a positive even number of clock cycles so the
two edges have the same integer duration.
Waveform explorer
Pick a waveform and move its sliders or type a value; the line under the plot is the call that makes it. combine applies the waveform arithmetic below to a second waveform, and modulate shows the drive in the qudit’s frame (see Frames and signs).
I (solid) and Q (dashed) of each parametric waveform, 40 clock cycles
(20 ns) long, as sample_waveform samples them. With JavaScript on,
the explorer replaces this figure.#
custom(duration, f) calls f once per sample of the lines it plays on
while the kernel is traced, at the middle of each sample, and holds each
value until the next: the IR records the custom_samples of those values,
so a custom envelope compiles, schedules and simulates on the CPU and the
GPU like the built-in ones. On the program clock that is once per clock
cycle (t = 0.5, 1.5, ..., duration - 0.5); a controller with its own
clock, or several samples per cycle, plays at its own rate, and f is
sampled at that rate (at half the clock, t = 1, 3, ...). Built-in
envelopes are evaluated continuously, so a function that reproduces one,
such as a Gaussian for gaussian, matches it up to that sampling. f
must be defined outside the kernel and return real numbers that do not
depend on kernel parameters; scale the waveform by a parameter with
wf_scale(custom(duration, f), amplitude). The duration must be known
while tracing and at most 252 samples (250 at a controller’s own rate), the
length of one sample record; play a longer envelope as consecutive drives.
A custom_samples array is made for one rate and plays only at that
rate: one sample per clock cycle, or sample_rate_ghz. On lines whose
controller plays another rate (its sample_rate_ghz)
it is a compile error, never a pulse that lasts longer or shorter than the
samples were made for; resample the array for the line and pass its rate,
or use custom:
@pulse.kernel
def raw(q):
d = get_drive_line(q)
# 1 GHz samples, for a controller at half of a 2 GHz program clock:
# 8 samples last 16 clock cycles.
drive(d, custom_samples(samples_1ghz, sample_rate_ghz=1.0))
Waveform Arithmetic#
Waveforms can be combined algebraically inside kernels:
import cudaq_pulse as pulse
@pulse.kernel
def combined_waveform(qubit, duration):
drive_line = get_drive_line(qubit)
wide_sigma = 8 * pulse.ns
narrow_sigma = 5 * pulse.ns
envelope_a = gaussian(duration, 0.5, wide_sigma)
envelope_b = gaussian(duration, 0.3, narrow_sigma)
combined = wf_add(envelope_a, envelope_b)
scaled = wf_scale(envelope_a, 0.5)
inverted = wf_neg(envelope_a)
Function |
Operation |
|---|---|
|
|
|
|
|
|
|
|
|
The operands of wf_add, wf_sub and wf_mul must have the same
duration; a mismatch is a compile error. For simulation and execution, a
sum, difference, scaling or negation lowers exactly: the drive Hamiltonian
is linear in the envelope, so each term plays as its own envelope. A
product is not linear and is sampled once per clock cycle into
piecewise-constant samples, as custom_samples would be.