Part E · Lesson 2

System calls

A fault-tolerant program asks for services: measure this, decode that, update the frame. A virtual machine charges each request one latency and one share of a service. This lesson runs such a program on the controller model and measures what each call actually costs.

Read lesson E1 first: this lesson reuses its feedback path. The background chapter on measurement, feedback and decoding explains syndromes and the Pauli frame.

1The virtual machine and its calls

How does a program for a million-qubit computer ask for a decoder?

The companion paper of this project describes a fault-tolerant quantum virtual machine, the FTQVM. A program never names a physical path or a pulse. It names qubit addresses and record bits, and obtains every shared resource through a system call: request_ancilla, route, measure, decode_syndrome, pauli_frame_update, request_magic and a few more. A machine is a declaration: for every call, how long it takes and how much of each shared service it holds. The paper puts the division of labor in one line: the program declares when, the machine declares how long, and the VM checks.

A call that moves N items (bits or qubits) in D nanoseconds holds a rate on the service that carries them for its whole interval:

r(N, D) = ⌈1000 · N / D⌉ items per µs

Concurrent calls add their rates, and the sum must stay below the service's capacity at every instant. A measurement holds r(1, λm) of the classical link, a decode holds the rate of its input bits, and a frame update a rate for the bits it reads. A decode of n bits also holds one decoder for its latency λd(n); if the rate r(n, λd(n)) exceeds what the link or the decoder's input can take, it gets an input phase of ⌈1000 n / cap⌉ ns first. In the paper's text form a decode reads syndrome[s] -> decode_syndrome rounds=1 and a frame update c[i] -> pauli_frame_update X data[1].

Those latencies are declared, not measured. The question this lesson starts to answer is whether one latency and one capacity are a fair summary of what a real control system does when it serves the call.

2Four calls on the transmon ring

In this section: the JSON form of a call program, which calls the ring realizes, and which it refuses.

The eight-transmon ring accepts a program of kind "ftqvm-calls", a list of calls on physical qubits. The scheduler is scheduleCalls in riscq/platforms/superconducting.mjs. Four calls have a realization:

CallJSONRealized as
gate{ call: "gate", name, qubits, when? }Calibrated pulses, as in lesson C1. With when it runs only if that bit is 1.
measure{ call: "measure", qubit, bit }A readout tone and a demodulation window; the bit is published through the hub.
decode_syndrome{ call: "decode_syndrome", bits, lut, into }A table lookup on a decoder core. lut[s] is the correction word for syndrome s, and bit j of it becomes into[j].
pauli_frame_update{ call: "pauli_frame_update", when, pauli, qubit }If when is 1, flip bits of the qubit's frame word: X = 1, Z = 2, Y = 3. No pulse is played.

For these calls the build gets a ninth RISC-Q core, named decoder. It drives no qubit. RISC-Q requires every core to have a channel, so it carries one digital channel that it never uses. It keeps the Pauli frame of every qubit as a word in its RAM and reports each new frame word to the host.

Three calls are refused with an error: request_ancilla, route and request_magic. The reasons are physical. Preparing a fresh ancilla needs a reset, and the calibration of this ring has no reset pulse. A route brings qubits together, and the couplers of a transmon ring are fixed. A magic state needs a factory, and an eight-qubit ring has none. The checker also refuses programs that break the virtual machine's rules for records: a decode must read bits that were measured, and the bits it writes need new names, because every record is written once.

Why does the ring refuse request_ancilla?

  1. All eight qubits are data qubits.
  2. Its calibration has no reset pulse to prepare a fresh ancilla in |0⟩.
  3. The decoder core has no free memory.
  4. Ancillas exist only on trapped-ion machines.
An ancilla request hands out qubits in |0⟩. On hardware that means an active reset, a pulse sequence conditioned on a measurement, or waiting several T1 times. RISC-Q's example calibration lists drive, CZ and readout pulses only. Realizing request_ancilla as an active reset is the first item on the project's list of next steps.

3A repetition-code round

In this section: the example program, what each call is for, and how the compiler splits it into segments.

The example superconducting-repetition is one round of a three-qubit bit-flip code. Qubits 0, 2 and 4 hold data. Qubits 1 and 3 are ancillas: two CNOTs copy the parity of qubits 0 and 2 onto qubit 1, two more the parity of 2 and 4 onto qubit 3. Measuring the ancillas gives two syndrome bits, s0 and s1.

{ "call": "gate", "name": "cx", "qubits": [0, 1] }      ... three more CNOTs
{ "call": "measure", "qubit": 1, "bit": "s0" }
{ "call": "measure", "qubit": 3, "bit": "s1" }
{ "call": "decode_syndrome", "bits": ["s0", "s1"],
  "lut": [0, 1, 4, 2], "into": ["e0", "e1", "e2"] }
{ "call": "pauli_frame_update", "when": "e0", "pauli": "X", "qubit": 0 }
{ "call": "pauli_frame_update", "when": "e2", "pauli": "X", "qubit": 4 }
{ "call": "gate", "name": "x", "qubits": [2], "when": "e1" }

The syndrome s = s0 + 2·s1 indexes the table. s = 1 means only the first check fired: qubit 0 flipped, so the word is 0b001 and e0 = 1. s = 2 means qubit 4, word 0b100. s = 3 means both checks fired: qubit 2, word 0b010. This is the decoder of a distance-3 repetition code, written out as a table.

The program corrects two qubits in two different ways on purpose. Errors on qubits 0 and 4 are recorded in the Pauli frame and never played: a later measurement result of that qubit is reinterpreted instead. An error on qubit 2 is corrected with a real x pulse. The first is how error-correcting machines normally work; the second shows the cost of a pulse that waits for a decoder.

Both checks fire: s0 = 1, s1 = 1. What does the round do?

  1. Flips the frame words of qubits 0 and 4.
  2. Nothing: a weight-2 syndrome cannot be decoded.
  3. Decodes e1 = 1 and plays an x pulse on qubit 2.
  4. Plays x pulses on qubits 0, 2 and 4.
lut[3] = 0b010, so only e1 is 1. Both frame updates find their bit at 0 and store nothing; the conditioned x on qubit 2 plays. Run it in the editor below with s0=1, s1=1 and check derived.bits.

Segments: pulses, then classical work, then pulses

The compiler groups the hardware instructions into three segments. The first holds every pulse of the CNOTs and the two readouts. The second is classical: the decode and both frame updates, all on the decoder core, with no span of its own, because the cores may go on as soon as the decoder is done. The third holds the conditioned x. Every segment begins with a barrier of all six active cores.

On the decoder core the decode is a short RV32I sequence (Firmware.decode in riscq/firmware.mjs): load the shared word from the board register, shift and mask the syndrome field, load the correction word from the table in RAM, then for each decoded bit store it, report it to the host and, if a gate on another core depends on it, publish it. A frame update loads the frame word, XORs the mask and stores it back. The compiler places the syndrome bits in consecutive slots of one shared word, so a single load reads the whole syndrome.

4What each call costs

In this section: the decode path from the last window to the conditioned pulse, read from the trace by decodeSamples in riscq/syscalls.mjs.

syndrome → decoder bar. lookup, store pub barrier SYNC_LEAD, 256 ns 086112 176196234 490 ns last syndrome window closes x opens on qubit 2 decoded bit at every core: 196 ns release time of the second barrier: 234 ns
The decode path of the repetition round with both checks fired. Times in ns after the last syndrome window closes, read from the trace. bar.: the barrier before the decode; pub: the decoded bit e1 travels through the hub to every core. Schematic drawing, to scale on the time axis.
MomentnsWhat happens
Syndrome at the decoder86The last syndrome bit is in the decoder's board register: the path of lesson E1.
Decode starts112The six cores have met at the barrier, and the decoder loads the shared word.
Decoded176The last decoded bit is stored. The lookup and stores took 64 ns.
Decoded bit at every core196e1 was published through the hub.
Conditioned pulse opens490After a second barrier and the 128-batch lead.

The decode itself costs 14 ns plus 14 ns per decoded bit in this firmware, and 8 ns more for each decoded bit it publishes: 3 bits and one publish give 14 + 42 + 8 = 64 ns. These are instruction counts under the assumed cost of one batch per instruction plus a penalty per load, store and taken branch. A frame update whose bit is set is stored 22 ns after the decode has finished. The second update of the program, when its bit is set, is stored 16 ns later still, 38 ns after the decode, because the first update's test runs before it.

Compare the conditioned pulse with lesson E1: conditioned directly on a measured bit it opened at 344 ns, conditioned on a decoded bit at 490 ns. The extra 146 ns are one more barrier and the decode. The schedule lead of 256 ns is paid once in each case.

The run with both checks fired, stopped where the decoder core loads the shared word (the syndrome, value 3). Step on to see the host stores of e0, e1, e2 and the publish of e1.

Run the repetition round with s0 = 1 and s1 = 1. How many ns after the last syndrome window closes is the last syndrome bit in the decoder core's board register?

The latest board frame on decoder.inbox caused by a syndrome publish. The path is the one of lesson E1: decoder and report, the measuring core's instructions, the hub and back.

In the same run, how long do the lookup and the stores take, from the decoder's load of the syndrome to its last stored decoded bit?

From the read of the board register to the last host store of the decode: 32 batches, 64 ns, for three decoded bits of which one is published.

Now run it with only s0 = 1. The decoder sets e0, and the frame of qubit 0 is updated. How many ns after the last decoded bit is stored is the new frame word stored?

The frame update runs right after the decode on the same core: load the frame word, XOR, store and report. The answer function reads the host store whose source is the frame update.

5Write your own calls

In this section: an editor that sends a call program to the simulator and shows the costs it measured.

Edit the program and the outcomes, then run it. The page sends { platform: "superconducting", calls, outcomes } to the server, which schedules the calls, compiles firmware for nine cores, executes it in the Lean model and returns the run. The table below is computed from that run the way decodeSamples computes it. Qubits are physical: 0 to 7. CZ is offered between ring neighbours except the pairs (5, 6) and (6, 7), whose CZ needs a pulse on the second excited level. A lookup decode takes 1 to 10 syndrome bits. A conditioned gate may not change a frame, so condition x, not sx or h.

System-call program

The result appears here.

The same program runs from the command line with node riscq/cli.mjs --calls program.json. The workspace opens the built-in example; a custom call program is not yet addressable by URL.

Load a four-bit identity decode: four qubits are measured into s0 to s3 and decoded with lut[s] = s into four bits that no gate uses. Run it. How long does the decode take?

14 ns plus 14 ns for each of the four decoded bits, and nothing is published because no gate reads the decoded bits: 70 ns. The cost grows with the number of decoded bits, not with the size of the table: the lookup is one load whatever the syndrome width.

6From a run to a declaration

In this section: what the measured times mean for the latencies and capacities a machine declares.

The FTQVM declares, among others, decoder_latency_ns, decoder_bandwidth and pauli_frame_update_ns. The run gives candidates for each on this machine, together with what a single number hides:

Declare decode_syndrome on this machine with the latency from the last window close to the last decoded bit stored, read from the run with both checks fired. What rate r(N, D) does a decode of its 2 syndrome bits then reserve on the classical link?

r(2, 176) = ⌈2000 / 176⌉ = 12 bits/µs. The answer function reads the 176 ns from the trace and applies the formula of section 1.
What this does not show. The lookup decoder is a table of 2n words; it is exact for this tiny code and impossible for a surface code of useful size. Lesson E3 runs a real union-find decoder on a control core. Nothing here says anything about gate fidelity: no quantum state is simulated, and the syndrome is the input you type.

What to remember

  1. The FTQVM charges each system call one latency and a rate r(N, D) = ⌈1000 N / D⌉ on a shared service.
  2. The transmon ring realizes gate, measure, decode_syndrome and pauli_frame_update, and refuses ancilla, route and magic requests for physical reasons.
  3. Decoding and frame updates run on a ninth core in a classical segment between two barriers; a frame update plays no pulse.
  4. In the model: syndrome at the decoder after 86 ns, decoded at 176 ns, frame stored 22 ns later, a dependent pulse at 490 ns.
  5. A single declared latency must say which interval it covers; the lookup is a small part of it.