Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,53 @@ http_archive(
urls = ["https://github.com/bazelbuild/platforms/archive/refs/tags/0.0.6.zip"],
strip_prefix = "platforms-0.0.6",
)

http_archive(
name = "rules_python",
sha256 = "62ddebb766b4d6ddf1712f753dac5740bea072646f630eb9982caa09ad8a7687",
strip_prefix = "rules_python-0.39.0",
url = "https://github.com/bazelbuild/rules_python/releases/download/0.39.0/rules_python-0.39.0.tar.gz",
)


load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "rules_proto",
sha256 = "14a225870ab4e91869652cfd69ef2028277fc1dc4910d65d353b62d6e0ae21f4",
strip_prefix = "rules_proto-7.1.0",
url = "https://github.com/bazelbuild/rules_proto/releases/download/7.1.0/rules_proto-7.1.0.tar.gz",
)

load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies")
rules_proto_dependencies()

load("@rules_proto//proto:toolchains.bzl", "rules_proto_toolchains")
rules_proto_toolchains()


load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_toolchains")

py_repositories()

python_register_toolchains(
name = "python",
ignore_root_user_error = True,
python_version = "3.12",
)


http_archive(
name = "pybind11_bazel",
strip_prefix = "pybind11_bazel-2.13.6",
sha256 = "9df284330336958c837fb70dc34c0a6254dac52a5c983b3373a8c2bbb79ac35e",
urls = ["https://github.com/pybind/pybind11_bazel/archive/v2.13.6.zip"],
)
# We still require the pybind library.
http_archive(
name = "pybind11",
build_file = "@pybind11_bazel//:pybind11-BUILD.bazel",
strip_prefix = "pybind11-2.13.6",
sha256 = "d0a116e91f64a4a2d8fb7590c34242df92258a61ec644b79127951e821b47be6",
urls = ["https://github.com/pybind/pybind11/archive/v2.13.6.zip"],
)
23 changes: 23 additions & 0 deletions src/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# limitations under the License.

# load("@benchmark//:benchmark.bzl", "cc_benchmark")
load("@pybind11_bazel//:build_defs.bzl", "pybind_extension")
load("@rules_python//python:defs.bzl", "py_library")

package(default_visibility = ["//visibility:public"])

Expand Down Expand Up @@ -63,6 +65,26 @@ cc_library(
],
)


pybind_extension(
name = "tesseract_py",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
name = "tesseract_py",
name = "tesseract_decoder",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done ... I also changed the names of the pybind11 files to match the convention used by stem

srcs = [
"common_py.h",
"tesseract_py.cc",
],
deps = [
":libcommon",
],
)


py_library(
name="libtesseract_py",
data=[":tesseract_py"],
imports=["src"],
)


cc_library(
name = "libutils",
srcs = ["utils.cc"],
Expand Down Expand Up @@ -171,3 +193,4 @@ cc_binary(
"@nlohmann_json//:json",
],
)

38 changes: 38 additions & 0 deletions src/common_py.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#ifndef TESSERACT_COMMON_PY_H
#define TESSERACT_COMMON_PY_H

#include <vector>

#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <pybind11/operators.h>

#include "common.h"

namespace py = pybind11;

void add_common_module(py::module &root)
{
auto m = root.def_submodule("common", "classes commonly used by the decoder");

// TODO: add as_dem_instruction_targets
py::class_<common::Symptom>(m, "Symptom")
.def(py::init<std::vector<int>, common::ObservablesMask>(), py::arg("detectors") = std::vector<int>(), py::arg("observables") = 0)
.def_readwrite("detectors", &common::Symptom::detectors)
.def_readwrite("observables", &common::Symptom::observables)
.def("__str__", &common::Symptom::str)
.def(py::self == py::self)
.def(py::self != py::self);

// TODO: add constructor with stim::DemInstruction.
py::class_<common::Error>(m, "Error")
.def_readwrite("likelihood_cost", &common::Error::likelihood_cost)
.def_readwrite("probability", &common::Error::probability)
.def_readwrite("symptom", &common::Error::symptom)
.def("__str__", &common::Error::str)
.def(py::init<>())
.def(py::init<double, std::vector<int> &, common::ObservablesMask, std::vector<bool> &>())
.def(py::init<double, double, std::vector<int> &, common::ObservablesMask, std::vector<bool> &>());
}

#endif
9 changes: 9 additions & 0 deletions src/tesseract_py.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <pybind11/pybind11.h>
#include "pybind11/detail/common.h"

#include "common_py.h"

PYBIND11_MODULE(tesseract_py, m)
{
add_common_module(m);
}