Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion docs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ configure_file(${SPHINX_CONF_IN} ${SPHINX_CONF} @ONLY)
# TODO: set warning as error (-W flag)
add_custom_command(
OUTPUT ${SPHINX_INDEX_FILE}
COMMAND ${SPHINX_EXECUTABLE} -v -n --keep-going -b html
COMMAND ${CMAKE_COMMAND} -E env
LD_LIBRARY_PATH=${CUDAQ_LIBRARY_DIR}:$ENV{LD_LIBRARY_PATH}
${SPHINX_EXECUTABLE} -v -n --keep-going -b html
-c ${CMAKE_CURRENT_BINARY_DIR}
-Dbreathe_projects.cudaqx=${DOXYGEN_OUTPUT_DIR}/xml
${SPHINX_SOURCE} ${SPHINX_BUILD}
Expand All @@ -113,6 +115,7 @@ add_custom_command(
${SPHINX_SOURCE}/index.rst
${DOXYGEN_INDEX_FILE}
cudaqx-pymodules
cudaq-qec-realtime-decoding-simulation
${CUDAQX_PUBLIC_PYTHON}
${CUDAQX_PUBLIC_RST}
MAIN_DEPENDENCY ${SPHINX_CONF_IN} ${SPHINX_CONF}
Expand Down
4 changes: 3 additions & 1 deletion docs/Doxyfile.in
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ ENABLE_PREPROCESSING = YES
MACRO_EXPANSION = YES
EXPAND_ONLY_PREDEF = YES
PREDEFINED = "__qpu__=" \
"__attribute__(x)="
"__attribute__(x)=" \
"CUDAQ_EXTENSION_CUSTOM_CREATOR_FUNCTION(TYPE,...)=" \
"CUDAQ_EXTENSION_CUSTOM_CREATOR_FUNCTION_WITH_NAME(TYPE,NAME,...)="

#---------------------------------------------------------------------------
# Configuration options related to the HTML output
Expand Down
17 changes: 17 additions & 0 deletions docs/sphinx/api/core/cpp_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ Namespaces
:desc-only:
.. doxygennamespace:: cudaq::qec
:desc-only:
.. doxygennamespace:: cudaq::qec::decoding
:desc-only:
.. doxygennamespace:: cudaq::qec::decoding::config
:desc-only:
.. doxygennamespace:: cudaq::qec::detail
:desc-only:
.. doxygennamespace:: cudaq::qec::realtime
:desc-only:
.. doxygennamespace:: cudaq::qec::realtime::experimental
:desc-only:
.. doxygennamespace:: cudaq::qec::steane
:desc-only:
.. doxygennamespace:: cudaq::qec::surface_code
Expand All @@ -30,6 +40,13 @@ Core
.. doxygenclass:: cudaqx::extension_point
:members:

.. doxygendefine:: CUDAQ_EXTENSION_CREATOR_FUNCTION
.. doxygendefine:: CUDAQ_EXTENSION_CUSTOM_CREATOR_FUNCTION
.. doxygendefine:: CUDAQ_EXTENSION_CUSTOM_CREATOR_FUNCTION_WITH_NAME
.. doxygendefine:: CUDAQ_EXT_PT_REGISTER_TYPE
.. doxygendefine:: INSTANTIATE_REGISTRY_NO_ARGS
.. doxygendefine:: INSTANTIATE_REGISTRY

.. doxygenclass:: cudaqx::heterogeneous_map
:members:

Expand Down
21 changes: 21 additions & 0 deletions docs/sphinx/api/qec/cpp_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ Code

.. _qec_stabilizer_grid_cpp:

.. doxygenenum:: cudaq::qec::surface_code::surface_role
.. doxygenenum:: cudaq::qec::surface_code::sc_orientation
.. doxygenstruct:: cudaq::qec::surface_code::vec2d
:members:

.. doxygenclass:: cudaq::qec::surface_code::stabilizer_grid
:members:

Expand All @@ -42,6 +47,11 @@ Detector Error Model
Decoder Interfaces
==================

.. doxygenstruct:: cudaq::qec::decoder_inputs
:members:

.. doxygentypedef:: cudaq::qec::decoder_init

.. doxygenclass:: cudaq::qec::decoder
:members:

Expand Down Expand Up @@ -82,6 +92,14 @@ Real-Time Decoding
Parity Check Matrix Utilities
=============================

.. doxygenenum:: cudaq::qec::sparse_binary_matrix_layout

.. doxygenclass:: cudaq::qec::sparse_binary_matrix
:members:

.. doxygenfunction:: cudaq::qec::to_parity_matrix(const std::vector<cudaq::spin_op_term> &, stabilizer_type)
.. doxygenfunction:: cudaq::qec::to_parity_matrix(const std::vector<std::string> &, stabilizer_type)

.. doxygenfunction:: cudaq::qec::dense_to_sparse(const cudaqx::tensor<uint8_t> &)
.. doxygenfunction:: cudaq::qec::generate_random_pcm(std::size_t, std::size_t, std::size_t, int, std::mt19937_64 &&);
.. doxygenfunction:: cudaq::qec::generate_timelike_sparse_detector_matrix(std::uint32_t num_syndromes_per_round, std::uint32_t num_rounds, bool include_first_round = false)
Expand Down Expand Up @@ -112,6 +130,8 @@ the ``CUDA_QEC_*`` macros exposed in ``cudaq/qec/logger.h``.
.. doxygenstruct:: cudaq::qec::detail::forwarded_log_record
:members:

.. doxygenvariable:: cudaq::qec::detail::realtime_forwarder_default_message_capacity

.. doxygenstruct:: cudaq::qec::detail::forwarder_config
:members:

Expand Down Expand Up @@ -141,6 +161,7 @@ Common
.. doxygentypedef:: cudaq::qec::float_t

.. doxygenenum:: cudaq::qec::operation
.. doxygenenum:: cudaq::qec::stabilizer_type

.. doxygenfunction:: cudaq::qec::sample_code_capacity(const cudaqx::tensor<uint8_t> &, std::size_t, double)
.. doxygenfunction:: cudaq::qec::sample_code_capacity(const cudaqx::tensor<uint8_t> &, std::size_t, double, unsigned)
Expand Down
11 changes: 11 additions & 0 deletions docs/sphinx/api/qec/cpp_realtime_decoding_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ Configuration API

The configuration API enables setting up decoders before circuit execution. Decoders are configured using YAML files or programmatically constructed configuration objects.

.. doxygenstruct:: cudaq::qec::realtime::graph_resources
:members:

.. doxygenenum:: cudaq::qec::decoding::config::DecoderTransport

.. doxygenstruct:: cudaq::qec::decoding::config::decoder_config
:members:

.. doxygenclass:: cudaq::qec::decoding::config::multi_decoder_config
:members:

.. doxygenfunction:: cudaq::qec::decoding::config::configure_decoders
.. doxygenfunction:: cudaq::qec::decoding::config::configure_decoders_from_file
.. doxygenfunction:: cudaq::qec::decoding::config::configure_decoders_from_str
Expand Down
11 changes: 10 additions & 1 deletion docs/sphinx/api/qec/python_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ CUDA-Q QEC Python API
******************************

.. automodule:: cudaq_qec
:members:

Code
=============
Expand Down Expand Up @@ -47,6 +46,14 @@ Decoder Interfaces
.. autoclass:: cudaq_qec.DecoderResult
:members:

.. autoclass:: cudaq_qec.BatchDecoderResult
:members:

.. autoclass:: cudaq_qec.AsyncDecoderResult
:members:

.. autofunction:: cudaq_qec.get_decoder

Built-in Decoders
=================

Expand Down Expand Up @@ -91,6 +98,8 @@ Common

.. autofunction:: cudaq_qec.sample_code_capacity

.. _parity_check_matrix_utilities_python:

Parity Check Matrix Utilities
=============================

Expand Down
2 changes: 1 addition & 1 deletion docs/sphinx/api/qec/python_realtime_decoding_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,4 @@ Real-time decoding requires converting matrices to sparse format for efficient d
config.D_sparse = qec.generate_timelike_sparse_detector_matrix(
numSyndromesPerRound, numRounds, False)

See also :ref:`Parity Check Matrix Utilities <python_api:Parity Check Matrix Utilities>` for additional PCM manipulation functions.
See also :ref:`parity_check_matrix_utilities_python` for additional PCM manipulation functions.
6 changes: 0 additions & 6 deletions docs/sphinx/api/qec/realtime_pipeline_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,3 @@ Pipeline

.. doxygenclass:: cudaq::qec::realtime::experimental::realtime_pipeline
:members:

.. doxygenstruct:: cudaq::qec::realtime::experimental::realtime_pipeline::Stats
:members:

.. doxygenstruct:: cudaq::qec::realtime::experimental::realtime_pipeline::ring_buffer_bases
:members:
2 changes: 1 addition & 1 deletion docs/sphinx/api/qec/tensor_network_decoder_api.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.. class:: cudaq_qec.plugin.decoders.tensor_network_decoder.TensorNetworkDecoder
.. class:: cudaq_qec.plugins.decoders.tensor_network_decoder.TensorNetworkDecoder

A general class for tensor network decoders for quantum error correction codes.

Expand Down
12 changes: 7 additions & 5 deletions docs/sphinx/api/solvers/cpp_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ CUDA-Q Solvers C++ API
.. doxygenclass:: cudaq::solvers::operator_pool
:members:

.. doxygenclass:: cudaq::solvers::spin_complement_gsd
.. doxygenclass:: cudaq::solvers::uccsd
.. doxygenclass:: cudaq::solvers::uccgsd
.. doxygenclass:: cudaq::solvers::spin_complement_gsd
.. doxygenclass:: cudaq::solvers::uccsd
.. doxygenclass:: cudaq::solvers::uccgsd
.. doxygenclass:: cudaq::solvers::ceo
.. doxygenclass:: cudaq::solvers::upccgsd

.. doxygenclass:: cudaq::solvers::qaoa_pool

Expand Down Expand Up @@ -75,8 +77,8 @@ CUDA-Q Solvers C++ API

.. doxygenstruct:: cudaq::solvers::qaoa_result
:members:
.. doxygenfunction:: cudaq::solvers::qaoa(const cudaq::spin_op &, const cudaq::spin_op &, const optim::optimizer &, std::size_t, const std::vector<double> &, const heterogeneous_map)
.. doxygenfunction:: cudaq::solvers::qaoa(const cudaq::spin_op &, const optim::optimizer &, std::size_t, const std::vector<double> &, const heterogeneous_map)
.. doxygenfunction:: cudaq::solvers::qaoa(const cudaq::spin_op &, const cudaq::spin_op &, optim::optimizer &, std::size_t, const std::vector<double> &, const heterogeneous_map)
.. doxygenfunction:: cudaq::solvers::qaoa(const cudaq::spin_op &, optim::optimizer &, std::size_t, const std::vector<double> &, const heterogeneous_map)
.. doxygenfunction:: cudaq::solvers::qaoa(const cudaq::spin_op &, std::size_t, const std::vector<double> &, const heterogeneous_map)
.. doxygenfunction:: cudaq::solvers::qaoa(const cudaq::spin_op &, const cudaq::spin_op &, std::size_t, const std::vector<double> &, const heterogeneous_map)
.. doxygenfunction:: cudaq::solvers::get_num_qaoa_parameters(const cudaq::spin_op &, const cudaq::spin_op &, std::size_t, const heterogeneous_map)
Expand Down
5 changes: 2 additions & 3 deletions docs/sphinx/components/qec/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -507,10 +507,9 @@ You must pass ``distance`` when constructing the code; there is no default.

The :ref:`stabilizer_grid <qec_stabilizer_grid_python>` helper documents how
stabilizers and data qubits are indexed on the grid and provides helpers to
print the layout. **Python:** :class:`cudaq_qec.stabilizer_grid` — see
:ref:`qec_stabilizer_grid_python`. **C++:**
print the layout. **Python:** :ref:`cudaq_qec.stabilizer_grid <qec_stabilizer_grid_python>` — **C++:**
:cpp:class:`cudaq::qec::surface_code::stabilizer_grid` — see
:ref:`qec_stabilizer_grid_cpp`. The header :file:`cudaq/qec/codes/surface_code.h`
:ref:`API <qec_stabilizer_grid_cpp>`. The header :file:`cudaq/qec/codes/surface_code.h`
contains the full declaration.

**Stabilizer measurement schedule**
Expand Down
74 changes: 72 additions & 2 deletions docs/sphinx/conf.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,20 @@ master_doc = 'index'
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_templates']
# Fragment files pulled in via ``.. include::`` must not also be processed as
# standalone documents — doing so causes duplicate C++ / Python domain
# declarations in the Sphinx domain registry.
exclude_patterns = [
'_templates',
'api/qec/nv_qldpc_decoder_api.rst',
'api/qec/sliding_window_api.rst',
'api/qec/trt_decoder_api.rst',
'api/qec/tensor_network_decoder_api.rst',
'api/qec/python_realtime_decoding_api.rst',
'api/qec/cpp_realtime_decoding_api.rst',
'api/qec/realtime_pipeline_api.rst',
'api/solvers/gqe_api.rst',
]

# The reST default role (used for this markup: `text`) to use for all documents.
default_role = 'code' # NOTE: the following may be a better choice to error on the side of flagging anything that is referenced but but not declared
Expand Down Expand Up @@ -156,6 +169,34 @@ def process_docstring(app, what, name, obj, options, lines):
for i, line in enumerate(lines):
lines[i] = fix_string(line)

def _fixup_class_modules():
# Types bound in the qecrt nanobind submodule have __module__ set to the
# internal extension path. Autodoc treats any class whose __module__ doesn't
# match the documenting module as an alias and emits "alias of <internal path>"
# instead of real documentation; stringify_annotation() also uses __module__ to
# build type-annotation strings in function signatures. Fix up every public
# type in cudaq_qec whose module still points at the internal path so that
# both autoclass and autofunction produce clean output automatically.
try:
import cudaq_qec
_internal_prefix = 'cudaq_qec._pycudaqx'
for _name in dir(cudaq_qec):
if _name.startswith('_'):
continue
_obj = getattr(cudaq_qec, _name, None)
if isinstance(_obj, type) and \
getattr(_obj, '__module__', '').startswith(_internal_prefix):
try:
_obj.__module__ = 'cudaq_qec'
except (AttributeError, TypeError):
pass
except ImportError:
pass

_fixup_class_modules()
del _fixup_class_modules


def setup(app):
app.connect('autodoc-process-signature', process_signature)
app.connect('autodoc-process-docstring', process_docstring)
Expand Down Expand Up @@ -183,6 +224,16 @@ redirects = {"versions": "../latest/releases.html"}
nitpick_ignore = [
('cpp:identifier', 'pid_t'),
('cpp:identifier', 'uint8_t'),
('cpp:identifier', 'uint32_t'),
('cpp:identifier', 'int64_t'),
('cpp:identifier', 'index_type'),
('ref', 'graph__resources_8h'),
('ref', 'decoder__config__schema_8h'),
('cpp:identifier', 'cudaq::pauli_word'),
('cpp:identifier', 'cudaGraphExec_t'),
('cpp:identifier', 'cudaStream_t'),
('cpp:identifier', 'SIZE_MAX'),
('cpp:identifier', 'uint64_t'),
('cpp:identifier', 'details::tensor_impl<Scalar>::scalar_type'),
('cpp:identifier', 'cudaqx'),
('cpp:identifier', 'size_t'),
Expand All @@ -199,9 +250,28 @@ nitpick_ignore = [
('cpp:identifier', 'cudaq::qview<>'),
('cpp:identifier', 'cudaq::measure_result'),
('py:class', 'SpinOperator'),
('py:class', 'cudaq.SpinOperator'),
('py:class', 'cudaq::sum_op<cudaq::spin_handler>'),
('py:class', 'list[cudaq::sum_op<cudaq::spin_handler>]'),
('py:class', 'tuple[float, list[float], list[cudaq::sum_op<cudaq::spin_handler>]]'),
('py:class', 'pauli_word'),
('py:class', 'PauliWord'),
('py:class', 'numpy.int32'),
('py:class', 'numpy.uint8'),
('py:class', 'cudaq.mlir._mlir_libs._quakeDialects.cudaq_runtime.qview')
('py:class', 'cudaq.mlir._mlir_libs._quakeDialects.cudaq_runtime.qview'),
('py:class', 'cudaq_qec.surface_role'),
('py:class', 'cudaq_qec.operation'),
('py:class', 'sc_orientation'),
('py:class', 'vec2d'),
]

# Suppress cross-reference warnings for types whose fully-qualified path still
# contains the internal pybind11 module name. This happens when Sphinx
# extracts the cross-reference from the raw nanobind-generated signature before
# the process_docstring / process_signature hooks have a chance to strip the
# prefix via doc_replacements.
nitpick_ignore_regex = [
('py:class', r'cudaq_qec\._pycudaqx_qec_the_suffix_matters_cudaq_qec\..*'),
]

napoleon_google_docstring = True
Expand Down
14 changes: 7 additions & 7 deletions docs/sphinx/examples_rst/qec/decoders.rst
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ Exact Maximum Likelihood Decoding with NVIDIA Tensor Network Decoder
Starting with CUDA-Q QEC v0.4.0, a GPU-accelerated Maximum Likelihood Decoder is included with the
CUDA-Q QEC library. The library follows the CUDA-Q decoder Python interface, namely :class:`cudaq_qec.Decoder`.
At this time, we only support the Python interface for the decoder, which is
available at :class:`cudaq_qec.plugins.decoders.tensor_network_decoder.TensorNetworkDecoder`.
available at :ref:`TensorNetworkDecoder <tensor_network_decoder_api_python>`.
As documented in the API sections :ref:`tensor_network_decoder_api_python`, there are many configuration options
that can be passed to the constructor. The decoder requires Python 3.11 or higher.

Expand Down Expand Up @@ -170,7 +170,7 @@ to decode surface code syndromes using PyTorch and Stim, exporting the model to
deploying it with the TensorRT decoder for accelerated inference.

Overview of the Training-to-Deployment Pipeline
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The workflow consists of three main stages:

Expand All @@ -186,7 +186,7 @@ The workflow consists of three main stages:
be loaded by the TensorRT decoder for optimized GPU inference in production QEC workflows.

Training a Neural Network Decoder with PyTorch and Stim
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The following example shows how to generate training data using Stim's built-in surface code
generator, train an MLP decoder with PyTorch, and export the model to ONNX format.
Expand All @@ -197,7 +197,7 @@ For instructions on installing PyTorch, see :ref:`Installing PyTorch <installing
:start-after: [Begin Documentation]

Using the TensorRT Decoder in CUDA-Q QEC
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Once you have a trained ONNX model, you can load it with the TensorRT decoder for accelerated
inference. The decoder can be used in both C++ and Python workflows.
Expand Down Expand Up @@ -279,7 +279,7 @@ you can load it directly:
engine_load_path="surface_code_decoder.trt")

Converting ONNX Models to TensorRT Engines
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

For production deployments where initialization time is critical, you can pre-build a TensorRT
engine from your ONNX model using the ``trtexec`` command-line tool that comes with TensorRT:
Expand Down Expand Up @@ -310,7 +310,7 @@ Pre-built engines offer several advantages:


Dependencies and Requirements
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The TensorRT decoder requires:

Expand All @@ -324,7 +324,7 @@ For training:
- **Stim**: For quantum circuit simulation and data generation

See Also
^^^^^^^^
~~~~~~~~

- :class:`cudaq_qec.Decoder` - Base decoder interface
- `ONNX <https://onnx.ai/>`_ - Open Neural Network Exchange format
Expand Down
Loading
Loading