Skip to content

Commit 4b3fc40

Browse files
committed
Add docs
Signed-off-by: Ben Howe <bhowe@nvidia.com>
1 parent 2aca305 commit 4b3fc40

4 files changed

Lines changed: 21 additions & 8 deletions

File tree

docs/sphinx/api/qec/nv_qldpc_decoder_api.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@
3333
[0, 1, 0, 1, 1, 0, 1],
3434
[0, 0, 1, 0, 1, 1, 1]], dtype=np.uint8) # sample 3x7 PCM
3535
opts = dict() # see below for options
36-
# Note: H must be in row-major order. If you use
37-
# `scipy.sparse.csr_matrix.todense()` to get the parity check
38-
# matrix, you must specify todense(order='C') to get a row-major
39-
# matrix.
36+
# H may also be a scipy.sparse matrix (CSR, CSC, COO, or any
37+
# other scipy.sparse format), which avoids a full dense rows×cols
38+
# allocation for large PCMs. Any format is normalised to CSR
39+
# internally; no call to .toarray() or .todense() is needed.
4040
nvdec = qec.get_decoder('nv-qldpc-decoder', H, **opts)
4141
4242
.. tab:: C++

docs/sphinx/components/qec/introduction.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,10 @@ CUDA-Q QEC supports implementing decoders in Python using the :code:`@qec.decode
644644
@qec.decoder("my_decoder")
645645
class MyDecoder:
646646
def __init__(self, H, **kwargs):
647+
# H is a scipy.sparse matrix or a dense numpy uint8 array,
648+
# mirroring whatever was passed to qec.get_decoder().
649+
# Pass it unchanged to Decoder.__init__ so the C++ base class
650+
# stores a compact sparse representation without a dense allocation.
647651
qec.Decoder.__init__(self, H)
648652
self.H = H
649653
# Initialize with optional kwargs

docs/sphinx/examples/qec/python/nv-qldpc-decoder.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ def parse_csr_mat(j, dims, mat_name):
4141
# Create a data array of ones.
4242
data = np.ones(indptr[-1], dtype=np.uint8)
4343

44-
# Build the CSR matrix and return it as a dense numpy array.
45-
csr = csr_matrix((data, indices, indptr), shape=dims, dtype=np.uint8)
46-
return csr.toarray()
44+
# Build and return the sparse matrix directly — no dense allocation.
45+
return csr_matrix((data, indices, indptr), shape=dims, dtype=np.uint8)
4746

4847

4948
def parse_H_csr(j, dims):
@@ -57,7 +56,7 @@ def parse_obs_csr(j, dims):
5756
"""
5857
Parse a CSR-style observable matrix from an input file in JSON format"
5958
"""
60-
return parse_csr_mat(j, dims, "obs_mat")
59+
return parse_csr_mat(j, dims, "obs_mat").toarray()
6160

6261

6362
### Main decoder loop ###

docs/sphinx/examples_rst/qec/decoders.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ The relationship between errors and syndromes is captured mathematically by the
99
stabilizer measurement, while each column represents a possible error. When we multiply an error pattern by this matrix, we get the syndrome
1010
that would result from those errors.
1111

12+
.. note::
13+
**scipy.sparse interop** — :func:`cudaq_qec.get_decoder` and
14+
:class:`cudaq_qec.Decoder` accept a ``scipy.sparse`` matrix (CSR, CSC,
15+
COO, or any other ``scipy.sparse`` format) as the parity-check matrix
16+
``H``. This is the preferred form for large PCMs because no dense
17+
``rows x cols`` allocation is made — the matrix is normalised to CSR
18+
internally. Dense NumPy ``uint8`` arrays remain supported.
19+
``scipy`` is an optional dependency; if it is not installed, pass a dense
20+
NumPy array instead.
21+
1222
Detector Error Model
1323
+++++++++++++++++++++
1424

0 commit comments

Comments
 (0)