Skip to content

Commit 9c4a6f1

Browse files
Make sinter decoder pickable
1 parent f2285e4 commit 9c4a6f1

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

src/py/tesseract_sinter_compat_test.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
from src.tesseract_decoder import tesseract_sinter_compat as tesseract_module
2323
from src import tesseract_decoder
24+
import sinter
2425

2526

2627
def test_tesseract_sinter_obj_exists():
@@ -493,6 +494,18 @@ def test_sinter_detector_counting():
493494
assert set(result.custom_counts.keys()) == {'detectors_checked', 'detection_events'}
494495

495496

497+
def test_full_scale():
498+
result, = sinter.collect(
499+
num_workers=2,
500+
tasks=[sinter.Task(circuit=stim.Circuit())],
501+
decoders=["tesseract"],
502+
max_shots=1000,
503+
custom_decoders=construct_tesseract_decoder_for_sinter(),
504+
)
505+
assert result.discards == 0
506+
assert result.shots == 1000
507+
assert result.errors == 0
508+
496509

497510

498511
if __name__ == "__main__":

src/tesseract_sinter_compat.pybind.h

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,5 +289,31 @@ void pybind_sinter_compat(py::module& root) {
289289
.def(py::self == py::self,
290290
R"pbdoc(Checks if two TesseractSinterDecoder instances are equal.)pbdoc")
291291
.def(py::self != py::self,
292-
R"pbdoc(Checks if two TesseractSinterDecoder instances are not equal.)pbdoc");
292+
R"pbdoc(Checks if two TesseractSinterDecoder instances are not equal.)pbdoc")
293+
.def(py::pickle(
294+
[](const TesseractSinterDecoder& self) -> py::tuple { // __getstate__
295+
return py::make_tuple(
296+
std::string(self.config.dem.str()), self.config.det_beam, self.config.beam_climbing,
297+
self.config.no_revisit_dets, self.config.at_most_two_errors_per_detector,
298+
self.config.verbose, self.config.merge_errors, self.config.pqlimit,
299+
self.config.det_orders, self.config.det_penalty, self.config.create_visualization);
300+
},
301+
[](py::tuple t) { // __setstate__
302+
if (t.size() != 11) {
303+
throw std::runtime_error("Invalid state for TesseractSinterDecoder!");
304+
}
305+
TesseractConfig config;
306+
config.dem = stim::DetectorErrorModel(t[0].cast<std::string>());
307+
config.det_beam = t[1].cast<int>();
308+
config.beam_climbing = t[2].cast<bool>();
309+
config.no_revisit_dets = t[3].cast<bool>();
310+
config.at_most_two_errors_per_detector = t[4].cast<bool>();
311+
config.verbose = t[5].cast<bool>();
312+
config.merge_errors = t[6].cast<bool>();
313+
config.pqlimit = t[7].cast<size_t>();
314+
config.det_orders = t[8].cast<std::vector<std::vector<size_t>>>();
315+
config.det_penalty = t[9].cast<double>();
316+
config.create_visualization = t[10].cast<bool>();
317+
return TesseractSinterDecoder(config);
318+
}));
293319
}

0 commit comments

Comments
 (0)