Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Windows fatal exception: access violation bug for pybind11 >v2.12 #99

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
CIBW_ARCHS_MACOS: "x86_64 universal2 arm64"
CIBW_BEFORE_BUILD: pip install --upgrade ninja
CIBW_TEST_REQUIRES: pytest stim
CIBW_TEST_COMMAND: pytest {project}/tests
CIBW_TEST_COMMAND: pytest {project}/tests -s
strategy:
fail-fast: false
matrix:
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ FetchContent_MakeAvailable(googletest)

FetchContent_Declare(stim
GIT_REPOSITORY https://github.com/quantumlib/Stim.git
GIT_TAG da4594c5ede00a063ec2b84bd830f846b5d097dd)
GIT_TAG fd8c95520941627d82b6453d9654d9c4dfb06020)
FetchContent_MakeAvailable(stim)
if (NOT (MSVC))
target_compile_options(libstim PRIVATE -fno-strict-aliasing -fPIC ${ARCH_OPT})
Expand Down
2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

git_repository(
name = "stim",
commit = "3e38d12d0a0fb3022646b694137b733a4700d300",
commit = "fd8c95520941627d82b6453d9654d9c4dfb06020",
remote = "https://github.com/quantumlib/stim.git",
)

Expand Down
2 changes: 1 addition & 1 deletion pybind11
Submodule pybind11 updated 157 files
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def build_extension(self, ext):
'console_scripts': ['pymatching=pymatching._cli_argv:cli_argv'],
},
python_requires=">=3.7",
install_requires=['scipy', 'numpy', 'networkx', 'matplotlib'],
install_requires=['scipy', 'numpy==1.*', 'networkx', 'matplotlib'],
# Needed on Windows to avoid the default `build` colliding with Bazel's `BUILD`.
options={'build': {'build_base': 'python_build_stim'}},
)
2 changes: 2 additions & 0 deletions src/pymatching/matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,9 @@ def decode_to_matched_dets_dict(self,
>>> d
{0: None, 3: 4, 4: 3}
"""
print(f"syndrome: {syndrome}", flush=True)
detection_events = self._syndrome_array_to_detection_events(syndrome)
print(f"detection_events: {detection_events}", flush=True)
return self._matching_graph.decode_to_matched_detection_events_dict(detection_events)

def draw(self) -> None:
Expand Down
6 changes: 4 additions & 2 deletions src/pymatching/sparse_blossom/arena.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ struct Arena {
}

~Arena() {
std::cout << "Arena0" << std::endl;
std::vector<T *> to_free = std::move(allocated);
std::vector<T *> not_in_use = std::move(available);

std::cout << "Arena1" << std::endl;
// Destruct the objects that were still in use.
std::sort(to_free.begin(), to_free.end());
std::sort(not_in_use.begin(), not_in_use.end());
Expand All @@ -75,11 +76,12 @@ struct Arena {
kf++;
}
}

std::cout << "Arena2" << std::endl;
// Free all allocated memory.
for (T *v : to_free) {
free(v);
}
std::cout << "Arena3" << std::endl;
}
};
} // namespace pm
Expand Down
5 changes: 4 additions & 1 deletion src/pymatching/sparse_blossom/driver/mwpm_decoding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

#include "pymatching/sparse_blossom/driver/mwpm_decoding.h"
#include <stdexcept>

pm::ExtendedMatchingResult::ExtendedMatchingResult() : obs_crossed(), weight(0) {
}
Expand Down Expand Up @@ -210,9 +211,11 @@ void pm::decode_detection_events(
}

void pm::decode_detection_events_to_match_edges(pm::Mwpm& mwpm, const std::vector<uint64_t>& detection_events) {
if (mwpm.flooder.negative_weight_sum != 0)
if (mwpm.flooder.negative_weight_sum != 0) {
std::cout << "mwpm.flooder.negative_weight_sum = " << mwpm.flooder.negative_weight_sum << " != 0" << std::endl;
throw std::invalid_argument(
"Decoding to matched detection events not supported for graphs containing edges with negative weights.");
}
process_timeline_until_completion(mwpm, detection_events);
mwpm.flooder.match_edges.clear();
shatter_blossoms_for_all_detection_events_and_extract_match_edges(mwpm, detection_events);
Expand Down
20 changes: 20 additions & 0 deletions src/pymatching/sparse_blossom/driver/user_graph.pybind.cc
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,32 @@ void pm_pybind::pybind_user_graph_methods(py::module &m, py::class_<pm::UserGrap
g.def(
"decode_to_matched_detection_events_array",
[](pm::UserGraph &self, const py::array_t<uint64_t> &detection_events) {
std::cout << "B0" << std::endl;
auto &mwpm = self.get_mwpm();
std::cout << "B1" << std::endl;
std::vector<uint64_t> detection_events_vec(
detection_events.data(), detection_events.data() + detection_events.size());
std::cout << "B2" << std::endl;
std::cout << "detection_events_vec.size(): " << detection_events_vec.size()
<< "\nentries: ";
for (auto& i : detection_events_vec) {
std::cout << i << " ";
}
std::cout << std::endl;
std::cout << "mwpm.flooder.negative_weight_sum: " << mwpm.flooder.negative_weight_sum << std::endl;
if (mwpm.flooder.negative_weight_sum != 0) {
throw py::value_error(
"Decoding to matched detection events not supported for graphs containing edges with negative weights.");
}
pm::decode_detection_events_to_match_edges(mwpm, detection_events_vec);
std::cout << "B3" << std::endl;
py::ssize_t num_edges = (py::ssize_t)(mwpm.flooder.match_edges.size());
std::cout << "B4" << std::endl;
py::array_t<int64_t> match_edges = py::array_t<int64_t>(num_edges * 2);
std::cout << "B5" << std::endl;
py::buffer_info buff = match_edges.request();
int64_t *ptr = (int64_t *)buff.ptr;
std::cout << "B6" << std::endl;

// Convert match edges to a vector of int64_t
for (size_t i = 0; i < mwpm.flooder.match_edges.size(); i++) {
Expand All @@ -233,8 +251,10 @@ void pm_pybind::pybind_user_graph_methods(py::module &m, py::class_<pm::UserGrap
ptr[2 * i + 1] = -1;
}
}
std::cout << "B7" << std::endl;
// Reshape the array
match_edges.resize({(py::ssize_t)num_edges, (py::ssize_t)2});
std::cout << "B8" << std::endl;
return match_edges;
},
"detection_events"_a);
Expand Down
Loading