Skip to content

Commit b2e47f9

Browse files
committed
comments from Melody TODO: new followup PR, code examples
Signed-off-by: Kevin Mato <[email protected]>
1 parent a280c12 commit b2e47f9

File tree

2 files changed

+43
-96
lines changed

2 files changed

+43
-96
lines changed

docs/sphinx/components/qec/introduction.rst

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,30 @@ The decoder returns the probability that the logical observable has flipped for
768768
CUDA-Q 0.5.0 is released.
769769

770770

771+
Real-Time Decoding
772+
------------------
773+
774+
CUDA-Q QEC provides real-time decoding capabilities for quantum error correction on actual quantum hardware.
775+
Real-time decoding enables decoders to process syndromes and compute corrections within qubit coherence times,
776+
making active error correction practical for real quantum computers.
777+
778+
Key Features
779+
^^^^^^^^^^^^
780+
781+
* **Low-Latency Operation**: Syndrome processing within coherence time constraints.
782+
* **Hardware Integration**: Direct integration with quantum hardware backends (Quantinuum H-Series).
783+
* **Simulation Support**: Test real-time workflows locally before deploying to hardware.
784+
* **Multiple Decoder Types**: Support for LUT decoders, QLDPC decoders, and sliding window approaches.
785+
* **GPU Acceleration**: Leverage CUDA for high-performance syndrome decoding.
786+
787+
For detailed information on real-time decoding, see:
788+
789+
* :doc:`/examples_rst/qec/realtime_decoding` - Complete Guide with Examples
790+
* :doc:`/api/qec/cpp_api` - C++ API Reference (see Real-Time Decoding section)
791+
* :doc:`/api/qec/python_api` - Python API Reference (see Real-Time Decoding section)
792+
793+
794+
771795
Numerical Experiments
772796
---------------------
773797

@@ -1057,27 +1081,4 @@ Additional Noise Models
10571081
// Specify two qubit errors
10581082
noise.add_all_qubit_channel(
10591083
"x", cudaq::depolarization2(/*probability*/ 0.01),
1060-
/*numControls*/ 1);
1061-
1062-
Real-Time Decoding
1063-
------------------
1064-
1065-
CUDA-Q QEC provides real-time decoding capabilities for quantum error correction on actual quantum hardware.
1066-
Real-time decoding enables decoders to process syndromes and compute corrections within qubit coherence times,
1067-
making active error correction practical for real quantum computers.
1068-
1069-
Key Features
1070-
^^^^^^^^^^^^
1071-
1072-
* **Low-Latency Operation**: Syndrome processing within coherence time constraints
1073-
* **Hardware Integration**: Direct integration with quantum hardware backends (Quantinuum H-Series)
1074-
* **Simulation Support**: Test real-time workflows locally before deploying to hardware
1075-
* **Multiple Decoder Types**: Support for LUT decoders, QLDPC decoders, and sliding window approaches
1076-
* **GPU Acceleration**: Leverage CUDA for high-performance syndrome decoding
1077-
1078-
For detailed information on real-time decoding, see:
1079-
1080-
* :doc:`/examples_rst/qec/realtime_decoding` - Complete Guide with Examples
1081-
* :doc:`/api/qec/cpp_api` - C++ API Reference (see Real-Time Decoding section)
1082-
* :doc:`/api/qec/python_api` - Python API Reference (see Real-Time Decoding section)
1083-
1084+
/*numControls*/ 1);

docs/sphinx/examples_rst/qec/realtime_decoding.rst

Lines changed: 18 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ The real-time decoding framework supports two primary deployment scenarios:
1111
Key Features
1212
------------
1313

14-
* **Low-Latency Decoding**: Syndrome processing and correction calculation within coherence time constraints
15-
* **Streaming Syndrome Interface**: Continuous syndrome enqueueing from quantum circuits
16-
* **Multiple Decoder Support**: Concurrent management of multiple logical qubits, each with independent decoder instances
17-
* **Flexible Configuration**: YAML-based decoder configuration supporting various decoder types and parameters
18-
* **Device-Agnostic API**: Unified API that works across simulation and hardware backends
19-
* **GPU Acceleration**: Leverages CUDA for high-performance syndrome decoding
14+
* **Low-Latency Decoding**: Syndrome processing and correction calculation within coherence time constraints.
15+
* **Streaming Syndrome Interface**: Continuous syndrome enqueueing from quantum circuits.
16+
* **Multiple Decoder Support**: Concurrent management of multiple logical qubits, each with independent decoder instances.
17+
* **Flexible Configuration**: YAML-based decoder configuration supporting various decoder types and parameters.
18+
* **Device-Agnostic API**: Unified API that works across simulation and hardware backends.
19+
* **GPU Acceleration**: Leverages CUDA for high-performance syndrome decoding.
2020

2121
Workflow Overview
2222
-----------------
@@ -64,7 +64,7 @@ The examples above showcase the main components of the real-time decoding workfl
6464

6565
- Decoder finalization: Frees up resources after circuit execution.
6666

67-
The API is designed to be called from within quantum kernels (marked with ``@cudaq.kernel`` in Python or ``__qpu__`` in C++). The runtime automatically routes these calls to the appropriate backend—whether a simulation environment on your local machine or a low-latency connection to quantum hardware. The API is device-agnostic, so the same kernel code works across different deployment scenarios.
67+
The API is designed to be called from within quantum kernels (marked with ``@cudaq.kernel`` in Python or ``__qpu__`` in C++). The runtime automatically routes these calls to the appropriate backend—whether a simulation environment on the local machine or a low-latency connection to quantum hardware. The API is device-agnostic, so the same kernel code works across different deployment scenarios.
6868

6969
The user is required to provide a configuration file or generate one if it is not present. The generation process depends on the decoder type and the detector error model studied in other sections of the documentation. Moreover, the user must write an appropriate kernel that describes the correct syndrome extraction and correction application logic.
7070

@@ -250,7 +250,7 @@ With decoders configured and initialized, they can be used within quantum kernel
250250

251251
These functions are designed to be called from within quantum kernels (marked with ``@cudaq.kernel`` in Python or ``__qpu__`` in C++). The runtime automatically routes these calls to the appropriate backend - whether that is a simulation environment on the local machine or a low-latency connection to quantum hardware. The API is device-agnostic, so the same kernel code works across different deployment scenarios.
252252

253-
The typical pattern is: reset the decoder at the start of each shot, enqueue syndromes after each stabilizer measurement round, then get corrections before measuring the logical observables. Decoders process syndromes asynchronously, so by the time ``get_corrections`` is called, the decoder has usually finished its analysis. If decoding takes longer than expected, ``get_corrections`` will block until results are available.
253+
The typical procedure is: reset the decoder at the start of each shot, enqueue syndromes after each stabilizer measurement round, then get corrections before measuring the logical observables. Decoders process syndromes asynchronously, so by the time ``get_corrections`` is called, the decoder has usually finished its analysis. If decoding takes longer than expected, ``get_corrections`` will block until results are available.
254254

255255
Here is how to use the real-time decoding API in quantum kernels:
256256

@@ -363,7 +363,7 @@ For most practical scenarios with distance-5 to distance-9 codes and error rates
363363
This decoder works well up to moderate code distances because the lookup table size scales combinatorially with the number of error locations and the error depth. Beyond distance 9, or when higher error rates need to be handled, belief propagation decoders like the NV-QLDPC decoder should be considered.
364364

365365
* **Best for**: Small to medium codes (distance 5-9), moderate error rates (0.1-1%), good balance of speed and accuracy
366-
* **Parameters**:
366+
* **Configuration Parameters**:
367367

368368
* ``lut_error_depth`` (int): Maximum number of simultaneous errors to consider (typically 2-3). Higher values improve accuracy but increase memory usage.
369369

@@ -393,7 +393,7 @@ This decoder excels when working with codes beyond distance 9, where lookup tabl
393393
The decoder offers extensive tunability. The number of BP iterations can be adjusted to trade off latency for accuracy, the user can choose between sum-product and min-sum BP variants, and OSD search depth can be controlled. For real-time applications, conservative settings (50 iterations, OSD order 7) are a good starting point, with tuning based on observed error rates and latency requirements.
394394

395395
* **Best for**: Medium to large codes (distance ≥ 7), moderate to high error rates, scenarios where GPU acceleration is available
396-
* **Key Parameters**:
396+
* **Configuration Parameters**:
397397

398398
* ``error_rate_vec`` (list/vector of floats): Per-mechanism error probabilities - crucial for BP convergence. These should match the DEM's error rates.
399399
* ``max_iterations`` (int): Maximum BP iterations (typically 50-100). More iterations improve accuracy but increase latency.
@@ -432,7 +432,7 @@ and then combining the results to form a global correction.
432432
This approach reduces memory and computational requirements while still capturing most local error correlations.
433433

434434
* **Best for**: Very long circuits, memory-constrained systems
435-
* **Parameters**:
435+
* **ConfigurationParameters**:
436436

437437
* ``window_size``: Number of rounds per window
438438
* ``step_size``: Window advancement (equals window_size for non-overlapping)
@@ -782,7 +782,7 @@ Given that the user follows the structure of the examples provided, where each e
782782
./my_circuit_hardware --distance 3 --num_shots 100 --load_dem config_d3.yaml \
783783
--num_rounds 12 --decoder_window 6
784784
785-
**Workflow Parameters:**
785+
**Application Parameters:**
786786

787787
- ``--distance``: Code distance (3, 5, 7, etc.)
788788
- ``--num_shots``: Number of circuit repetitions
@@ -794,26 +794,26 @@ Given that the user follows the structure of the examples provided, where each e
794794

795795
Debugging and Environment Variables
796796
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
797-
797+
798798
**Useful Environment Variables:**
799799

800800
.. code-block:: bash
801801
802802
# Enable decoder configuration debugging
803803
export CUDAQ_QEC_DEBUG_DECODER=1
804804
805-
# Set default simulator (Python only, before importing cudaq)
805+
# Set default simulator
806806
export CUDAQ_DEFAULT_SIMULATOR=stim
807807
808808
# Dump JIT IR for debugging compilation issues
809809
export CUDAQ_DUMP_JIT_IR=1
810810
811-
# Keep log files after test execution
812-
export KEEP_LOG_FILES=true
813-
814811
# Set Quantinuum credentials file
815812
export CUDAQ_QUANTINUUM_CREDENTIALS=/path/to/credentials.json
816813
814+
The variables can be set in the user's environment or in a script.
815+
They are valid both for python and C++ applications, however, they must be set before importing the cudaq or cudaq_qec libraries.
816+
817817
**Common Compilation Issues:**
818818

819819
1. **Missing libraries**: Ensure all ``-lcudaq-qec-*`` libraries are linked in correct order
@@ -828,61 +828,6 @@ Debugging and Environment Variables
828828
3. **Dimension mismatch errors**: Verify DEM dimensions match the circuit's syndrome count
829829
4. **High error rates**: Check decoder window size matches DEM generation window
830830

831-
Testing Your Setup
832-
^^^^^^^^^^^^^^^^^^^
833-
834-
The installation can be verified with this minimal test:
835-
836-
.. tab:: Python
837-
838-
.. code-block:: python
839-
840-
import os
841-
os.environ["CUDAQ_DEFAULT_SIMULATOR"] = "stim"
842-
843-
import cudaq
844-
import cudaq_qec as qec
845-
846-
# Test decoder configuration
847-
print("Testing real-time decoding setup...")
848-
849-
# Create minimal decoder config
850-
config = qec.decoder_config()
851-
config.id = 0
852-
config.type = "multi_error_lut"
853-
config.block_size = 10
854-
config.syndrome_size = 5
855-
config.H_sparse = [0, 1, -1, 1, 2, -1] # Minimal test data
856-
config.O_sparse = [0, -1]
857-
config.D_sparse = [0, -1]
858-
859-
lut_config = qec.multi_error_lut_config()
860-
lut_config.lut_error_depth = 1
861-
config.set_decoder_custom_args(lut_config)
862-
863-
multi_config = qec.multi_decoder_config()
864-
multi_config.decoders = [config]
865-
866-
status = qec.configure_decoders(multi_config)
867-
print(f"Configuration status: {status}")
868-
869-
qec.finalize_decoders()
870-
print("Setup verified!")
871-
872-
.. tab:: C++
873-
874-
.. code-block:: bash
875-
876-
# Compile test
877-
nvq++ --target stim test_setup.cpp \
878-
-lcudaq-qec \
879-
-lcudaq-qec-realtime-decoding \
880-
-lcudaq-qec-realtime-decoding-simulation
881-
882-
# Run
883-
./a.out
884-
885-
If the test completes without errors, the setup is ready for real-time decoding experiments.
886831

887832
Best Practices
888833
--------------
@@ -891,6 +836,7 @@ Successfully deploying real-time decoding requires attention to several key deta
891836

892837
Decoder Selection
893838
^^^^^^^^^^^^^^^^^
839+
The page `CUDA-Q QEC Decoders <https://nvidia.github.io/cudaqx/components/qec/introduction.html#pre-built-qec-decoders>`_ provides initial guidance on how to choose the right decoder for the target application.
894840

895841
Choosing the right decoder is crucial for balancing accuracy, latency, and resource usage. The decision depends on multiple factors: the quantum code's distance, expected physical error rates, available computational resources, and latency requirements. This table provides initial guidance, but validation with the specific workload is always recommended:
896842

0 commit comments

Comments
 (0)