Skip to content

Commit 1516c90

Browse files
committed
Update C++ tests for public repo
Signed-off-by: Ben Howe <[email protected]>
1 parent 075193c commit 1516c90

File tree

5 files changed

+77
-64
lines changed

5 files changed

+77
-64
lines changed

libs/qec/unittests/realtime/app_examples/CMakeLists.txt

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,19 @@ add_test(
3838
${CMAKE_BINARY_DIR}/lib
3939
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
4040
)
41-
add_test(
42-
NAME app_examples.surface_code-1-local-test-distance-5
43-
COMMAND
44-
bash "${CMAKE_CURRENT_SOURCE_DIR}/surface_code-1-test.sh"
45-
${CMAKE_CURRENT_BINARY_DIR}/surface_code-1-local
46-
${CMAKE_CURRENT_BINARY_DIR}/surface_code-1-local
47-
5 40 40 NULL 20 10
48-
${CMAKE_BINARY_DIR}/lib
49-
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
50-
)
41+
# This must be disabled for now because the multi_error_lut decoder is not
42+
# powerful enough to pass this test. The nv-qldpc-decoder can pass this test,
43+
# but that is not available on the GitHub repo.
44+
# add_test(
45+
# NAME app_examples.surface_code-1-local-test-distance-5
46+
# COMMAND
47+
# bash "${CMAKE_CURRENT_SOURCE_DIR}/surface_code-1-test.sh"
48+
# ${CMAKE_CURRENT_BINARY_DIR}/surface_code-1-local
49+
# ${CMAKE_CURRENT_BINARY_DIR}/surface_code-1-local
50+
# 5 40 40 NULL 20 10
51+
# ${CMAKE_BINARY_DIR}/lib
52+
# WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
53+
# )
5154

5255
# Surface code 1 Python test
5356
add_test(
@@ -151,16 +154,19 @@ add_test(
151154
${CMAKE_BINARY_DIR}/lib
152155
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
153156
)
154-
add_test(
155-
NAME app_examples.surface_code-2-local-test-distance-5
156-
COMMAND
157-
bash "${CMAKE_CURRENT_SOURCE_DIR}/surface_code-2-test.sh"
158-
${CMAKE_CURRENT_BINARY_DIR}/surface_code-2-local
159-
${CMAKE_CURRENT_BINARY_DIR}/surface_code-2-local
160-
5 10 10 NULL
161-
${CMAKE_BINARY_DIR}/lib
162-
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
163-
)
157+
# This must be disabled for now because the multi_error_lut decoder is not
158+
# powerful enough to pass this test. The nv-qldpc-decoder can pass this test,
159+
# but that is not available on the GitHub repo.
160+
# add_test(
161+
# NAME app_examples.surface_code-2-local-test-distance-5
162+
# COMMAND
163+
# bash "${CMAKE_CURRENT_SOURCE_DIR}/surface_code-2-test.sh"
164+
# ${CMAKE_CURRENT_BINARY_DIR}/surface_code-2-local
165+
# ${CMAKE_CURRENT_BINARY_DIR}/surface_code-2-local
166+
# 5 10 10 NULL
167+
# ${CMAKE_BINARY_DIR}/lib
168+
# WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
169+
# )
164170

165171
# End of surface code 2, fully local, regular Stim simulator
166172
#------------------------------------------------------------------------------#
@@ -226,7 +232,10 @@ add_test(
226232

227233

228234
macro(add_surface_code_test base_name exe_local exe_remote dist server)
229-
foreach(err_rate IN ITEMS 0.010 0.015)
235+
# For now, disable 0.015 error rate because the multi_error_lut decoder is not
236+
# powerful enough to pass this test. The nv-qldpc-decoder can pass this test,
237+
# but that is not available on the GitHub repo.
238+
foreach(err_rate IN ITEMS 0.010)
230239
foreach(prep IN ITEMS prep0 prepp)
231240
add_test(
232241
NAME ${base_name}-dist-${dist}-${prep}-err-${err_rate}

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

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void save_dem_to_file(const cudaq::qec::detector_error_model &dem,
3939
auto numRounds = dem.num_detectors() / numSyndromesPerRound + 1;
4040
cudaq::qec::decoding::config::decoder_config config;
4141
config.id = i;
42-
config.type = "nv-qldpc-decoder";
42+
config.type = "multi_error_lut";
4343
config.block_size = dem.num_error_mechanisms();
4444
config.syndrome_size = dem.num_detectors();
4545
config.num_syndromes_per_round = numSyndromesPerRound;
@@ -49,16 +49,11 @@ void save_dem_to_file(const cudaq::qec::detector_error_model &dem,
4949
config.D_sparse = cudaq::qec::generate_timelike_sparse_detector_matrix(
5050
numSyndromesPerRound, numRounds, /*include_first_round=*/false);
5151
config.decoder_custom_args =
52-
cudaq::qec::decoding::config::nv_qldpc_decoder_config();
53-
auto &nv_config =
54-
std::get<cudaq::qec::decoding::config::nv_qldpc_decoder_config>(
52+
cudaq::qec::decoding::config::multi_error_lut_config();
53+
auto &multi_error_lut_config =
54+
std::get<cudaq::qec::decoding::config::multi_error_lut_config>(
5555
config.decoder_custom_args);
56-
nv_config.use_sparsity = true;
57-
nv_config.error_rate_vec = dem.error_rates;
58-
nv_config.use_osd = true;
59-
nv_config.max_iterations = 50;
60-
nv_config.osd_order = 60;
61-
nv_config.osd_method = 3;
56+
multi_error_lut_config.lut_error_depth = 2;
6257
multi_config.decoders.push_back(config);
6358
}
6459
std::string config_str = multi_config.to_yaml_str(200);
@@ -88,7 +83,7 @@ void load_dem_from_file(const std::string &dem_filename,
8883
}
8984
auto decoder_config = config.decoders[0];
9085
auto nv_qldpc_config =
91-
std::get<cudaq::qec::decoding::config::nv_qldpc_decoder_config>(
86+
std::get<cudaq::qec::decoding::config::multi_error_lut_config>(
9287
decoder_config.decoder_custom_args);
9388
dem.detector_error_matrix = cudaq::qec::pcm_from_sparse_vec(
9489
decoder_config.H_sparse, decoder_config.syndrome_size,
@@ -99,7 +94,6 @@ void load_dem_from_file(const std::string &dem_filename,
9994
decoder_config.O_sparse.end(), -1);
10095
dem.observables_flips_matrix = cudaq::qec::pcm_from_sparse_vec(
10196
decoder_config.O_sparse, num_observables, decoder_config.block_size);
102-
dem.error_rates = nv_qldpc_config.error_rate_vec.value();
10397
printf("Loaded dem from file: %s\n", dem_filename.c_str());
10498

10599
// Now configure the decoders

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

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void save_dem_to_file(const cudaq::qec::detector_error_model &dem,
3838
for (uint64_t i = 0; i < numLogical; i++) {
3939
cudaq::qec::decoding::config::decoder_config config;
4040
config.id = i;
41-
config.type = "nv-qldpc-decoder";
41+
config.type = "multi_error_lut";
4242
config.block_size = dem.num_error_mechanisms();
4343
config.syndrome_size = dem.num_detectors();
4444
config.num_syndromes_per_round = numSyndromesPerRound;
@@ -47,16 +47,11 @@ 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 = std::vector<int64_t>(det_mat);
4949
config.decoder_custom_args =
50-
cudaq::qec::decoding::config::nv_qldpc_decoder_config();
51-
auto &nv_config =
52-
std::get<cudaq::qec::decoding::config::nv_qldpc_decoder_config>(
50+
cudaq::qec::decoding::config::multi_error_lut_config();
51+
auto &multi_error_lut_config =
52+
std::get<cudaq::qec::decoding::config::multi_error_lut_config>(
5353
config.decoder_custom_args);
54-
nv_config.use_sparsity = true;
55-
nv_config.error_rate_vec = dem.error_rates;
56-
nv_config.use_osd = true;
57-
nv_config.max_iterations = 50;
58-
nv_config.osd_order = 60;
59-
nv_config.osd_method = 3;
54+
multi_error_lut_config.lut_error_depth = 2;
6055
multi_config.decoders.push_back(config);
6156
}
6257
std::string config_str = multi_config.to_yaml_str(200);
@@ -85,8 +80,8 @@ void load_dem_from_file(const std::string &dem_filename,
8580
exit(1);
8681
}
8782
auto decoder_config = config.decoders[0];
88-
auto nv_qldpc_config =
89-
std::get<cudaq::qec::decoding::config::nv_qldpc_decoder_config>(
83+
auto multi_error_lut_config =
84+
std::get<cudaq::qec::decoding::config::multi_error_lut_config>(
9085
decoder_config.decoder_custom_args);
9186
dem.detector_error_matrix = cudaq::qec::pcm_from_sparse_vec(
9287
decoder_config.H_sparse, decoder_config.syndrome_size,
@@ -97,7 +92,6 @@ void load_dem_from_file(const std::string &dem_filename,
9792
decoder_config.O_sparse.end(), -1);
9893
dem.observables_flips_matrix = cudaq::qec::pcm_from_sparse_vec(
9994
decoder_config.O_sparse, num_observables, decoder_config.block_size);
100-
dem.error_rates = nv_qldpc_config.error_rate_vec.value();
10195
printf("Loaded dem from file: %s\n", dem_filename.c_str());
10296

10397
// Now configure the decoders

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

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,19 @@ create_decoder_config(uint64_t id, const cudaq::qec::detector_error_model &dem,
3737
uint64_t numSyndromesPerRound) {
3838
cudaq::qec::decoding::config::decoder_config config;
3939
config.id = id;
40-
config.type = "nv-qldpc-decoder";
40+
config.type = "multi_error_lut";
4141
config.block_size = dem.num_error_mechanisms();
4242
config.syndrome_size = dem.num_detectors();
4343
config.num_syndromes_per_round = numSyndromesPerRound;
4444
config.H_sparse = cudaq::qec::pcm_to_sparse_vec(dem.detector_error_matrix);
4545
config.O_sparse = cudaq::qec::pcm_to_sparse_vec(dem.observables_flips_matrix);
4646
config.D_sparse = det_mat;
4747
config.decoder_custom_args =
48-
cudaq::qec::decoding::config::nv_qldpc_decoder_config();
49-
auto &nv_config =
50-
std::get<cudaq::qec::decoding::config::nv_qldpc_decoder_config>(
48+
cudaq::qec::decoding::config::multi_error_lut_config();
49+
auto &multi_error_lut_config =
50+
std::get<cudaq::qec::decoding::config::multi_error_lut_config>(
5151
config.decoder_custom_args);
52-
nv_config.use_sparsity = true;
53-
nv_config.error_rate_vec = dem.error_rates;
54-
nv_config.use_osd = true;
55-
nv_config.max_iterations = 50;
56-
nv_config.osd_order = 60;
57-
nv_config.osd_method = 3;
52+
multi_error_lut_config.lut_error_depth = 2;
5853
return config;
5954
}
6055

@@ -111,11 +106,11 @@ void load_dem_from_file(const std::string &dem_filename,
111106
const auto &decoder_config_z = config.decoders[2 * i];
112107
const auto &decoder_config_x = config.decoders[2 * i + 1];
113108

114-
auto nv_qldpc_config_z =
115-
std::get<cudaq::qec::decoding::config::nv_qldpc_decoder_config>(
109+
auto multi_error_lut_config_z =
110+
std::get<cudaq::qec::decoding::config::multi_error_lut_config>(
116111
decoder_config_z.decoder_custom_args);
117-
auto nv_qldpc_config_x =
118-
std::get<cudaq::qec::decoding::config::nv_qldpc_decoder_config>(
112+
auto multi_error_lut_config_x =
113+
std::get<cudaq::qec::decoding::config::multi_error_lut_config>(
119114
decoder_config_x.decoder_custom_args);
120115

121116
// Z stab decoder
@@ -129,8 +124,6 @@ void load_dem_from_file(const std::string &dem_filename,
129124
decoder_config_z.O_sparse, num_observables_z,
130125
decoder_config_z.block_size);
131126

132-
dem_z[i].error_rates = nv_qldpc_config_z.error_rate_vec.value();
133-
134127
// X stab decoder
135128
dem_x[i].detector_error_matrix = cudaq::qec::pcm_from_sparse_vec(
136129
decoder_config_x.H_sparse, decoder_config_x.syndrome_size,
@@ -141,8 +134,6 @@ void load_dem_from_file(const std::string &dem_filename,
141134
dem_x[i].observables_flips_matrix = cudaq::qec::pcm_from_sparse_vec(
142135
decoder_config_x.O_sparse, num_observables_x,
143136
decoder_config_x.block_size);
144-
145-
dem_x[i].error_rates = nv_qldpc_config_x.error_rate_vec.value();
146137
}
147138

148139
printf("Loaded %lu Z and %lu X DEMs from file: %s\n", dem_z.size(),

libs/qec/unittests/test_decoders_yaml.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,29 @@ create_test_decoder_config_nv_qldpc(int id) {
111111
return config;
112112
}
113113

114+
bool is_nv_qldpc_decoder_available() {
115+
try {
116+
std::size_t block_size = 7;
117+
std::size_t syndrome_size = 3;
118+
cudaqx::tensor<uint8_t> H;
119+
// clang-format off
120+
std::vector<uint8_t> H_vec = {1, 0, 0, 1, 0, 1, 1,
121+
0, 1, 0, 1, 1, 0, 1,
122+
0, 0, 1, 0, 1, 1, 1};
123+
// clang-format on
124+
H.copy(H_vec.data(), {syndrome_size, block_size});
125+
126+
auto d = cudaq::qec::decoder::get("nv-qldpc-decoder", H);
127+
return true;
128+
} catch (const std::exception &e) {
129+
return false;
130+
}
131+
}
132+
114133
TEST(DecoderYAMLTest, SingleDecoder) {
134+
if (!is_nv_qldpc_decoder_available()) {
135+
GTEST_SKIP() << "nv-qldpc-decoder is not available";
136+
}
115137
cudaq::qec::decoding::config::multi_decoder_config multi_config;
116138
cudaq::qec::decoding::config::decoder_config config =
117139
create_test_decoder_config_nv_qldpc(0);
@@ -122,6 +144,9 @@ TEST(DecoderYAMLTest, SingleDecoder) {
122144
}
123145

124146
TEST(DecoderYAMLTest, MultiDecoder) {
147+
if (!is_nv_qldpc_decoder_available()) {
148+
GTEST_SKIP() << "nv-qldpc-decoder is not available";
149+
}
125150
cudaq::qec::decoding::config::multi_decoder_config multi_config;
126151
cudaq::qec::decoding::config::decoder_config config1 =
127152
create_test_decoder_config_nv_qldpc(0);

0 commit comments

Comments
 (0)