Skip to content

Commit 3ef9349

Browse files
authored
Merge pull request #46 from noajshu/codex/fix-runtimeerror-in-tesseract_decoder
Reuse detector coordinate utility in Simplex and ignore logical_observable in DEM parsing
2 parents 1e0cd87 + 771b881 commit 3ef9349

3 files changed

Lines changed: 41 additions & 19 deletions

File tree

src/simplex.cc

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "Highs.h"
2020
#include "io/HMPSIO.h"
21+
#include "utils.h"
2122

2223
constexpr size_t T_COORD = 2;
2324

@@ -51,24 +52,16 @@ SimplexDecoder::SimplexDecoder(SimplexConfig _config) : config(_config) {
5152
dem_error_to_error = std::move(dem_error_map);
5253
error_to_dem_error = common::invert_error_map(dem_error_to_error, config.dem.count_errors());
5354

54-
std::vector<double> detector_t_coords(config.dem.count_detectors());
55-
for (const stim::DemInstruction& instruction : config.dem.flattened().instructions) {
56-
switch (instruction.type) {
57-
case stim::DemInstructionType::DEM_SHIFT_DETECTORS:
58-
throw std::runtime_error("DEM_SHIFT_DETECTORS instruction is not supported.");
59-
break;
60-
case stim::DemInstructionType::DEM_ERROR: {
61-
if (!(instruction.arg_data[0] > 0)) {
62-
throw std::invalid_argument("Error instruction probability must be greater than zero.");
63-
}
64-
errors.emplace_back(instruction);
65-
break;
66-
}
67-
case stim::DemInstructionType::DEM_DETECTOR:
68-
detector_t_coords[instruction.target_data[0].val()] = instruction.arg_data[T_COORD];
69-
break;
70-
default:
71-
throw std::runtime_error("Unsupported instruction type encountered.");
55+
errors = get_errors_from_dem(config.dem.flattened());
56+
57+
std::vector<double> detector_t_coords(config.dem.count_detectors(), 0);
58+
std::vector<std::vector<double>> detector_coords = get_detector_coords(config.dem);
59+
if (detector_coords.size() != config.dem.count_detectors()) {
60+
throw std::runtime_error("Mismatch between detector coordinates and detector count.");
61+
}
62+
for (size_t d = 0; d < detector_coords.size(); ++d) {
63+
if (detector_coords[d].size() > T_COORD) {
64+
detector_t_coords[d] = detector_coords[d][T_COORD];
7265
}
7366
}
7467
std::map<double, std::vector<size_t>> start_time_to_errors_map, end_time_to_errors_map;

src/tesseract.test.cc

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,33 @@ TEST(tesseract, DecodersStripZeroProbabilityErrors) {
219219
EXPECT_EQ(s_dec.errors.size(), 2);
220220
}
221221

222+
223+
TEST(tesseract, GetDetectorCoordsAllowsLogicalObservableInstructionsInDem) {
224+
stim::DetectorErrorModel dem(R"DEM(
225+
error(0.1) D0 L0
226+
detector(1,2,3) D0
227+
logical_observable L0
228+
)DEM");
229+
230+
std::vector<std::vector<double>> detector_coords = get_detector_coords(dem);
231+
ASSERT_EQ(detector_coords.size(), 1);
232+
ASSERT_EQ(detector_coords[0].size(), 3);
233+
EXPECT_EQ(detector_coords[0][0], 1);
234+
EXPECT_EQ(detector_coords[0][1], 2);
235+
EXPECT_EQ(detector_coords[0][2], 3);
236+
}
237+
TEST(tesseract, SimplexAllowsLogicalObservableInstructionsInDem) {
238+
stim::DetectorErrorModel dem(R"DEM(
239+
error(0.1) D0 L0
240+
detector(0,0,0) D0
241+
logical_observable L0
242+
)DEM");
243+
244+
EXPECT_NO_THROW({
245+
SimplexDecoder s_dec(SimplexConfig{dem});
246+
});
247+
}
248+
222249
TEST(tesseract, DecoderErrorIndexMapsAreInOriginalDemCoordinates) {
223250
stim::DetectorErrorModel dem(R"DEM(
224251
error(0.1) D0
@@ -344,4 +371,4 @@ TEST(tesseract, EneighborsCorrectness_ComplexGrid) {
344371
EXPECT_EQ(t_dec.get_eneighbors()[5], expected_e5_neighbors);
345372
EXPECT_EQ(t_dec.get_eneighbors()[6], expected_e6_neighbors);
346373
EXPECT_EQ(t_dec.get_eneighbors()[7], expected_e7_neighbors);
347-
}
374+
}

src/utils.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ std::vector<std::vector<double>> get_detector_coords(const stim::DetectorErrorMo
4545
detector_coords.push_back(coord);
4646
break;
4747
}
48+
case stim::DemInstructionType::DEM_LOGICAL_OBSERVABLE:
49+
break;
4850
default:
4951
throw std::invalid_argument(
5052
"Unexpected DemInstructionType found in the detector error model.");

0 commit comments

Comments
 (0)