Measuring Streaming Interleaved Feed-forward Latency (SIFL) =========================================================== This experiment shows how waiting for a decoder's correction can increase the work in the next shot. Two decoder instances alternate surface-code memory shots. While one shot is being decoded, the next collects measurement rounds until the previous correction arrives or a round cap is reached. The script varies the interval between rounds and reports the resulting shot lengths and decoding response times. Use it to investigate the connection between measurement cadence, feedback waiting, and decoder backlog. A longer wait can produce a larger shot, which can take longer to decode in turn. Increasing the interval between rounds gives the decoder more time to finish before further measurements arrive. The default configuration uses PyMatching on the CPU, with measurements generated by Stim and sent by the :doc:`Playback Emulator `. Prerequisites ------------- * A CUDA-Q QEC installation built with CUDA-Q realtime support, including the Python playback interface (``cudaq_qec.playback``), development headers, ``libcudaq-qec-decoders``, and the PyMatching decoder plugin. * ``python3`` with ``cudaq_qec``, ``numpy``, and ``stim`` importable, plus ``g++`` with C++17 support and Bash to build and run the example plugin. * A writable example directory. The runner creates ``libper_round_decoder.so`` beside the source files and removes that generated plugin when it exits. The default PyMatching experiment runs in process and needs no decoding server, GPU, QPU, or FPGA. The 0.9.0 pip wheels do not include the Python playback interface. Use a realtime-enabled installation and ensure its headers and libraries match; see `Building CUDA-Q QEC from Source `__ if you need to prepare that environment. Run the Experiment ------------------ Use the directory ``docs/sphinx/examples/qec/sifl_demo/`` in your CUDA-Q QEC checkout, or download these three files into one directory: .. list-table:: :header-rows: 1 :widths: 45 55 * - File - Purpose * - :download:`run_sifl_demo.sh <../../examples/qec/sifl_demo/run_sifl_demo.sh>` - Builds the plugin and runs the experiment with the supplied options. * - :download:`sifl_demo.py <../../examples/qec/sifl_demo/sifl_demo.py>` - Prepares detector error models, runs the playback schedules, and prints results. * - :download:`per_round_decoder.cpp <../../examples/qec/sifl_demo/per_round_decoder.cpp>` - Buffers each shot and selects a sub-decoder for its final round count. With the installation's Python and library environment set up, start with a small run from that directory: .. code-block:: bash bash run_sifl_demo.sh --distance 3 --shots 6 \ --init-rounds 3 --max-rounds 12 --cadences 2 20 100 This runs six shots at each of three requested round periods: 2, 20, and 100 microseconds. Expect one result line per period, each with six shot lengths. The first shot has three rounds; subsequent shots have between one and nine rounds, where nine is ``max-rounds - init-rounds``. For the default experiment, run: .. code-block:: bash bash run_sifl_demo.sh The defaults are distance 5, physical error probability ``0.01``, 30 shots per cadence, ten rounds in the first shot, and round periods of 2, 5, 10, 20, and 50 microseconds. ``--max-rounds`` defaults to 60, giving subsequent shots a cap of 50 rounds. ``bash run_sifl_demo.sh --help`` lists the options; ``--decoder`` selects the sub-decoder, with ``pymatching`` as the default. How the Example Runs -------------------- The Python script generates a detector error model for each possible shot length. The C++ plugin prepares a sub-decoder from each detector error model and warms it up before the timed runs. For an incoming shot, it buffers the measurement rounds, then selects the matching sub-decoder when the final data readout arrives. Decoding happens at that point, rather than incrementally as each round is enqueued. The playback schedule sends one stabilizer round every requested :math:`T` microseconds. After the first shot, a completion signal from the previous shot's correction ends the current stream, subject to the minimum of one round and the configured cap. The two decoder instances exchange roles on each shot. This models a timing dependency; the returned correction bits do not change the next circuit's operations. Reading the Output ------------------ The script prints two quantities for each cadence: * **Decode time per round:** Sum the intervals from dispatching each shot's final data readout to receiving its correction, then divide by the total stabilizer rounds streamed. The intervals include decoder and request-handling time, but exclude preparation of the final readout and the earlier streaming of measurement rounds. This is a normalized response time, not the total experiment runtime divided by its rounds. * **Rounds streamed per shot:** The length of each shot in stabilizer rounds, excluding its final data readout. Read the sequence to see whether shots become longer, remain short, or repeatedly reach the cap. The following illustrative output uses the default first-shot length and round cap; the lists are shortened for display. Timings and shot lengths vary with the decoder, host, workload, and scheduling: .. code-block:: text Decode time per round and rounds streamed per shot (stream cap 50): T = 2 us decode time per round 7.17 us [10, 50, 50, 50, 50, 50, 50, ...] T = 10 us decode time per round 9.87 us [10, 16, 13, 12, 18, 12, 16, ...] T = 50 us decode time per round 12.84 us [10, 3, 2, 2, 2, 1, 2, ...] Here, the 2-microsecond cadence repeatedly reaches the cap, while the 50-microsecond cadence leaves more time for corrections to return between measurement rounds. A cap of 50 limits what can be observed: reaching it is not evidence of an unlimited shot length. Likewise, a short run with small shots does not establish a latency guarantee. Host scheduling, measurement generation, and decoding all affect the results. The requested round cadence does not guarantee that the emulator dispatches each round on time. Consider the shot-length sequence alongside the reported average when comparing configurations under the same conditions. The script checks that correction requests complete, but supplies no expected logical values and does not measure logical error rate. For timing details behind the averages, the Python playback result contains per-request dispatch and reply timestamps; see the :ref:`Playback Emulator output format `. The Example Source ------------------ .. literalinclude:: ../../examples/qec/sifl_demo/sifl_demo.py :language: python :start-after: [Begin Documentation] :end-before: [End Documentation] See Also -------- * :doc:`Realtime Decoding with the Playback Emulator ` -- simpler in-process and server examples * :doc:`Experiments and Noise Modeling ` -- experiments for logical accuracy under noise * :doc:`Performance Studies ` -- decoder performance under specified workloads