Skip to content

Commit 85e9d2b

Browse files
fix formatting
Signed-off-by: vedika-saravanan <vsaravanan@nvidia.com>
1 parent eb9d051 commit 85e9d2b

4 files changed

Lines changed: 44 additions & 41 deletions

File tree

libs/qec/include/cudaq/qec/decoder.h

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@ using float_t = double;
3131
#endif
3232

3333
/// @brief Construction input for a decoder: either an explicit parity-check
34-
/// matrix (\c cudaq::qec::sparse_binary_matrix) or a Stim detector error model string
35-
/// (\c std::string_view).
34+
/// matrix (`cudaq::qec::sparse_binary_matrix`) or a Stim detector error model
35+
/// string (`std::string_view`).
3636
///
3737
/// Parity-check-matrix-based decoders (LUT, sliding_window, TRT, PyMatching,
3838
/// nv-qldpc, ...) accept either alternative: a DEM string is parsed into a
39-
/// parity-check matrix via \c dem_from_stim_text. Decoders that require the raw
39+
/// parity-check matrix via `dem_from_stim_text`. Decoders that require the raw
4040
/// DEM (e.g. Chromobius, which needs detector color/basis annotations) require
4141
/// the string alternative and reject a bare matrix.
4242
///
4343
/// @note The string alternative is non-owning. The referenced buffer must stay
44-
/// alive for the duration of the \c get_decoder / \c decoder::get call;
44+
/// alive for the duration of the `get_decoder` / `decoder::get` call;
4545
/// decoders parse it during construction and do not retain the view.
4646
using decoder_init =
4747
std::variant<cudaq::qec::sparse_binary_matrix, std::string_view>;
@@ -164,16 +164,16 @@ class decoder
164164
/// @brief Decode a single syndrome
165165
/// @param syndrome A vector of syndrome measurements where the floating point
166166
/// value is the probability that the syndrome measurement is a |1>. The
167-
/// length of the syndrome vector should be equal to \p syndrome_size.
168-
/// @returns Vector of length \p block_size with soft probabilities of errors
167+
/// length of the syndrome vector should be equal to `syndrome_size`.
168+
/// @returns Vector of length `block_size` with soft probabilities of errors
169169
/// in each index.
170170
virtual decoder_result decode(const std::vector<float_t> &syndrome) = 0;
171171

172172
/// @brief Decode a single syndrome
173173
/// @param syndrome An order-1 tensor of syndrome measurements where a 1 bit
174174
/// represents that the syndrome measurement is a |1>. The
175-
/// length of the syndrome vector should be equal to \p syndrome_size.
176-
/// @returns Vector of length \p block_size of errors in each index.
175+
/// length of the syndrome vector should be equal to `syndrome_size`.
176+
/// @returns Vector of length `block_size` of errors in each index.
177177
virtual decoder_result decode(const cudaqx::tensor<uint8_t> &syndrome);
178178

179179
/// @brief Decode a single syndrome
@@ -196,7 +196,7 @@ class decoder
196196
/// @brief Construct a registered decoder by name.
197197
/// @param name The registered decoder name.
198198
/// @param init Either a parity-check matrix or a Stim DEM string (see
199-
/// \c decoder_init). The variant is forwarded to the decoder's creator, so
199+
/// `decoder_init`). The variant is forwarded to the decoder's creator, so
200200
/// parity-check-matrix-based decoders and DEM-native decoders (Chromobius)
201201
/// share a single entry point.
202202
/// @param param_map Optional decoder-specific parameters.
@@ -206,19 +206,22 @@ class decoder
206206

207207
static std::unique_ptr<decoder>
208208
get(const std::string &name, const cudaq::qec::sparse_binary_matrix &H,
209-
const cudaqx::heterogeneous_map &param_map = cudaqx::heterogeneous_map()) {
209+
const cudaqx::heterogeneous_map &param_map =
210+
cudaqx::heterogeneous_map()) {
210211
return get(name, decoder_init{H}, param_map);
211212
}
212213

213214
static std::unique_ptr<decoder>
214215
get(const std::string &name, const cudaqx::tensor<uint8_t> &H,
215-
const cudaqx::heterogeneous_map &param_map = cudaqx::heterogeneous_map()) {
216+
const cudaqx::heterogeneous_map &param_map =
217+
cudaqx::heterogeneous_map()) {
216218
return get(name, cudaq::qec::sparse_binary_matrix(H), param_map);
217219
}
218220

219221
static std::unique_ptr<decoder>
220222
get(const std::string &name, std::string_view stim_dem_text,
221-
const cudaqx::heterogeneous_map &param_map = cudaqx::heterogeneous_map()) {
223+
const cudaqx::heterogeneous_map &param_map =
224+
cudaqx::heterogeneous_map()) {
222225
return get(name, decoder_init{stim_dem_text}, param_map);
223226
}
224227

@@ -503,26 +506,27 @@ dem_default_values dem_defaults_for_missing_keys(
503506
const std::function<bool(const std::string &)> &contains_user_key,
504507
const detector_error_model &dem);
505508

506-
/// @brief Extract the Stim DEM text from a \c decoder_init, throwing if it holds
507-
/// a parity-check matrix instead. Use this in the create() function of decoders
508-
/// that require a raw DEM (e.g. Chromobius), which cannot be reconstructed from
509-
/// a bare parity-check matrix.
509+
/// @brief Extract the Stim DEM text from a `decoder_init`, throwing if it
510+
/// holds a parity-check matrix instead. Use this in the create() function of
511+
/// decoders that require a raw DEM (e.g. Chromobius), which cannot be
512+
/// reconstructed from a bare parity-check matrix.
510513
std::string_view require_dem_text(const decoder_init &init);
511514

512-
/// @brief Build a parity-check-matrix-based decoder from a \c decoder_init.
515+
/// @brief Build a parity-check-matrix-based decoder from a `decoder_init`.
513516
///
514-
/// If \p init holds a sparse matrix, it is used directly as the parity-check matrix.
515-
/// If it holds a Stim DEM string, it is parsed via \c dem_from_stim_text and the
516-
/// derived observables (`"O"`) and per-error rates (`"error_rate_vec"`) are
517-
/// injected into \p params unless the user already supplied them (user values
518-
/// win). This is the shared implementation behind the create() function of every
519-
/// parity-check-matrix-based decoder, giving them DEM-string support for free.
517+
/// If `init` holds a sparse matrix, it is used directly as the parity-check
518+
/// matrix. If it holds a Stim DEM string, it is parsed via
519+
/// `dem_from_stim_text` and the derived observables (`"O"`) and per-error
520+
/// rates (`"error_rate_vec"`) are injected into `params` unless the user
521+
/// already supplied them (user values win). This is the shared implementation
522+
/// behind the create() function of every parity-check-matrix-based decoder,
523+
/// giving them DEM-string support for free.
520524
///
521525
/// @note The DEM parse is lossy: detector annotations, decomposition
522526
/// separators, and `error_ids` are dropped. Sufficient for matching-style /
523527
/// parity-check-matrix decoders (LUT, NV, sliding_window, TRT, PyMatching).
524528
/// Decoders that need full DEM metadata (e.g. Chromobius detector color/basis)
525-
/// must consume the string directly via \c require_dem_text.
529+
/// must consume the string directly via `require_dem_text`.
526530
template <typename DecoderT>
527531
std::unique_ptr<decoder>
528532
make_pcm_decoder(const decoder_init &init,
@@ -545,8 +549,8 @@ make_pcm_decoder(const decoder_init &init,
545549

546550
/// @brief Construct a decoder by name from a Stim detector error model string.
547551
///
548-
/// @deprecated Prefer \c get_decoder, which now accepts a Stim DEM string
549-
/// directly via \c decoder_init. Retained as a thin convenience alias.
552+
/// @deprecated Prefer `get_decoder`, which now accepts a Stim DEM string
553+
/// directly via `decoder_init`. Retained as a thin convenience alias.
550554
std::unique_ptr<decoder>
551555
get_decoder_from_stim_dem(const std::string &name,
552556
const std::string &stim_dem_text,

libs/qec/include/cudaq/qec/detector_error_model.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ namespace cudaq::qec {
1919
/// decoder to help make predictions about observables flips.
2020
///
2121
/// Shared size parameters among the matrix types.
22-
/// - \p detector_error_matrix: num_detectors x num_error_mechanisms [d, e]
23-
/// - \p error_rates: num_error_mechanisms
24-
/// - \p observables_flips_matrix: num_observables x num_error_mechanisms [k, e]
22+
/// - `detector_error_matrix`: num_detectors x num_error_mechanisms [d, e]
23+
/// - `error_rates`: num_error_mechanisms
24+
/// - `observables_flips_matrix`: num_observables x num_error_mechanisms [k, e]
2525
///
2626
/// @note The C++ API for this class may change in the future. The Python API is
2727
/// more likely to be backwards compatible.
@@ -33,7 +33,7 @@ struct detector_error_model {
3333
cudaqx::tensor<uint8_t> detector_error_matrix;
3434

3535
/// The list of weights has length equal to the number of columns of
36-
/// \p detector_error_matrix, which assigns a likelihood to each error
36+
/// `detector_error_matrix`, which assigns a likelihood to each error
3737
/// mechanism.
3838
std::vector<double> error_rates;
3939

@@ -67,17 +67,17 @@ struct detector_error_model {
6767
};
6868

6969
/// @brief Parse a Stim detector error model text into a
70-
/// \p cudaq::qec::detector_error_model. Each `error` instruction in the DEM
71-
/// becomes a single column in \p detector_error_matrix and
72-
/// \p observables_flips_matrix; suggested decomposition separators are
70+
/// `cudaq::qec::detector_error_model`. Each `error` instruction in the DEM
71+
/// becomes a single column in `detector_error_matrix` and
72+
/// `observables_flips_matrix`; suggested decomposition separators are
7373
/// folded into the same column.
7474
///
7575
/// @note Lossy: only detector/observable flips and error probabilities
7676
/// are extracted. Annotations (`detector`, `logical_observable`),
77-
/// suggested-decomposition separators, and \p error_ids are dropped.
77+
/// suggested-decomposition separators, and `error_ids` are dropped.
7878
/// Decoders that need full DEM metadata (e.g. Chromobius detector
79-
/// color/basis) require the planned \p detector_coords extension on
80-
/// \p detector_error_model; tracked as a follow-up.
79+
/// color/basis) require the planned `detector_coords` extension on
80+
/// `detector_error_model`; tracked as a follow-up.
8181
detector_error_model dem_from_stim_text(const std::string &dem_text);
8282

8383
} // namespace cudaq::qec

libs/qec/lib/decoder.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919

2020
INSTANTIATE_REGISTRY(cudaq::qec::decoder,
2121
const cudaq::qec::sparse_binary_matrix &)
22-
INSTANTIATE_REGISTRY(cudaq::qec::decoder,
23-
const cudaq::qec::decoder_init &,
22+
INSTANTIATE_REGISTRY(cudaq::qec::decoder, const cudaq::qec::decoder_init &,
2423
const cudaqx::heterogeneous_map &)
2524

2625
// Include decoder implementations AFTER registry instantiation

libs/qec/python/bindings/py_decoder.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -790,9 +790,9 @@ void bindDecoder(nb::module_ &mod) {
790790
// Shared implementation for constructing a decoder from a Stim DEM string,
791791
// used by both the get_decoder(str) overload and the (deprecated)
792792
// get_decoder_from_stim_dem entry point.
793-
auto get_decoder_from_dem_text =
794-
[](const std::string &name, const std::string &dem_text,
795-
nb::kwargs options)
793+
auto get_decoder_from_dem_text = [](const std::string &name,
794+
const std::string &dem_text,
795+
nb::kwargs options)
796796
-> std::variant<nb::object, std::unique_ptr<decoder>> {
797797
if (PyDecoderRegistry::contains(name)) {
798798
auto dem = dem_from_stim_text(dem_text);

0 commit comments

Comments
 (0)