From 2ec5f5276ccadb49dfd9d692be268a60831625a3 Mon Sep 17 00:00:00 2001 From: Nour Yosri Date: Tue, 10 Jun 2025 18:10:15 -0700 Subject: [PATCH 1/7] fix pybind11 build --- src/py/BUILD | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/py/BUILD b/src/py/BUILD index 9f24e4c..b1b6383 100644 --- a/src/py/BUILD +++ b/src/py/BUILD @@ -1,14 +1,17 @@ -load("@rules_python//python:py_test.bzl", "py_test") +load("@rules_python//python:py_library.bzl", "py_library") +load("@rules_python//python:py_binary.bzl", "py_binary") load("@rules_python//python:pip.bzl", "compile_pip_requirements") -py_test( - name = "common_test", - srcs = ["common_test.py"], +py_binary( + name = "tmp", + srcs = ["tmp.py"], visibility = ["//:__subpackages__"], deps = [ - "@pypi//pytest", + "@pypi//numpy", + "@pypi//stim", "//src:lib_tesseract_decoder", ], + # imports = ["//src:lib_tesseract_decoder"], ) py_test( From d2d884f83ecfe76af5ffdfebea82b2fe1b61e01c Mon Sep 17 00:00:00 2001 From: Nour Yosri Date: Tue, 10 Jun 2025 19:58:29 -0700 Subject: [PATCH 2/7] link tesseract with stim and add tests for the python wrapper of common.h --- src/py/BUILD | 13 +++++-------- src/py/common_test.py | 1 + 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/py/BUILD b/src/py/BUILD index b1b6383..9f24e4c 100644 --- a/src/py/BUILD +++ b/src/py/BUILD @@ -1,17 +1,14 @@ -load("@rules_python//python:py_library.bzl", "py_library") -load("@rules_python//python:py_binary.bzl", "py_binary") +load("@rules_python//python:py_test.bzl", "py_test") load("@rules_python//python:pip.bzl", "compile_pip_requirements") -py_binary( - name = "tmp", - srcs = ["tmp.py"], +py_test( + name = "common_test", + srcs = ["common_test.py"], visibility = ["//:__subpackages__"], deps = [ - "@pypi//numpy", - "@pypi//stim", + "@pypi//pytest", "//src:lib_tesseract_decoder", ], - # imports = ["//src:lib_tesseract_decoder"], ) py_test( diff --git a/src/py/common_test.py b/src/py/common_test.py index b059a41..3ed0902 100644 --- a/src/py/common_test.py +++ b/src/py/common_test.py @@ -15,6 +15,7 @@ import pytest import stim +# import tesseract_decoder from src import tesseract_decoder From bd4ce6c124bb71fe817f432e78c5cee734caf2b4 Mon Sep 17 00:00:00 2001 From: Nour Yosri Date: Tue, 10 Jun 2025 20:01:06 -0700 Subject: [PATCH 3/7] nit --- src/py/common_test.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/py/common_test.py b/src/py/common_test.py index 3ed0902..b059a41 100644 --- a/src/py/common_test.py +++ b/src/py/common_test.py @@ -15,7 +15,6 @@ import pytest import stim -# import tesseract_decoder from src import tesseract_decoder From a066b2e74d5d19a039c423a37e5b77ec1388e73a Mon Sep 17 00:00:00 2001 From: Nour Yosri Date: Wed, 11 Jun 2025 23:19:41 -0700 Subject: [PATCH 4/7] Expose all of tesseract to python --- src/tesseract.pybind.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/tesseract.pybind.cc b/src/tesseract.pybind.cc index 4c35029..a4de726 100644 --- a/src/tesseract.pybind.cc +++ b/src/tesseract.pybind.cc @@ -15,8 +15,6 @@ #include "tesseract.pybind.h" #include - -#include "common.pybind.h" #include "pybind11/detail/common.h" #include "simplex.pybind.h" #include "utils.pybind.h" From 6354a3ff09ea8715181f68e0a7a5b9511dc63e34 Mon Sep 17 00:00:00 2001 From: Nour Yosri Date: Tue, 24 Jun 2025 16:00:33 -0700 Subject: [PATCH 5/7] Add py_wheel rule, clean old rules and canonize python version --- MODULE.bazel | 5 +++- WORKSPACE | 8 ------ external/stim_py.BUILD | 64 ------------------------------------------ src/BUILD | 17 +++++++++-- src/py/BUILD | 4 +++ 5 files changed, 22 insertions(+), 76 deletions(-) delete mode 100644 external/stim_py.BUILD diff --git a/MODULE.bazel b/MODULE.bazel index 98f03c8..0404c79 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -8,6 +8,9 @@ bazel_dep(name = "pybind11_bazel", version = "2.13.6") DEFAULT_PYTHON_VERSION = "3.11" +python = use_extension("@rules_python//python/extensions:python.bzl", "python") +python.toolchain(python_version = DEFAULT_PYTHON_VERSION, is_default = True) + python_configure = use_extension("@pybind11_bazel//:python_configure.bzl", "extension") use_repo(python_configure, "local_config_python") @@ -16,7 +19,7 @@ pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip") pip.parse( hub_name = "pypi", - python_version = "3.11", + python_version = DEFAULT_PYTHON_VERSION, requirements_lock = "//src/py:requirements_lock.txt", ) diff --git a/WORKSPACE b/WORKSPACE index c2af5ef..ded3a8f 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -66,11 +66,3 @@ http_archive( urls = ["https://github.com/bazelbuild/platforms/archive/refs/tags/0.0.6.zip"], strip_prefix = "platforms-0.0.6", ) - -http_archive( - name = "stim_py", - build_file = "//external:stim_py.BUILD", - sha256 = "95236006859d6754be99629d4fb44788e742e962ac8c59caad421ca088f7350e", - strip_prefix = "stim-1.15.0", - urls = ["https://github.com/quantumlib/Stim/releases/download/v1.15.0/stim-1.15.0.tar.gz"], -) diff --git a/external/stim_py.BUILD b/external/stim_py.BUILD deleted file mode 100644 index 7c14e00..0000000 --- a/external/stim_py.BUILD +++ /dev/null @@ -1,64 +0,0 @@ -load("@pybind11_bazel//:build_defs.bzl", "pybind_library") -load("@pybind11_bazel//:build_defs.bzl", "pybind_extension") - -SOURCE_FILES_NO_MAIN = glob( - [ - "src/**/*.cc", - "src/**/*.h", - "src/**/*.inl", - ], - exclude = glob([ - "src/**/*.test.cc", - "src/**/*.test.h", - "src/**/*.perf.cc", - "src/**/*.perf.h", - "src/**/*.pybind.cc", - "src/**/*.pybind.h", - "src/**/main.cc", - ]), -) - -PYBIND_MODULES = [ - "src/stim/py/march.pybind.cc", - "src/stim/py/stim.pybind.cc", -] - -PYBIND_FILES_WITHOUT_MODULES = glob( - [ - "src/**/*.pybind.cc", - "src/**/*.pybind.h", - ], - exclude=PYBIND_MODULES, -) - - - -pybind_library( - name = "stim_pybind_lib", - srcs = SOURCE_FILES_NO_MAIN + PYBIND_FILES_WITHOUT_MODULES, - copts = [ - "-O3", - "-std=c++20", - "-fvisibility=hidden", - "-march=native", - "-DVERSION_INFO=0.0.dev0", - ], - includes = ["src/"], - visibility = ["//visibility:public"], -) - -pybind_extension( - name = "stim", - srcs = PYBIND_MODULES, - copts = [ - "-O3", - "-std=c++20", - "-fvisibility=hidden", - "-march=native", - "-DSTIM_PYBIND11_MODULE_NAME=stim", - "-DVERSION_INFO=0.0.dev0", - ], - deps=[":stim_pybind_lib"], - includes = ["src/"], - visibility = ["//visibility:public"], -) diff --git a/src/BUILD b/src/BUILD index a222eaf..b2cc362 100644 --- a/src/BUILD +++ b/src/BUILD @@ -15,6 +15,7 @@ # load("@benchmark//:benchmark.bzl", "cc_benchmark") load("@pybind11_bazel//:build_defs.bzl", "pybind_extension", "pybind_library") load("@rules_python//python:defs.bzl", "py_library") +load("@rules_python//python:packaging.bzl", "py_wheel") package(default_visibility = ["//visibility:public"]) @@ -63,7 +64,6 @@ cc_library( ], ) - pybind_library( name = "tesseract_decoder_pybind", srcs = [ @@ -77,7 +77,7 @@ pybind_library( ":libutils", ":libsimplex", ":libtesseract", - "@stim_py//:stim_pybind_lib", + "@stim//:stim_pybind_lib", ], ) @@ -88,10 +88,20 @@ pybind_extension( ], deps = [ ":tesseract_decoder_pybind", - "@stim_py//:stim", ], ) +py_wheel( + name="tesseract_decoder_wheel", + distribution = "tesseract_decoder", + deps=[ + ":tesseract_decoder", + ], + version = "0.0.dev0", + requires=[ + "stim", + ], +) py_library( name="lib_tesseract_decoder", @@ -214,3 +224,4 @@ cc_binary( ], ) + diff --git a/src/py/BUILD b/src/py/BUILD index 9f24e4c..7bc4a4f 100644 --- a/src/py/BUILD +++ b/src/py/BUILD @@ -7,6 +7,7 @@ py_test( visibility = ["//:__subpackages__"], deps = [ "@pypi//pytest", + "@pypi//stim", "//src:lib_tesseract_decoder", ], ) @@ -17,6 +18,7 @@ py_test( visibility = ["//:__subpackages__"], deps = [ "@pypi//pytest", + "@pypi//stim", "//src:lib_tesseract_decoder", ], ) @@ -27,6 +29,7 @@ py_test( visibility = ["//:__subpackages__"], deps = [ "@pypi//pytest", + "@pypi//stim", "//src:lib_tesseract_decoder", ], ) @@ -37,6 +40,7 @@ py_test( visibility = ["//:__subpackages__"], deps = [ "@pypi//pytest", + "@pypi//stim", "//src:lib_tesseract_decoder", ], ) From 627c15794cedbf774448e4e8100e1ae0c1f12c5f Mon Sep 17 00:00:00 2001 From: Nour Yosri Date: Tue, 24 Jun 2025 16:06:06 -0700 Subject: [PATCH 6/7] format --- src/tesseract.pybind.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/tesseract.pybind.cc b/src/tesseract.pybind.cc index a4de726..ff0bf75 100644 --- a/src/tesseract.pybind.cc +++ b/src/tesseract.pybind.cc @@ -12,12 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "tesseract.pybind.h" -#include #include "pybind11/detail/common.h" +#include + +#include "common.pybind.h" #include "simplex.pybind.h" #include "utils.pybind.h" +#include "tesseract.pybind.h" PYBIND11_MODULE(tesseract_decoder, tesseract) { py::module::import("stim"); From cc6f9bf93c5a2a89d1914aa7467e9c37b2b060b8 Mon Sep 17 00:00:00 2001 From: Nour Yosri Date: Wed, 25 Jun 2025 11:25:59 -0700 Subject: [PATCH 7/7] format --- src/tesseract.pybind.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tesseract.pybind.cc b/src/tesseract.pybind.cc index ff0bf75..4c35029 100644 --- a/src/tesseract.pybind.cc +++ b/src/tesseract.pybind.cc @@ -12,14 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "tesseract.pybind.h" -#include "pybind11/detail/common.h" #include #include "common.pybind.h" +#include "pybind11/detail/common.h" #include "simplex.pybind.h" #include "utils.pybind.h" -#include "tesseract.pybind.h" PYBIND11_MODULE(tesseract_decoder, tesseract) { py::module::import("stim");