Where Timing Is Exact and Where It Can Move#

A compiled program is a schedule: every drive, readout and wait has a start in clock cycles, and a controller places each one there. This page says where that schedule is exact, where a program’s timing can move while it runs, which lines move together when it does, and how to read all of it from a compiled program.

The four places a time is not a constant#

A kernel can give a time that is not a number written in its source in four ways. Two leave the schedule exact, and two do not.

What the kernel writes

Lines exact relative to each other

Exact against the clock

Can timing move?

wait(line, tau * pulse.ns) with tau a float argument

yes

yes, once a call gives tau

no

f.submit(...).result(), or result(timeout=...)

yes

yes: the schedule reserves the longest the answer may take

no

wait(line, answer * pulse.ns, bounds=...) with answer taken from a classical call

the lines the wait holds back, among themselves

no: what follows starts later, within the bounds

yes

f.submit(...).result() of a function declared with latency_mode="blocking"

the lines the answer holds back, among themselves

no: what follows starts when the answer arrives

yes

A length a call binds. A wait whose length is computed from float arguments is fixed for each call of the compiled kernel: the call rounds the length to whole cycles, checks it against the wait’s bounds if it has any, and schedules with it. The program a controller gets has a wait of one length.

An answer taken by its budget. The schedule places the answer of a classical call after the function’s max_latency_ns, the time its request holds its link and the link’s feedback time, and with result(timeout=...) after the timeout. That is the time the electronics need, stated by the function and the link, and it is part of the schedule: nothing moves when the answer comes earlier. ScheduledKernel.classical_report() gives it for every call (see Call Classical Code During a Shot).

A wait whose length is an answer. The length is known only when the program runs. The schedule places the wait at its lowest length, and what follows on the lines it holds back starts later by the rest, up to the highest length of its bounds.

An answer waited for as long as it takes. A function declared with latency_mode="blocking" has no latest time: the lines that wait for its answer stop until it arrives.

Lines move together when they are synced#

A point where timing can move holds back the lines that wait for it: the line of the wait, the lines whose pulses use the answer, and every line tied to them by a sync, a measurement or an answer used on both, a branch, or a tone or value carried between them. Those lines sync before the point and move together after it, so they stay exact relative to each other.

A line that nothing ties to them keeps the time it is scheduled at. Its pulses do not move with the wait, also where the kernel writes them after it:

@pulse.kernel
def follow(a, b):
    drive_a = get_drive_line(a)
    drive_b = get_drive_line(b)
    readout_b = get_readout_line(b)
    outcome = readout(readout_b, square(400 * pulse.ns, 0.05))
    gap = next_gap.submit([outcome]).result()
    wait(drive_b, gap * pulse.ns, bounds=(20 * pulse.ns, 100 * pulse.ns))
    drive(drive_b, square(40 * pulse.ns, 0.2))
    sync(drive_a, drive_b)       # drive_a waits with drive_b
    drive(drive_a, square(20 * pulse.ns, 0.2))

With the sync, the last pulse on drive_a starts when the pulse on drive_b ends, however long the wait was. Without it, drive_a is not tied to the wait, and its pulse plays when the schedule places it, whatever the wait takes. sync is how a kernel says that lines are timed together, across such a point as anywhere else.

Reading it from a compiled program#

ScheduledKernel.timing says it in one place. A program whose timing cannot move is exact; one with a point where it can is elastic, and each such point is a break:

scheduled = pulse.compile(follow, control_system=control_system).lower(q0, q1)
print(scheduled)
print(scheduled.timing)

Output

<ScheduledKernel 13 ops on transmon_surface17>
elastic: timing can move at 1 point; exact up to cycle 1224
  follow.py:18  wait on q1.drive, its length an answer of next_gap (40 to 200 cycles)
      what follows starts 0 to 160 cycles later
      held back, moving together: q0.drive, q1.drive, q1.readout
latest end: cycle 1544
reserved for answers, part of the schedule:
  next_gap: 424 cycles from submit to answer

There is one row per kernel line, however often the line runs: a wait in a loop of a thousand rounds is one row that says so (1000 times:), and reading the report does not walk the rounds. A line that has operations after the break and is not held is listed as not held, keeping their scheduled time: if its pulses should follow the wait, sync it with a held line. latest end is the latest any line can end: its end as scheduled and what the breaks that hold it back add, each as often as it runs. The last part is the time the schedule reserves for each classical function’s answers, from a submission’s start to when its answer is due, which is exact.

The same as data: timing.exact, timing.breaks (a TimingBreak per row, with source_file, source_line, cause, function, bounds_cycles, shift_cycles, held_lines, free_lines, trips and first_cycles), timing.lines (the program’s lines as (role, qudit), which the line numbers above count; also for a program that calls no classical function), timing.reserved and timing.latest_end_cycles (None when a break has no limit); see Compilation API. The kernel line of an answer waited for as long as it takes is not recorded: its row names the function, and the answers of one function on one link that hold the same lines are one row, which counts them all. A loop that runs no round has no row.

ScheduledKernel.segments() lists the segments of a program, once for each time a break runs. A program whose timing cannot move has one. Each wait whose length is an answer, and each answer waited for as long as it takes, ends a segment of the lines it holds back and starts the next:

scheduled = pulse.compile(follow, control_system=control_system).lower(q0, q1)
for segment in scheduled.segments():
    print(segment.index, segment.opened_by, segment.start_cycles,
          segment.min_shift_cycles, segment.max_shift_cycles)

start_cycles is the segment’s start as scheduled, and at run time it starts between min_shift_cycles and max_shift_cycles later (None: no limit). The export for a controller gives each event its segment, the wait its min_cycles and max_cycles, and an answer its wait: "bounded", "timeout" or "blocking" (see The Program a Backend Reads).

Where such a point cannot be#

Some places need a length that is fixed when the program compiles. There, compiling fails with a CompilationError:

  • inside one arm of a branch on a measurement or an answer: wait after the branch, and let the answer be 0 where no wait is wanted;

  • inside a kernel called with its own schedule=, whose length is fixed: move the wait out of it, or return the future and take the answer after the kernel returns;

  • without a highest length (bounds=(lowest, None), or no bounds), or as an answer waited for as long as it takes, inside a kernel with max_duration_cycles or on a controller with max_program_duration.

In the first two places the error names the kernel line of the wait, or the function whose answer is waited for. Under a longest duration it names the line of a wait without a highest length; of an answer waited for as long as it takes it says that the kernel waits for one, without its line or its function. The check of a branch’s arms is the verify pass’s, so a compile with passes=() does not make it.

A controller that cannot time a wait at all states so in its supports (see Describe Your Control System); the "wait" capability covers every wait, of a fixed length or not.