Choose a Schedule#
Scheduling gives every pulse, readout and wait of a kernel its start time. This page shows the scheduling policies, what each does to the same kernel, and how to read the result. It is for anyone who needs to know when each operation starts: the start cycles are what the control electronics receive.
What scheduling decides#
A kernel says which operations play on which lines and in what order. It
does not say when. The scheduler gives every timed operation (a drive, a
readout, a wait) a start and a length, both whole numbers of cycles of the
program clock, QuantumSystem.clock_ghz. transmon_surface17 runs a
2 GHz clock, so one of its cycles is 0.5 ns.
Every schedule keeps what the hardware and the kernel fix:
operations on one line play one after the other, in the order the kernel gives them, and so do pulses that share a tone;
the lines of a
syncare lined up: what follows it on any of them starts after everything before it on all of them has ended;an operation that depends on a readout’s outcome starts no sooner than the feedback latency of the controller that read it, counted from the end of the readout;
under the resource-constrained policies, no more drives and readouts play at once than the control system has lanes for.
What is left open is where the idle time goes: a line that is ready before the others can play at once and then wait, or wait and then play. The policy decides that.
The start cycles are final. A controller backend places every event at the start it is given, and the simulator plays the pulses at the same cycles.
The policies#
schedule= takes one of four names, which are three kinds of policy:
|
Kind |
When an operation starts |
|---|---|---|
|
as early as possible |
as soon as its line and what it depends on are ready |
|
as late as possible |
as late as what follows it allows |
|
resource-constrained |
as early as possible once a lane is free for it |
|
resource-constrained, as late as possible |
as late as possible on a lane that is free for it |
pulse.compile(kernel, schedule=...) sets the policy of a program.
Without it, the program uses the schedule= its kernel was declared
with, else "alap". Any other name is an InvalidValueError (a
ValueError) that lists the four and names the closest.
Each policy below is shown on the same kernel in the figure of the next section.
As early as possible: "asap"#
- What it does
Every operation starts as soon as its line is free and everything it depends on has ended. A line that has less to do than the others plays first and idles afterwards, until the next
sync.- When to choose it
When idle time should come after the pulses: a layer of pulses that must all start together (see Schedules inside schedules), or a comparison with the default.
- In the figure
The first timeline: all three lines start at 0 ns.
As late as possible: "alap"#
- What it does
Every operation starts as late as the operations after it allow. A line that has less to do than the others idles first and plays right before the next
sync. The program is as long as under"asap".- When to choose it
By default. A qudit that is prepared right before it is used or measured has less time to decay, as the second example shows.
- In the figure
The second timeline: D1’s pulse and D2’s two pulses end together with D3’s long pulse, at the
sync.
Resource-constrained: "rcp"#
- What it does
Operations are placed in program order, each as early as its line, what it depends on and a free lane allow. At most
max_concurrent_drivesdrives andmax_concurrent_readoutsreadouts of theControlSystemplay at once. A later operation is never moved ahead of an earlier one to fill a lane.- When to choose it
When the control electronics play fewer pulses at once than the kernel asks for, and the compiler should spread them out.
- In the figure
The third timeline: two drive lanes, so D3’s long pulse waits until D1’s pulse has ended, and the program is 40 ns longer.
Resource-constrained, as late as possible: "alap_rcp"#
- What it does
The same limits as
"rcp", with lanes handed out from the end of the program in reverse program order: each operation starts as late as its line, what follows it and a free lane allow.- When to choose it
When the lanes are limited and qudits should be prepared late.
- In the figure
The fourth timeline: as long as
"rcp", with D2’s two pulses moved to the end and D1’s pulse in the lane that is free before them.
One kernel under each policy#
The kernel plays one calibrated π pulse on D1, two on D2 and one long
Gaussian pulse on D3. A sync then lines the three up, D3 is read out,
and a π pulse flips it back if it read 1. The long pulse’s values are
kernel arguments:
import cudaq_pulse as pulse
system = pulse.quantum_system("transmon_surface17")
d1, d2, d3 = system.qudit("D1"), system.qudit("D2"), system.qudit("D3")
@pulse.kernel
def prepare_and_reset(a, b, c, long_duration, long_amplitude, long_sigma):
drive_a = get_drive_line(a)
drive_b = get_drive_line(b)
drive_c = get_drive_line(c)
readout_c = get_readout_line(c)
flip_b = drive_b.get_calibration(pulse.gates.X)
drive(drive_a, drive_a.get_calibration(pulse.gates.X))
drive(drive_b, flip_b)
drive(drive_b, flip_b)
drive(drive_c, gaussian(long_duration, long_amplitude, long_sigma))
sync(drive_a, drive_b, drive_c, readout_c)
outcome = readout(readout_c, readout_c.get_calibration(pulse.gates.READOUT))
sync(drive_c, readout_c)
if outcome:
drive(drive_c, drive_c.get_calibration(pulse.gates.X))
arguments = (d1, d2, d3, 120 * pulse.ns, 0.1, 30 * pulse.ns)
Compile it under each policy for a control system with two drive lanes,
and print each program’s length and the start cycle of every operation.
event.line numbers the kernel’s lines in the order it takes them: 0, 1
and 2 are the drive lines of D1, D2 and D3, and 3 is D3’s readout line.
D3’s drive line has two starts, the long pulse and the conditional pulse.
policies = ("asap", "alap", "rcp", "alap_rcp")
def starts(program, line):
"""The start cycles of the operations on one line, as text."""
return ", ".join(str(event.start) for event in program.schedule if event.line == line)
def compare(control_system):
print("asked placed as length D1 drive D2 drive D3 drive D3 readout")
for policy in policies:
compiled = pulse.compile(
prepare_and_reset,
quantum_system=system,
control_system=control_system,
schedule=policy,
)
program = compiled.lower(*arguments)
print(
f"{policy:9} {program.options.schedule:9} {str(program.duration):>7}"
f" {starts(program, 0):8} {starts(program, 1):8}"
f" {starts(program, 2):9} {starts(program, 3)}"
)
two_lanes = pulse.ControlSystem(max_concurrent_drives=2)
compare(two_lanes)
Output
asked placed as length D1 drive D2 drive D3 drive D3 readout
asap asap 460 ns 0 0, 80 0, 840 240
alap alap 460 ns 160 80, 160 0, 840 240
rcp rcp 500 ns 0 0, 80 80, 920 320
alap_rcp alap_rcp 500 ns 80 160, 240 80, 920 320
prepare_and_reset under the four policies, for two drive lanes, on
one time axis in nanoseconds (one nanosecond is two cycles). The last
pulse on D3’s drive line, drawn with a dashed outline, plays only if
the readout read 1. Dashed blue is a pulse’s Q quadrature.#
Four timelines of prepare_and_reset on the drive lines of D1, D2 and D3 and on D3's readout line: one pi pulse on D1, two on D2 and a Gaussian pulse of 120 ns on D3, then a sync, a readout of D3 and a pi pulse on D3 that plays only if the readout read 1. asap: D1 at 0 ns, D2 at 0 and 40 ns, D3 at 0 ns, readout at 120 ns, conditional pulse at 420 ns, done at 460 ns; alap: D1 at 80 ns, D2 at 40 and 80 ns, D3 at 0 ns, readout at 120 ns, conditional pulse at 420 ns, done at 460 ns; rcp: D1 at 0 ns, D2 at 0 and 40 ns, D3 at 40 ns, readout at 160 ns, conditional pulse at 460 ns, done at 500 ns; alap_rcp: D1 at 40 ns, D2 at 80 and 120 ns, D3 at 40 ns, readout at 160 ns, conditional pulse at 460 ns, done at 500 ns. asap and alap drive 3 lines at once; rcp and alap_rcp never more than 2.
What to notice:
"asap"and"alap"give programs of the same length. Only the pulses on D1 and D2, the lines with less to do, move: to the start, or up to thesync.Both play three drives at once. This control system has no controllers, so it states two lanes and nothing checks them.
"rcp"and"alap_rcp"never play more than two drives at once. D3’s pulse waits for a lane, and everything after thesyncstarts 80 cycles later.The readout and the conditional pulse keep their place after the
syncunder every policy.
A control system with controllers#
Give the control system a controller, here one with 200 cycles (100 ns) of feedback latency, and two things change:
controller = pulse.Controller(feedback_latency_cycles=200)
checked = pulse.ControlSystem(controllers=[controller], max_concurrent_drives=2)
compare(checked)
Output
asked placed as length D1 drive D2 drive D3 drive D3 readout
asap rcp 600 ns 0 0, 80 80, 1120 320
alap alap_rcp 600 ns 80 160, 240 80, 1120 320
rcp rcp 600 ns 0 0, 80 80, 1120 320
alap_rcp alap_rcp 600 ns 80 160, 240 80, 1120 320
What to notice:
Under every policy the conditional pulse now starts 200 cycles after the readout ends: feedback latency is hardware, so every schedule waits it.
The lanes are now checked under every policy.
"asap"and"alap"place this kernel past them, so the compiler places it as"rcp"and as"alap_rcp"would.program.options.schedulenames the policy that placed the program.A program that
"asap"or"alap"places within the lanes keeps its schedule exactly. One that the resource-constrained placement cannot keep within the limits either fails to compile with aControllerLimitError. Thepulse.ControlSystemfield table of Describe Your Control System hasmax_concurrent_drivesandmax_concurrent_readouts, and the paragraph on them in its Clocks section says how they are counted on several controllers and what the error names.
Where the difference matters#
A qudit that waits in its excited state decays. This kernel excites one qudit and reads it out after another qudit has finished a longer sequence, two π pulses with a wait between them:
@pulse.kernel
def excite_and_hold(busy, held, hold):
drive_busy = get_drive_line(busy)
drive_held = get_drive_line(held)
readout_held = get_readout_line(held)
flip_busy = drive_busy.get_calibration(pulse.gates.X)
drive(drive_busy, flip_busy)
wait(drive_busy, hold)
drive(drive_busy, flip_busy)
drive(drive_held, drive_held.get_calibration(pulse.gates.X))
sync(drive_busy, drive_held, readout_held)
readout(readout_held, readout_held.get_calibration(pulse.gates.READOUT))
Compile it with a wait of 1 µs under "asap" and "alap". From each
schedule take the cycles between the end of D2’s pulse and the start of
its readout, and simulate the program for the probability that the readout
gives 1:
for policy in ("asap", "alap"):
compiled = pulse.compile(excite_and_hold, quantum_system=system, schedule=policy)
program = compiled.lower(d1, d2, 1000 * pulse.ns)
flip = next(e for e in program.schedule if e.kind == "drive" and e.line == 1)
measurement = next(e for e in program.schedule if e.kind == "readout")
result = pulse.simulate(program)
reads_1 = sum(b.probability for b in result.branches if b.levels == (1,))
idle = program.exposure[1].idle_cycles
print(
f"{policy}: D2 flipped at cycle {flip.start}, read out {measurement.start - flip.end}"
f" cycles later, reads 1 with probability {reads_1:.3f}; idle {idle} cycles in all"
)
Output
asap: D2 flipped at cycle 0, read out 2080 cycles later, reads 1 with probability 0.952; idle 2080 cycles in all
alap: D2 flipped at cycle 2080, read out 0 cycles later, reads 1 with probability 0.983; idle 2080 cycles in all
excite_and_hold with a 1 µs wait, as early and as late as possible.
The shaded stretch is the time D2 spends excited before its readout.#
Two timelines of excite_and_hold on the drive lines of D1 and D2 and on D2's readout line. In both, D1 plays two pi pulses with a wait of 1000 ns between them and D2 is read out from 1080 ns. As early as possible, D2's pi pulse plays from 0 ns and D2 waits 1040 ns excited, shaded, before its readout, which gives 1 with probability 0.952. As late as possible, the pulse plays from 1040 ns, right before the readout, which gives 1 with probability 0.983.
What to notice:
Both programs are equally long, and D2 idles for 2080 cycles in both.
program.exposurecounts each qudit’s driven, read out and idle cycles, so it gives the same row for the two.What differs is the state D2 idles in. As early as possible it waits all 2080 cycles (1040 ns) in its excited state, and the readout gives 1 about 3% less often; as late as possible it waits in its ground state.
A lane limit costs time in another way: the program gets longer, so every
qudit idles more. Flip six qudits at once for the two drive lanes of
two_lanes:
@pulse.kernel
def flip_all(qudits):
for qudit in qudits:
drive_line = get_drive_line(qudit)
drive(drive_line, drive_line.get_calibration(pulse.gates.X))
six = system.qudits[0:6]
for policy in ("alap", "rcp"):
compiled = pulse.compile(
flip_all, quantum_system=system, control_system=two_lanes, schedule=policy
)
program = compiled.lower(six)
pulse_starts = [event.start for event in program.schedule]
idle = [row.idle_cycles for row in program.exposure]
print(f"{policy}: {program.duration}, starts {pulse_starts}, idle {idle}")
Output
alap: 40 ns, starts [0, 0, 0, 0, 0, 0], idle [0, 0, 0, 0, 0, 0]
rcp: 120 ns, starts [0, 0, 80, 80, 160, 160], idle [160, 160, 160, 160, 160, 160]
Under "rcp" the six pulses play two at a time, the program is three
times as long, and each qudit idles for two thirds of it.
print(program.exposure) gives the full table, with what the idle time
costs at each qudit’s T1 and T2 star.
Compare the policies#
Policy |
Where idle time goes |
What it needs from the control system |
Typical use |
Cost |
|---|---|---|---|---|
|
after a line’s operations, before the next |
nothing |
operations that must start at once; a comparison with |
none |
|
before a line’s operations, after the previous |
nothing |
the default: qudits are prepared right before they are used |
none |
|
after a line’s operations, and wherever an operation waits for a lane |
|
control electronics that play a limited number of pulses at once |
a longer program when the lanes bind |
|
before a line’s operations, and wherever an operation waits for a lane |
the same as |
limited lanes, with qudits prepared late |
a longer program when the lanes bind |
Every policy keeps the order on each line and tone, every sync and the
feedback latency. "rcp" and "alap_rcp" also keep a lane busy for
line_switch_penalty_cycles of the ControlSystem after each
operation.
Under "asap" and "alap" the lanes are checked only when the control
system states them (ControlSystem(max_concurrent_drives=...) or
max_concurrent_readouts=...) and has controllers. A program placed
past them is then placed as "rcp" places it, for "asap", or as
"alap_rcp" does, for "alap", and its options.schedule names
that policy.
Schedules inside schedules#
A kernel declared with @pulse.kernel(schedule="asap") or
schedule="alap" and called from another kernel is scheduled on its own
with that policy, and then placed whole by its caller’s policy. Its
internal timing is the same wherever it is called.
pulse.compile(..., flatten_schedules=True) ignores the policies of the
called kernels and schedules the whole program with one:
@pulse.kernel(schedule="asap")
def start_together(a, b):
drive_a = get_drive_line(a)
drive_b = get_drive_line(b)
flip_b = drive_b.get_calibration(pulse.gates.X)
drive(drive_a, drive_a.get_calibration(pulse.gates.X))
drive(drive_b, flip_b)
drive(drive_b, flip_b)
@pulse.kernel
def caller(a, b):
start_together(a, b)
sync(get_drive_line(a), get_drive_line(b))
for flatten in (False, True):
compiled = pulse.compile(caller, quantum_system=system, flatten_schedules=flatten)
program = compiled.lower(d1, d2)
print(f"flatten_schedules={flatten}: D1's pulse starts at cycle {starts(program, 0)}")
Output
flatten_schedules=False: D1's pulse starts at cycle 0
flatten_schedules=True: D1's pulse starts at cycle 80
caller is scheduled as late as possible. Inside start_together the
two lines still start together; flattened, D1’s pulse moves up to the
sync.
"rcp" and "alap_rcp" apply to a whole program: only
pulse.compile takes them, and a program that calls kernels with their
own schedule= is compiled under them with flatten_schedules=True.
@pulse.kernel(max_duration_cycles=n) makes compiling fail when the
kernel can take more than n cycles. See “Per-kernel schedules” and
“Duration budgets” in Compile and Inspect a Program.
What a control system adds#
A ControlSystem states what the electronics need in time, and the
scheduler keeps to it:
- Feedback latency
Controller(feedback_latency_cycles=...)is the least time from the end of a readout to the start of an operation that depends on its outcome. Every policy waits it. See One QPU, Several Control Systems.- Latency between controllers
When one controller reads a qudit and another plays the pulse that depends on the outcome, the reader’s
peer_latency_cyclesand both controllers’ start uncertainty are added. See One QPU, Several Control Systems and “Clocks” in Describe Your Control System.- Lanes
ControlSystem(max_concurrent_drives=..., max_concurrent_readouts=...)are the most drives and readouts the system plays at once."rcp"and"alap_rcp"place by them; with controllers, they are checked under every policy. See From Kernel to Controller.- Timesteps
A controller with
cycles_per_timestepstarts and ends operations only on its timesteps, and every operation on its lines must start and last whole timesteps.pulse.round_durationrounds a length to them. See “Clocks” in Describe Your Control System.
Read a schedule yourself#
kernel.lower(*arguments) and compiled.lower(*arguments) return the
scheduled program of one call. Its schedule lists the drives, readouts
and waits as ScheduledEvent objects with a kind, a line, the
qudit of that line, and start and end in cycles:
program = prepare_and_reset.lower(*arguments)
print(f"{'kind':8} {'line':>4} {'qudit':>5} {'start':>5} {'end':>5}")
for event in program.schedule:
print(f"{event.kind:8} {event.line:>4} {event.qudit:>5} {event.start:>5} {event.end:>5}")
print("policy:", program.options.schedule)
print("duration:", program.duration)
print("segments:", len(program.segments()))
Output
kind line qudit start end
drive 0 0 160 240
drive 1 1 80 160
drive 1 1 160 240
drive 2 2 0 240
readout 3 2 240 840
drive 2 2 840 920
policy: alap
duration: 460 ns
segments: 1
program.duration is the latest end of the program’s operations, as a
time. program.segments() lists the stretches of the program between
waits whose length is known only when it runs; a program without such
waits has one segment, and all of its start cycles are fixed.
program.timeline() draws the schedule with matplotlib (the [viz]
extra), one row per line:
figure = program.timeline(title="prepare_and_reset, as late as possible")
figure.savefig("prepare_and_reset.svg")
What the control electronics receive#
A controller backend receives every event of the scheduled program with its start and its length in cycles of the program clock. A backend places every event at its start and does not schedule again; see “Exporting a program” in The Program a Backend Reads. On a control system of several controllers, each controller receives the events of its own lines, and a controller that runs its own clock receives them in its own cycles.
From a Kernel to Your Control Electronics follows a program from the kernel to the instruments, and From Kernel to Controller writes a small backend that plays one.
Where to go next#
Compile and Inspect a Program: every option of
pulse.compile, per-kernel schedules, duration budgets and idle replacement.Several Qubits: Registers, Sync and Scheduling:
syncand the two basic policies, step by step.One QPU, Several Control Systems: how feedback latency, several controllers and drive lanes change one program.
MLIR Passes: the schedule passes behind the policies.