Skip to content

Commit d38c913

Browse files
committed
Made D_sparse no longer optional, and fixed surface_code segfault
Signed-off-by: Chuck Ketcham <[email protected]>
1 parent c97e326 commit d38c913

File tree

4 files changed

+11
-15
lines changed

4 files changed

+11
-15
lines changed

libs/qec/include/cudaq/qec/realtime/decoding_config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ struct decoder_config {
120120
uint64_t syndrome_size = 0;
121121
std::vector<std::int64_t> H_sparse;
122122
std::vector<std::int64_t> O_sparse;
123-
std::optional<std::vector<std::int64_t>> D_sparse;
123+
std::vector<std::int64_t> D_sparse;
124124
std::variant<single_error_lut_config, multi_error_lut_config,
125125
nv_qldpc_decoder_config, sliding_window_config>
126126
decoder_custom_args;

libs/qec/lib/realtime/config.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ struct MappingTraits<cudaq::qec::decoding::config::decoder_config> {
351351
io.mapRequired("syndrome_size", config.syndrome_size);
352352
io.mapRequired("H_sparse", config.H_sparse);
353353
io.mapRequired("O_sparse", config.O_sparse);
354-
io.mapOptional("D_sparse", config.D_sparse);
354+
io.mapRequired("D_sparse", config.D_sparse);
355355

356356
// Validate that the number of rows in the H_sparse vector is equal to
357357
// syndrome_size.
@@ -383,9 +383,9 @@ struct MappingTraits<cudaq::qec::decoding::config::decoder_config> {
383383
// Validate that if the D_sparse is provided, it is a valid D matrix. That
384384
// means that the number of rows in the D_sparse matrix should be equal to
385385
// the number of rows in the H_sparse matrix, and no row should be empty.
386-
if (config.D_sparse.has_value()) {
386+
if (!config.D_sparse.empty()) {
387387
auto num_D_rows =
388-
std::count(config.D_sparse->begin(), config.D_sparse->end(), -1);
388+
std::count(config.D_sparse.begin(), config.D_sparse.end(), -1);
389389
if (num_D_rows != config.syndrome_size) {
390390
throw std::runtime_error("Number of rows in D_sparse vector is not "
391391
"equal to syndrome_size: " +
@@ -394,14 +394,13 @@ struct MappingTraits<cudaq::qec::decoding::config::decoder_config> {
394394
}
395395
// No row should be empty, which means that there should be no
396396
// back-to-back -1 values.
397-
for (std::size_t i = 0; i < config.D_sparse->size() - 1; ++i) {
398-
if (config.D_sparse->at(i) == -1 && config.D_sparse->at(i + 1) == -1) {
397+
for (std::size_t i = 0; i < config.D_sparse.size() - 1; ++i) {
398+
if (config.D_sparse.at(i) == -1 && config.D_sparse.at(i + 1) == -1) {
399399
throw std::runtime_error("D_sparse row is empty for decoder " +
400400
std::to_string(config.id));
401401
}
402402
}
403403
}
404-
405404
#define INIT_AND_MAP_DECODER_CUSTOM_ARGS(type) \
406405
do { \
407406
if (!std::holds_alternative<type>(config.decoder_custom_args)) { \

libs/qec/lib/realtime/realtime_decoding.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ int configure_decoders(
7373
auto observable_matrix = cudaq::qec::pcm_from_sparse_vec(
7474
decoder_config.O_sparse, num_observables, decoder_config.block_size);
7575
new_decoder->set_O_sparse(decoder_config.O_sparse);
76-
if (decoder_config.D_sparse.has_value()) {
77-
new_decoder->set_D_sparse(*decoder_config.D_sparse);
76+
if (!decoder_config.D_sparse.empty()) {
77+
new_decoder->set_D_sparse(decoder_config.D_sparse);
7878
} else {
7979
throw std::runtime_error(
8080
"D_sparse must be provided in decoder configuration");

libs/qec/unittests/realtime/app_examples/surface_code-1.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,9 @@ void save_dem_to_file(const cudaq::qec::detector_error_model &dem,
4747
cudaq::qec::pcm_to_sparse_vec(dem.observables_flips_matrix);
4848
config.D_sparse = cudaq::qec::generate_timelike_sparse_detector_matrix(
4949
numSyndromesPerRound, numRounds, /*include_first_round=*/false);
50-
config.decoder_custom_args =
51-
cudaq::qec::decoding::config::multi_error_lut_config();
52-
auto &multi_error_lut_config =
53-
std::get<cudaq::qec::decoding::config::multi_error_lut_config>(
54-
config.decoder_custom_args);
55-
multi_error_lut_config.lut_error_depth = 2;
50+
cudaq::qec::decoding::config::multi_error_lut_config lut_config;
51+
lut_config.lut_error_depth = 2;
52+
config.decoder_custom_args = lut_config;
5653
multi_config.decoders.push_back(config);
5754
}
5855
std::string config_str = multi_config.to_yaml_str(200);

0 commit comments

Comments
 (0)