|
1 | 1 | #ifndef TESSERACT_COMMON_PY_H |
2 | 2 | #define TESSERACT_COMMON_PY_H |
3 | 3 |
|
| 4 | +#include <vector> |
| 5 | + |
4 | 6 | #include <pybind11/operators.h> |
5 | 7 | #include <pybind11/pybind11.h> |
6 | 8 | #include <pybind11/stl.h> |
7 | 9 |
|
8 | | -#include <vector> |
| 10 | +#include "src/stim/dem/dem_instruction.pybind.h" |
| 11 | +#include "stim/dem/detector_error_model_target.pybind.h" |
9 | 12 |
|
10 | 13 | #include "common.h" |
11 | 14 |
|
12 | 15 | namespace py = pybind11; |
13 | 16 |
|
14 | | -void add_common_module(py::module &root) { |
15 | | - auto m = root.def_submodule("common", "classes commonly used by the decoder"); |
16 | | - |
17 | | - // TODO: add as_dem_instruction_targets |
18 | | - py::class_<common::Symptom>(m, "Symptom") |
19 | | - .def(py::init<std::vector<int>, common::ObservablesMask>(), |
20 | | - py::arg("detectors") = std::vector<int>(), |
21 | | - py::arg("observables") = 0) |
22 | | - .def_readwrite("detectors", &common::Symptom::detectors) |
23 | | - .def_readwrite("observables", &common::Symptom::observables) |
24 | | - .def("__str__", &common::Symptom::str) |
25 | | - .def(py::self == py::self) |
26 | | - .def(py::self != py::self); |
27 | | - |
28 | | - // TODO: add constructor with stim::DemInstruction. |
29 | | - py::class_<common::Error>(m, "Error") |
30 | | - .def_readwrite("likelihood_cost", &common::Error::likelihood_cost) |
31 | | - .def_readwrite("probability", &common::Error::probability) |
32 | | - .def_readwrite("symptom", &common::Error::symptom) |
33 | | - .def("__str__", &common::Error::str) |
34 | | - .def(py::init<>()) |
35 | | - .def(py::init<double, std::vector<int> &, common::ObservablesMask, |
36 | | - std::vector<bool> &>()) |
37 | | - .def(py::init<double, double, std::vector<int> &, common::ObservablesMask, |
38 | | - std::vector<bool> &>()); |
| 17 | +void add_common_module(py::module &root) |
| 18 | +{ |
| 19 | + auto m = root.def_submodule("common", "classes commonly used by the decoder"); |
| 20 | + |
| 21 | + py::class_<common::Symptom>(m, "Symptom") |
| 22 | + .def(py::init<std::vector<int>, common::ObservablesMask>(), |
| 23 | + py::arg("detectors") = std::vector<int>(), |
| 24 | + py::arg("observables") = 0) |
| 25 | + .def_readwrite("detectors", &common::Symptom::detectors) |
| 26 | + .def_readwrite("observables", &common::Symptom::observables) |
| 27 | + .def("__str__", &common::Symptom::str) |
| 28 | + .def(py::self == py::self) |
| 29 | + .def(py::self != py::self) |
| 30 | + .def("as_dem_instruction_targets", [](common::Symptom s) |
| 31 | + { |
| 32 | + std::vector<stim_pybind::ExposedDemTarget> ret; |
| 33 | + for(auto & t : s.as_dem_instruction_targets()) ret.emplace_back(t); |
| 34 | + return ret; }); |
| 35 | + |
| 36 | + py::class_<common::Error>(m, "Error") |
| 37 | + .def_readwrite("likelihood_cost", &common::Error::likelihood_cost) |
| 38 | + .def_readwrite("probability", &common::Error::probability) |
| 39 | + .def_readwrite("symptom", &common::Error::symptom) |
| 40 | + .def("__str__", &common::Error::str) |
| 41 | + .def(py::init<>()) |
| 42 | + .def(py::init<double, std::vector<int> &, common::ObservablesMask, |
| 43 | + std::vector<bool> &>()) |
| 44 | + .def(py::init<double, double, std::vector<int> &, common::ObservablesMask, |
| 45 | + std::vector<bool> &>()) |
| 46 | + .def(py::init([](stim_pybind::ExposedDemInstruction edi) |
| 47 | + { return new common::Error(edi.as_dem_instruction()); })); |
| 48 | + |
| 49 | + m.def("merge_identical_errors", &common::merge_identical_errors); |
| 50 | + m.def("remove_zero_probability_errors", &common::remove_zero_probability_errors); |
| 51 | + m.def("dem_from_counts", &common::dem_from_counts); |
39 | 52 | } |
40 | 53 |
|
41 | 54 | #endif |
0 commit comments