-
Notifications
You must be signed in to change notification settings - Fork 17
fixing https://github.com/quantumlib/tesseract-decoder/issues/92 by updating decode_to_errors #111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
78e5ec8
482cb81
106ce02
b4c9d08
5c211bc
d93e31d
7c10268
8a27808
1e52d57
c34dd80
24c0d69
96849b6
3d486b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # Agent Instructions | ||
|
|
||
| - Use the **CMake** build system when interacting with this repository. Humans use Bazel. | ||
| - A bug in some LLM coding environments makes Bazel difficult to use, so agents should rely on CMake. | ||
| - Keep both the CMake and Bazel builds working at all times. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -243,33 +243,73 @@ void add_tesseract_module(py::module& root) { | |
| config : TesseractConfig | ||
| The configuration object for the decoder. | ||
| )pbdoc") | ||
| .def("decode_to_errors", | ||
| py::overload_cast<const std::vector<uint64_t>&>(&TesseractDecoder::decode_to_errors), | ||
| py::arg("detections"), | ||
| py::call_guard<py::scoped_ostream_redirect, py::scoped_estream_redirect>(), R"pbdoc( | ||
| .def( | ||
| "decode_to_errors", | ||
| [](TesseractDecoder& self, const py::array_t<bool>& syndrome) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it is wise to have logic in this part of the code ... having logic here should only happen for simple copying or conversion. lets either modify the C++ decode_to_errors method to have the checks and filter or create a new one that does with tests
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good idea
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In a future refactor, let's add methods to the SimplexDecoder and TesseractDecoder APIs which accept a dense representation of the detection events. These will just convert to a sparse representation and call the sparse API methods. The checks for the array size can happen there instead of being duplicated throughout all the pybind glue code for both decoders. WDYT? |
||
| if ((size_t)syndrome.size() != self.num_detectors) { | ||
| std::string msg = "Syndrome array size (" + std::to_string(syndrome.size()) + | ||
| ") does not match the number of detectors in the decoder (" + | ||
| std::to_string(self.num_detectors) + ")."; | ||
| throw std::invalid_argument(msg); | ||
| } | ||
|
|
||
| std::vector<uint64_t> detections; | ||
| auto syndrome_unchecked = syndrome.unchecked<1>(); | ||
| for (size_t i = 0; i < (size_t)syndrome_unchecked.size(); ++i) { | ||
| if (syndrome_unchecked(i)) { | ||
| detections.push_back(i); | ||
| } | ||
| } | ||
| self.decode_to_errors(detections); | ||
| return self.predicted_errors_buffer; | ||
| }, | ||
| py::arg("syndrome"), | ||
| py::call_guard<py::scoped_ostream_redirect, py::scoped_estream_redirect>(), | ||
| R"pbdoc( | ||
| Decodes a single shot to a list of error indices. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| detections : list[int] | ||
| A list of indices of the detectors that have fired. | ||
| syndrome : np.ndarray | ||
| A 1D NumPy array of booleans representing the detector outcomes for a single shot. | ||
| The length of the array should match the number of detectors in the DEM. | ||
|
|
||
| Returns | ||
| ------- | ||
| list[int] | ||
| A list of predicted error indices. | ||
| )pbdoc") | ||
| .def("decode_to_errors", | ||
| py::overload_cast<const std::vector<uint64_t>&, size_t, size_t>( | ||
| &TesseractDecoder::decode_to_errors), | ||
| py::arg("detections"), py::arg("det_order"), py::arg("det_beam"), | ||
| py::call_guard<py::scoped_ostream_redirect, py::scoped_estream_redirect>(), R"pbdoc( | ||
| )pbdoc") | ||
| .def( | ||
| "decode_to_errors", | ||
| [](TesseractDecoder& self, const py::array_t<bool>& syndrome, size_t det_order, | ||
| size_t det_beam) { | ||
| if ((size_t)syndrome.size() != self.num_detectors) { | ||
| std::string msg = "Syndrome array size (" + std::to_string(syndrome.size()) + | ||
| ") does not match the number of detectors in the decoder (" + | ||
| std::to_string(self.num_detectors) + ")."; | ||
| throw std::invalid_argument(msg); | ||
| } | ||
|
|
||
| std::vector<uint64_t> detections; | ||
| auto syndrome_unchecked = syndrome.unchecked<1>(); | ||
| for (size_t i = 0; i < (size_t)syndrome_unchecked.size(); ++i) { | ||
| if (syndrome_unchecked(i)) { | ||
| detections.push_back(i); | ||
| } | ||
| } | ||
| self.decode_to_errors(detections, det_order, det_beam); | ||
| return self.predicted_errors_buffer; | ||
| }, | ||
| py::arg("syndrome"), py::arg("det_order"), py::arg("det_beam"), | ||
| py::call_guard<py::scoped_ostream_redirect, py::scoped_estream_redirect>(), | ||
| R"pbdoc( | ||
| Decodes a single shot using a specific detector ordering and beam size. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| detections : list[int] | ||
| A list of indices of the detectors that have fired. | ||
| syndrome : np.ndarray | ||
| A 1D NumPy array of booleans representing the detector outcomes for a single shot. | ||
| The length of the array should match the number of detectors in the DEM. | ||
| det_order : int | ||
| The index of the detector ordering to use. | ||
| det_beam : int | ||
|
|
@@ -279,7 +319,7 @@ void add_tesseract_module(py::module& root) { | |
| ------- | ||
| list[int] | ||
| A list of predicted error indices. | ||
| )pbdoc") | ||
| )pbdoc") | ||
| .def( | ||
| "get_observables_from_errors", | ||
| [](TesseractDecoder& self, const std::vector<size_t>& predicted_errors) { | ||
|
|
@@ -355,11 +395,10 @@ void add_tesseract_module(py::module& root) { | |
| "decode", | ||
| [](TesseractDecoder& self, const py::array_t<bool>& syndrome) { | ||
| if ((size_t)syndrome.size() != self.num_detectors) { | ||
| std::ostringstream msg; | ||
| msg << "Syndrome array size (" << syndrome.size() | ||
| << ") does not match the number of detectors in the decoder (" | ||
| << self.num_detectors << ")."; | ||
| throw std::invalid_argument(msg.str()); | ||
| std::string msg = "Syndrome array size (" + std::to_string(syndrome.size()) + | ||
| ") does not match the number of detectors in the decoder (" + | ||
| std::to_string(self.num_detectors) + ")."; | ||
| throw std::invalid_argument(msg); | ||
| } | ||
|
|
||
| std::vector<uint64_t> detections; | ||
|
|
@@ -413,11 +452,11 @@ void add_tesseract_module(py::module& root) { | |
| size_t num_detectors = syndromes_unchecked.shape(1); | ||
|
|
||
| if (num_detectors != self.num_detectors) { | ||
| std::ostringstream msg; | ||
| msg << "The number of detectors in the input array (" << num_detectors | ||
| << ") does not match the number of detectors in the decoder (" | ||
| << self.num_detectors << ")."; | ||
| throw std::invalid_argument(msg.str()); | ||
| std::string msg = "The number of detectors in the input array (" + | ||
| std::to_string(num_detectors) + | ||
| ") does not match the number of detectors in the decoder (" + | ||
| std::to_string(self.num_detectors) + ")."; | ||
| throw std::invalid_argument(msg); | ||
| } | ||
|
|
||
| // Allocate the result array. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.