@@ -243,33 +243,73 @@ void add_tesseract_module(py::module& root) {
243243 config : TesseractConfig
244244 The configuration object for the decoder.
245245 )pbdoc" )
246- .def (" decode_to_errors" ,
247- py::overload_cast<const std::vector<uint64_t >&>(&TesseractDecoder::decode_to_errors),
248- py::arg (" detections" ),
249- py::call_guard<py::scoped_ostream_redirect, py::scoped_estream_redirect>(), R"pbdoc(
246+ .def (
247+ " decode_to_errors" ,
248+ [](TesseractDecoder& self, const py::array_t <bool >& syndrome) {
249+ if ((size_t )syndrome.size () != self.num_detectors ) {
250+ std::string msg = " Syndrome array size (" + std::to_string (syndrome.size ()) +
251+ " ) does not match the number of detectors in the decoder (" +
252+ std::to_string (self.num_detectors ) + " )." ;
253+ throw std::invalid_argument (msg);
254+ }
255+
256+ std::vector<uint64_t > detections;
257+ auto syndrome_unchecked = syndrome.unchecked <1 >();
258+ for (size_t i = 0 ; i < (size_t )syndrome_unchecked.size (); ++i) {
259+ if (syndrome_unchecked (i)) {
260+ detections.push_back (i);
261+ }
262+ }
263+ self.decode_to_errors (detections);
264+ return self.predicted_errors_buffer ;
265+ },
266+ py::arg (" syndrome" ),
267+ py::call_guard<py::scoped_ostream_redirect, py::scoped_estream_redirect>(),
268+ R"pbdoc(
250269 Decodes a single shot to a list of error indices.
251270
252271 Parameters
253272 ----------
254- detections : list[int]
255- A list of indices of the detectors that have fired.
273+ syndrome : np.ndarray
274+ A 1D NumPy array of booleans representing the detector outcomes for a single shot.
275+ The length of the array should match the number of detectors in the DEM.
256276
257277 Returns
258278 -------
259279 list[int]
260280 A list of predicted error indices.
261- )pbdoc" )
262- .def (" decode_to_errors" ,
263- py::overload_cast<const std::vector<uint64_t >&, size_t , size_t >(
264- &TesseractDecoder::decode_to_errors),
265- py::arg (" detections" ), py::arg (" det_order" ), py::arg (" det_beam" ),
266- py::call_guard<py::scoped_ostream_redirect, py::scoped_estream_redirect>(), R"pbdoc(
281+ )pbdoc" )
282+ .def (
283+ " decode_to_errors" ,
284+ [](TesseractDecoder& self, const py::array_t <bool >& syndrome, size_t det_order,
285+ size_t det_beam) {
286+ if ((size_t )syndrome.size () != self.num_detectors ) {
287+ std::string msg = " Syndrome array size (" + std::to_string (syndrome.size ()) +
288+ " ) does not match the number of detectors in the decoder (" +
289+ std::to_string (self.num_detectors ) + " )." ;
290+ throw std::invalid_argument (msg);
291+ }
292+
293+ std::vector<uint64_t > detections;
294+ auto syndrome_unchecked = syndrome.unchecked <1 >();
295+ for (size_t i = 0 ; i < (size_t )syndrome_unchecked.size (); ++i) {
296+ if (syndrome_unchecked (i)) {
297+ detections.push_back (i);
298+ }
299+ }
300+ self.decode_to_errors (detections, det_order, det_beam);
301+ return self.predicted_errors_buffer ;
302+ },
303+ py::arg (" syndrome" ), py::arg (" det_order" ), py::arg (" det_beam" ),
304+ py::call_guard<py::scoped_ostream_redirect, py::scoped_estream_redirect>(),
305+ R"pbdoc(
267306 Decodes a single shot using a specific detector ordering and beam size.
268307
269308 Parameters
270309 ----------
271- detections : list[int]
272- A list of indices of the detectors that have fired.
310+ syndrome : np.ndarray
311+ A 1D NumPy array of booleans representing the detector outcomes for a single shot.
312+ The length of the array should match the number of detectors in the DEM.
273313 det_order : int
274314 The index of the detector ordering to use.
275315 det_beam : int
@@ -279,7 +319,7 @@ void add_tesseract_module(py::module& root) {
279319 -------
280320 list[int]
281321 A list of predicted error indices.
282- )pbdoc" )
322+ )pbdoc" )
283323 .def (
284324 " get_observables_from_errors" ,
285325 [](TesseractDecoder& self, const std::vector<size_t >& predicted_errors) {
@@ -355,11 +395,10 @@ void add_tesseract_module(py::module& root) {
355395 " decode" ,
356396 [](TesseractDecoder& self, const py::array_t <bool >& syndrome) {
357397 if ((size_t )syndrome.size () != self.num_detectors ) {
358- std::ostringstream msg;
359- msg << " Syndrome array size (" << syndrome.size ()
360- << " ) does not match the number of detectors in the decoder ("
361- << self.num_detectors << " )." ;
362- throw std::invalid_argument (msg.str ());
398+ std::string msg = " Syndrome array size (" + std::to_string (syndrome.size ()) +
399+ " ) does not match the number of detectors in the decoder (" +
400+ std::to_string (self.num_detectors ) + " )." ;
401+ throw std::invalid_argument (msg);
363402 }
364403
365404 std::vector<uint64_t > detections;
@@ -413,11 +452,11 @@ void add_tesseract_module(py::module& root) {
413452 size_t num_detectors = syndromes_unchecked.shape (1 );
414453
415454 if (num_detectors != self.num_detectors ) {
416- std::ostringstream msg;
417- msg << " The number of detectors in the input array ( " << num_detectors
418- << " ) does not match the number of detectors in the decoder ("
419- << self.num_detectors << " )." ;
420- throw std::invalid_argument (msg. str () );
455+ std::string msg = " The number of detectors in the input array ( " +
456+ std::to_string ( num_detectors) +
457+ " ) does not match the number of detectors in the decoder (" +
458+ std::to_string ( self.num_detectors ) + " )." ;
459+ throw std::invalid_argument (msg);
421460 }
422461
423462 // Allocate the result array.
0 commit comments