1+ // Copyright 2025 Google LLC
2+ //
3+ // Licensed under the Apache License, Version 2.0 (the "License");
4+ // you may not use this file except in compliance with the License.
5+ // You may obtain a copy of the License at
6+ //
7+ // http://www.apache.org/licenses/LICENSE-2.0
8+ //
9+ // Unless required by applicable law or agreed to in writing, software
10+ // distributed under the License is distributed on an "AS IS" BASIS,
11+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ // See the License for the specific language governing permissions and
13+ // limitations under the License.
14+
115#ifndef TESSERACT_COMMON_PY_H
216#define TESSERACT_COMMON_PY_H
317
822#include < vector>
923
1024#include " common.h"
25+ #include " src/stim/dem/dem_instruction.pybind.h"
26+ #include " stim/dem/detector_error_model_target.pybind.h"
1127
1228namespace py = pybind11;
1329
1430void add_common_module (py::module &root) {
1531 auto m = root.def_submodule (" common" , " classes commonly used by the decoder" );
1632
17- // TODO: add as_dem_instruction_targets
1833 py::class_<common::Symptom>(m, " Symptom" )
1934 .def (py::init<std::vector<int >, common::ObservablesMask>(),
2035 py::arg (" detectors" ) = std::vector<int >(),
@@ -23,19 +38,38 @@ void add_common_module(py::module &root) {
2338 .def_readwrite (" observables" , &common::Symptom::observables)
2439 .def (" __str__" , &common::Symptom::str)
2540 .def (py::self == py::self)
26- .def (py::self != py::self);
41+ .def (py::self != py::self)
42+ .def (" as_dem_instruction_targets" , [](common::Symptom s) {
43+ std::vector<stim_pybind::ExposedDemTarget> ret;
44+ for (auto &t : s.as_dem_instruction_targets ()) ret.emplace_back (t);
45+ return ret;
46+ });
2747
28- // TODO: add constructor with stim::DemInstruction.
2948 py::class_<common::Error>(m, " Error" )
3049 .def_readwrite (" likelihood_cost" , &common::Error::likelihood_cost)
3150 .def_readwrite (" probability" , &common::Error::probability)
3251 .def_readwrite (" symptom" , &common::Error::symptom)
3352 .def (" __str__" , &common::Error::str)
3453 .def (py::init<>())
3554 .def (py::init<double , std::vector<int > &, common::ObservablesMask,
36- std::vector<bool > &>())
55+ std::vector<bool > &>(),
56+ py::arg (" likelihood_cost" ), py::arg (" detectors" ),
57+ py::arg (" observables" ), py::arg (" dets_array" ))
3758 .def (py::init<double , double , std::vector<int > &, common::ObservablesMask,
38- std::vector<bool > &>());
59+ std::vector<bool > &>(),
60+ py::arg (" likelihood_cost" ), py::arg (" probability" ),
61+ py::arg (" detectors" ), py::arg (" observables" ), py::arg (" dets_array" ))
62+ .def (py::init ([](stim_pybind::ExposedDemInstruction edi) {
63+ return new common::Error (edi.as_dem_instruction ());
64+ }),
65+ py::arg (" error" ));
66+
67+ m.def (" merge_identical_errors" , &common::merge_identical_errors,
68+ py::arg (" dem" ));
69+ m.def (" remove_zero_probability_errors" ,
70+ &common::remove_zero_probability_errors, py::arg (" dem" ));
71+ m.def (" dem_from_counts" , &common::dem_from_counts, py::arg (" orig_dem" ),
72+ py::arg (" error_counts" ), py::arg (" num_shots" ));
3973}
4074
4175#endif
0 commit comments