Skip to content

Commit

Permalink
remove BlossomV
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarhiggott committed Nov 21, 2020
1 parent b1832d9 commit 3db1b54
Show file tree
Hide file tree
Showing 12 changed files with 17 additions and 319 deletions.
6 changes: 0 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ add_compile_definitions(PERFECT_MATCHING_DOUBLE)

file(GLOB SOURCES "src/pymatching/*.cpp")

add_subdirectory(lib/blossom5-v2.05.src)
target_compile_options(Blossom5 PRIVATE "-fPIC")

add_subdirectory(lib/pybind11)
pybind11_add_module(_cpp_mwpm ${SOURCES})

Expand All @@ -19,11 +16,8 @@ target_link_libraries(_cpp_mwpm PRIVATE lemon)

include_directories(${CMAKE_SOURCE_DIR}/lib/boost_1_72_0)

target_link_libraries(_cpp_mwpm PRIVATE Blossom5)

target_include_directories(_cpp_mwpm PRIVATE
"${PROJECT_BINARY_DIR}"
"${PROJECT_SOURCE_DIR}/lib/blossom5-v2.05.src"
"${CMAKE_SOURCE_DIR}/lib/lemon"
"${CMAKE_BINARY_DIR}/lib/lemon"
)
Expand Down
Binary file modified docs/_static/pymatching_vs_networkx.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 16 additions & 9 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,31 @@ While a Python library such as NetworkX can also be used to
implement MWPM, it is far too slow to be used for large
fault-tolerance simulations, which often require
matching graphs with many thousands of nodes. On the other hand,
the excellent C++ BlossomV library is fast, but using it to decode
the widly used C++ BlossomV library is fast, but using it to decode
quantum codes also requires path-finding algorithms, which must
also be implemented in C++ for a fast implementation. Furthermore,
attempting to solve the full matching problem even with BlossomV
can become prohibitively expensive for matching graphs with more
than a few thousand nodes, since the average complexity is
empirically roughly quadratic in the number of nodes.
empirically roughly quadratic in the number of nodes. BlossomV
is also not open-source since it does not have a permissive license.

PyMatching is intended to provide the best of both
worlds: the algorithms and data structures are implemented
in C++ for good performance (with the help of BlossomV and the Boost Graph library),
worlds: all the
core functionality of PyMatching is useable via the Python
bindings, making it easy to use
in conjunction with numpy, scipy and NetworkX. However the
core algorithms and data structures are implemented
in C++ for good performance (with the help of the open-source
Lemon and the Boost Graph libraries),
using a local variant of the matching decoder given in the
Appendix of https://arxiv.org/abs/2010.09626, which empirically
has an average runtime roughly linear in the number of nodes
and gives the same output as full matching in practice.
Furthermore, Python bindings are provided for all the
core functionality of PyMatching, making it easy to use
in conjunction with numpy, scipy and NetworkX.
PyMatching can be applied to any quantum code for which
and gives the same output as full matching in practice. Since
PyMatching uses the open-source Lemon C++ library for matching,
which has similar performance to BlossomV, both PyMatching and
its dependencies have permissive licenses. PyMatching can be
applied to any quantum code for which
defects come in pairs (or in isolation at a boundary),
and does not require knowledge of the specific geometry
used.
Expand Down
3 changes: 0 additions & 3 deletions lib/blossom5-v2.05.src/.gitignore

This file was deleted.

6 changes: 0 additions & 6 deletions lib/blossom5-v2.05.src/CMakeLists.txt

This file was deleted.

7 changes: 0 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@ def download_and_extract(pkg_url, pkg_fn, pkg_orig_dir=None, pkg_new_dir=None):
if os.path.isfile(pkg_fn):
os.remove(pkg_fn)

blossom5_url = "https://pub.ist.ac.at/~vnk/software/blossom5-v2.05.src.tar.gz"
blossom5_fn = os.path.join(root_dir, "blossom5-v2.05.src.tar.gz")
blossom5_dir = os.path.join(lib_dir, "blossom5-v2.05.src")

if not os.path.isfile(os.path.join(blossom5_dir, "PerfectMatching.h")):
download_and_extract(blossom5_url, blossom5_fn)

lemon_url = "http://lemon.cs.elte.hu/pub/sources/lemon-1.3.1.tar.gz"
lemon_fn = os.path.join(root_dir, "lemon-1.3.1.tar.gz")
lemon_old_dir = os.path.join(lib_dir, "lemon-1.3.1")
Expand Down
3 changes: 1 addition & 2 deletions src/pymatching/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from ._cpp_mwpm import (PerfectMatching, Options, randomize, set_seed,
rand_float)
from ._cpp_mwpm import (randomize, set_seed, rand_float)
from .matching import *

randomize() # Set random seed using std::random_device
28 changes: 0 additions & 28 deletions src/pymatching/bindings.cpp
Original file line number Diff line number Diff line change
@@ -1,36 +1,14 @@
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include"mwpm.h"
#include <PerfectMatching.h>
#include "stabiliser_graph.h"
#include "weighted_stabiliser_graph.h"
#include "rand_gen.h"
#include "boost_mwpm.h"
#include "lemon_mwpm.h"

namespace py = pybind11;
using namespace pybind11::literals;

PYBIND11_MODULE(_cpp_mwpm, m) {
py::class_<PerfectMatching>(m, "PerfectMatching")
.def(py::init<int, int>(), "nodeNum"_a, "edgeNumMax"_a)
.def("add_edge", &PerfectMatching::AddEdge,
"i"_a, "j"_a, "cost"_a)
.def("solve", &PerfectMatching::Solve, "finish"_a=true)
.def("get_match", &PerfectMatching::GetMatch, "i"_a)
.def("get_solution", &PerfectMatching::GetSolution, "e"_a)
.def_readwrite("options", &PerfectMatching::options);

py::class_<PerfectMatching::Options>(m, "Options")
.def(py::init<>())
.def_readwrite("fractional_jumpstart", &PerfectMatching::Options::fractional_jumpstart)
.def_readwrite("dual_greedy_update_option", &PerfectMatching::Options::dual_greedy_update_option)
.def_readwrite("dual_LP_threshold", &PerfectMatching::Options::dual_LP_threshold)
.def_readwrite("update_duals_before", &PerfectMatching::Options::update_duals_before)
.def_readwrite("update_duals_after", &PerfectMatching::Options::update_duals_after)
.def_readwrite("single_tree_threshold", &PerfectMatching::Options::single_tree_threshold)
.def_readwrite("verbose", &PerfectMatching::Options::verbose);

py::class_<IStabiliserGraph>(m, "IStabiliserGraph")
.def("distance", &IStabiliserGraph::Distance, "node1"_a, "node2"_a)
.def("space_time_distance", &IStabiliserGraph::SpaceTimeDistance, "node1"_a, "node2"_a)
Expand Down Expand Up @@ -59,16 +37,10 @@ PYBIND11_MODULE(_cpp_mwpm, m) {
"source"_a, "num_neighbours"_a, "defect_id"_a)
.def("get_path", &WeightedStabiliserGraph::GetPath, "source"_a, "target"_a);

m.def("bv_decode", &Decode, "sg"_a, "defects"_a);
m.def("bv_decode_match_neighbourhood", &DecodeMatchNeighbourhood,
"sg"_a ,"defects"_a, "num_neighbours"_a);
m.def("randomize", &randomize);
m.def("set_seed", &set_seed, "s"_a);
m.def("rand_float", &rand_float, "from"_a, "to"_a);

m.def("boost_decode_match_neighbourhood", &BoostDecodeMatchNeighbourhood, "sg"_a ,"defects"_a, "num_neighbours"_a);
m.def("boost_decode", &BoostDecode, "sg"_a, "defects"_a);

m.def("decode_match_neighbourhood", &LemonDecodeMatchNeighbourhood);
m.def("decode", &LemonDecode);
}
122 changes: 0 additions & 122 deletions src/pymatching/boost_mwpm.cpp

This file was deleted.

8 changes: 0 additions & 8 deletions src/pymatching/boost_mwpm.h

This file was deleted.

Loading

0 comments on commit 3db1b54

Please sign in to comment.