|
19 | 19 | #include <pybind11/pybind11.h> |
20 | 20 | #include <pybind11/stl.h> |
21 | 21 |
|
| 22 | +#include "stim_utils.pybind.h" |
22 | 23 | #include "tesseract.h" |
23 | 24 |
|
24 | 25 | namespace py = pybind11; |
25 | 26 |
|
| 27 | +namespace { |
| 28 | +TesseractConfig tesseract_config_maker( |
| 29 | + py::object dem, int det_beam = INF_DET_BEAM, bool beam_climbing = false, |
| 30 | + bool no_revisit_dets = false, bool at_most_two_errors_per_detector = false, |
| 31 | + bool verbose = false, size_t pqlimit = std::numeric_limits<size_t>::max(), |
| 32 | + std::vector<std::vector<size_t>> det_orders = std::vector<std::vector<size_t>>(), |
| 33 | + double det_penalty = 0.0) { |
| 34 | + stim::DetectorErrorModel input_dem = parse_py_object<stim::DetectorErrorModel>(dem); |
| 35 | + return TesseractConfig({input_dem, det_beam, beam_climbing, no_revisit_dets, |
| 36 | + at_most_two_errors_per_detector, verbose, pqlimit, det_orders, |
| 37 | + det_penalty}); |
| 38 | +} |
| 39 | +}; // namespace |
26 | 40 | void add_tesseract_module(py::module &root) { |
27 | 41 | auto m = root.def_submodule("tesseract", "Module containing the tesseract algorithm"); |
28 | 42 |
|
29 | 43 | m.attr("INF_DET_BEAM") = INF_DET_BEAM; |
30 | 44 | py::class_<TesseractConfig>(m, "TesseractConfig") |
31 | | - .def(py::init<stim::DetectorErrorModel, int, bool, bool, bool, bool, size_t, |
32 | | - std::vector<std::vector<size_t>>, double>(), |
33 | | - py::arg("dem"), py::arg("det_beam") = INF_DET_BEAM, py::arg("beam_climbing") = false, |
34 | | - py::arg("no_revisit_dets") = false, py::arg("at_most_two_errors_per_detector") = false, |
35 | | - py::arg("verbose") = false, py::arg("pqlimit") = std::numeric_limits<size_t>::max(), |
| 45 | + .def(py::init(&tesseract_config_maker), py::arg("dem"), py::arg("det_beam") = INF_DET_BEAM, |
| 46 | + py::arg("beam_climbing") = false, py::arg("no_revisit_dets") = false, |
| 47 | + py::arg("at_most_two_errors_per_detector") = false, py::arg("verbose") = false, |
| 48 | + py::arg("pqlimit") = std::numeric_limits<size_t>::max(), |
36 | 49 | py::arg("det_orders") = std::vector<std::vector<size_t>>(), py::arg("det_penalty") = 0.0) |
37 | | - .def_readwrite("dem", &TesseractConfig::dem) |
| 50 | + .def_property("dem", &dem_getter<TesseractConfig>, &dem_setter<TesseractConfig>) |
38 | 51 | .def_readwrite("det_beam", &TesseractConfig::det_beam) |
39 | 52 | .def_readwrite("no_revisit_dets", &TesseractConfig::no_revisit_dets) |
40 | 53 | .def_readwrite("at_most_two_errors_per_detector", |
|
0 commit comments