Skip to content

Commit 6379a82

Browse files
Better default arguments for Tesseract config
1 parent ad65b82 commit 6379a82

File tree

3 files changed

+36
-28
lines changed

3 files changed

+36
-28
lines changed

src/py/tesseract_test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def test_create_node():
4949
def test_create_tesseract_config():
5050
assert (
5151
str(tesseract_decoder.tesseract.TesseractConfig(_DETECTOR_ERROR_MODEL))
52-
== "TesseractConfig(dem=DetectorErrorModel_Object, det_beam=65535, no_revisit_dets=0, at_most_two_errors_per_detector=0, verbose=0, merge_errors=1, pqlimit=18446744073709551615, det_orders=[], det_penalty=0, create_visualization=0)"
52+
== "TesseractConfig(dem=DetectorErrorModel_Object, det_beam=5, no_revisit_dets=1, at_most_two_errors_per_detector=0, verbose=0, merge_errors=1, pqlimit=200000, det_orders=[[1, 0], [0, 1], [1, 0], [0, 1], [1, 0], [0, 1], [1, 0], [1, 0], [0, 1], [1, 0], [1, 0], [1, 0], [0, 1], [0, 1], [0, 1], [1, 0], [0, 1], [0, 1], [1, 0], [1, 0]], det_penalty=0, create_visualization=0)"
5353
)
5454
assert (
5555
tesseract_decoder.tesseract.TesseractConfig(_DETECTOR_ERROR_MODEL).dem
@@ -66,7 +66,7 @@ def test_create_tesseract_config_with_dem():
6666
# Assert the string representation matches the expected format.
6767
assert (
6868
str(config)
69-
== "TesseractConfig(dem=DetectorErrorModel_Object, det_beam=65535, no_revisit_dets=0, at_most_two_errors_per_detector=0, verbose=0, merge_errors=1, pqlimit=18446744073709551615, det_orders=[], det_penalty=0, create_visualization=0)"
69+
== "TesseractConfig(dem=DetectorErrorModel_Object, det_beam=5, no_revisit_dets=1, at_most_two_errors_per_detector=0, verbose=0, merge_errors=1, pqlimit=200000, det_orders=[[1, 0], [0, 1], [1, 0], [0, 1], [1, 0], [0, 1], [1, 0], [1, 0], [0, 1], [1, 0], [1, 0], [1, 0], [0, 1], [0, 1], [0, 1], [1, 0], [0, 1], [0, 1], [1, 0], [1, 0]], det_penalty=0, create_visualization=0)"
7070
)
7171

7272
# Assert that the `dem` attribute is correctly set.
@@ -93,7 +93,7 @@ def test_create_tesseract_config_with_dem_and_custom_args():
9393
# Assert the string representation is as expected.
9494
assert (
9595
str(config)
96-
== "TesseractConfig(dem=DetectorErrorModel_Object, det_beam=100, no_revisit_dets=0, at_most_two_errors_per_detector=0, verbose=0, merge_errors=0, pqlimit=18446744073709551615, det_orders=[], det_penalty=0.5, create_visualization=0)"
96+
== "TesseractConfig(dem=DetectorErrorModel_Object, det_beam=100, no_revisit_dets=1, at_most_two_errors_per_detector=0, verbose=0, merge_errors=0, pqlimit=200000, det_orders=[[1, 0], [0, 1], [1, 0], [0, 1], [1, 0], [0, 1], [1, 0], [1, 0], [0, 1], [1, 0], [1, 0], [1, 0], [0, 1], [0, 1], [0, 1], [1, 0], [0, 1], [0, 1], [1, 0], [1, 0]], det_penalty=0.5, create_visualization=0)"
9797
)
9898

9999
def test_compile_decoder_for_dem_basic_functionality():
@@ -164,7 +164,7 @@ def test_create_tesseract_config_no_dem():
164164
# Assert that the string representation shows the default values.
165165
assert (
166166
str(config_default)
167-
== "TesseractConfig(dem=DetectorErrorModel_Object, det_beam=65535, no_revisit_dets=0, at_most_two_errors_per_detector=0, verbose=0, merge_errors=1, pqlimit=18446744073709551615, det_orders=[], det_penalty=0, create_visualization=0)"
167+
== "TesseractConfig(dem=DetectorErrorModel_Object, det_beam=5, no_revisit_dets=1, at_most_two_errors_per_detector=0, verbose=0, merge_errors=1, pqlimit=200000, det_orders=[], det_penalty=0, create_visualization=0)"
168168
)
169169

170170
def test_create_tesseract_config_no_dem_with_custom_args():
@@ -184,7 +184,7 @@ def test_create_tesseract_config_no_dem_with_custom_args():
184184
# Assert that the string representation reflects the custom values.
185185
assert (
186186
str(config_custom)
187-
== "TesseractConfig(dem=DetectorErrorModel_Object, det_beam=15, no_revisit_dets=0, at_most_two_errors_per_detector=0, verbose=1, merge_errors=1, pqlimit=18446744073709551615, det_orders=[], det_penalty=0, create_visualization=0)"
187+
== "TesseractConfig(dem=DetectorErrorModel_Object, det_beam=15, no_revisit_dets=1, at_most_two_errors_per_detector=0, verbose=1, merge_errors=1, pqlimit=200000, det_orders=[[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], []], det_penalty=0, create_visualization=0)"
188188
)
189189

190190

src/tesseract.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,18 @@
2828
#include "visualization.h"
2929

3030
constexpr size_t INF_DET_BEAM = std::numeric_limits<uint16_t>::max();
31+
constexpr int DEFAULT_DET_BEAM = 5;
32+
constexpr size_t DEFAULT_PQLIMIT = 200000;
3133

3234
struct TesseractConfig {
3335
stim::DetectorErrorModel dem;
34-
int det_beam = INF_DET_BEAM;
36+
int det_beam = DEFAULT_DET_BEAM;
3537
bool beam_climbing = false;
36-
bool no_revisit_dets = false;
38+
bool no_revisit_dets = true;
3739
bool at_most_two_errors_per_detector = false;
3840
bool verbose = false;
3941
bool merge_errors = true;
40-
size_t pqlimit = std::numeric_limits<size_t>::max();
42+
size_t pqlimit = DEFAULT_PQLIMIT;
4143
std::vector<std::vector<size_t>> det_orders;
4244
double det_penalty = 0;
4345
bool create_visualization = false;

src/tesseract.pybind.h

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include "stim_utils.pybind.h"
2525
#include "tesseract.h"
26+
#include "utils.h"
2627

2728
namespace py = pybind11;
2829

@@ -32,30 +33,35 @@ std::unique_ptr<TesseractDecoder> _compile_tesseract_decoder_helper(const Tesser
3233
return std::make_unique<TesseractDecoder>(self);
3334
}
3435

35-
TesseractConfig tesseract_config_maker_no_dem(
36-
int det_beam = INF_DET_BEAM, bool beam_climbing = false, bool no_revisit_dets = false,
37-
bool at_most_two_errors_per_detector = false, bool verbose = false, bool merge_errors = true,
38-
size_t pqlimit = std::numeric_limits<size_t>::max(),
39-
std::vector<std::vector<size_t>> det_orders = std::vector<std::vector<size_t>>(),
40-
double det_penalty = 0.0, bool create_visualization = false) {
36+
TesseractConfig tesseract_config_maker_no_dem(int det_beam, bool beam_climbing,
37+
bool no_revisit_dets,
38+
bool at_most_two_errors_per_detector, bool verbose,
39+
bool merge_errors, size_t pqlimit,
40+
std::vector<std::vector<size_t>> det_orders,
41+
double det_penalty, bool create_visualization) {
4142
stim::DetectorErrorModel empty_dem;
43+
if (det_orders.empty()) {
44+
det_orders = build_det_orders(empty_dem, 20, true, 2384753);
45+
}
4246
return TesseractConfig({empty_dem, det_beam, beam_climbing, no_revisit_dets,
4347
at_most_two_errors_per_detector, verbose, merge_errors, pqlimit,
4448
det_orders, det_penalty, create_visualization});
4549
}
4650

47-
TesseractConfig tesseract_config_maker(
48-
py::object dem, int det_beam = INF_DET_BEAM, bool beam_climbing = false,
49-
bool no_revisit_dets = false, bool at_most_two_errors_per_detector = false,
50-
bool verbose = false, bool merge_errors = true,
51-
size_t pqlimit = std::numeric_limits<size_t>::max(),
52-
std::vector<std::vector<size_t>> det_orders = std::vector<std::vector<size_t>>(),
53-
double det_penalty = 0.0, bool create_visualization = false) {
54-
stim::DetectorErrorModel input_dem = parse_py_object<stim::DetectorErrorModel>(dem);
51+
TesseractConfig tesseract_config_maker(py::object dem_obj, int det_beam, bool beam_climbing,
52+
bool no_revisit_dets, bool at_most_two_errors_per_detector,
53+
bool verbose, bool merge_errors, size_t pqlimit,
54+
std::vector<std::vector<size_t>> det_orders,
55+
double det_penalty, bool create_visualization) {
56+
stim::DetectorErrorModel input_dem = parse_py_object<stim::DetectorErrorModel>(dem_obj);
57+
if (det_orders.empty()) {
58+
det_orders = build_det_orders(input_dem, 20, true, 2384753);
59+
}
5560
return TesseractConfig({input_dem, det_beam, beam_climbing, no_revisit_dets,
5661
at_most_two_errors_per_detector, verbose, merge_errors, pqlimit,
5762
det_orders, det_penalty, create_visualization});
5863
}
64+
5965
}; // namespace
6066
void add_tesseract_module(py::module& root) {
6167
auto m = root.def_submodule("tesseract", "Module containing the tesseract algorithm");
@@ -73,10 +79,10 @@ void add_tesseract_module(py::module& root) {
7379
Default constructor for TesseractConfig.
7480
Creates a new instance with default parameter values.
7581
)pbdoc")
76-
.def(py::init(&tesseract_config_maker_no_dem), py::arg("det_beam") = INF_DET_BEAM,
77-
py::arg("beam_climbing") = false, py::arg("no_revisit_dets") = false,
82+
.def(py::init(&tesseract_config_maker_no_dem), py::arg("det_beam") = 5,
83+
py::arg("beam_climbing") = false, py::arg("no_revisit_dets") = true,
7884
py::arg("at_most_two_errors_per_detector") = false, py::arg("verbose") = false,
79-
py::arg("merge_errors") = true, py::arg("pqlimit") = std::numeric_limits<size_t>::max(),
85+
py::arg("merge_errors") = true, py::arg("pqlimit") = 200000,
8086
py::arg("det_orders") = std::vector<std::vector<size_t>>(), py::arg("det_penalty") = 0.0,
8187
py::arg("create_visualization") = false,
8288
R"pbdoc(
@@ -108,10 +114,10 @@ void add_tesseract_module(py::module& root) {
108114
create_visualization: bool, defualt=False
109115
Whether to record the information needed to create a visualization or not.
110116
)pbdoc")
111-
.def(py::init(&tesseract_config_maker), py::arg("dem"), py::arg("det_beam") = INF_DET_BEAM,
112-
py::arg("beam_climbing") = false, py::arg("no_revisit_dets") = false,
117+
.def(py::init(&tesseract_config_maker), py::arg("dem"), py::arg("det_beam") = 5,
118+
py::arg("beam_climbing") = false, py::arg("no_revisit_dets") = true,
113119
py::arg("at_most_two_errors_per_detector") = false, py::arg("verbose") = false,
114-
py::arg("merge_errors") = true, py::arg("pqlimit") = std::numeric_limits<size_t>::max(),
120+
py::arg("merge_errors") = true, py::arg("pqlimit") = 200000,
115121
py::arg("det_orders") = std::vector<std::vector<size_t>>(), py::arg("det_penalty") = 0.0,
116122
py::arg("create_visualization") = false,
117123
R"pbdoc(

0 commit comments

Comments
 (0)