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

Simplify matching decoding #414

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
c5e592a
add logical node property
quantumjim Dec 14, 2023
7c3b496
remove unused and untested functions
quantumjim Dec 14, 2023
4b6e8fc
rename boundary nodes as logical nodes (if associated with a logical)
quantumjim Dec 14, 2023
0fd172a
fix issues
quantumjim Dec 14, 2023
a1a6bf1
linting
quantumjim Dec 14, 2023
8982cb2
add graph conversion
quantumjim Dec 15, 2023
1549e02
rename old file
quantumjim Dec 15, 2023
9badddb
Create pymatching_decoder.py (#415)
hetenyib Dec 15, 2023
235fe97
linting
quantumjim Dec 21, 2023
160c2c9
remove old matching code and tests
quantumjim Jan 18, 2024
ac4121e
remove old matching code and tests
quantumjim Jan 18, 2024
0de738c
Merge branch 'main' into 413-logical-nodes
quantumjim Jan 18, 2024
e9cdb74
remove old imports
quantumjim Jan 18, 2024
2f8bd05
fix fault id issue
quantumjim Jan 18, 2024
d379596
standardize stim code circuit
quantumjim Jan 18, 2024
06d0ca0
get rid of measured_logicals
quantumjim Jan 19, 2024
6ab2010
Merge branch 'main' into 413-logical-nodes
quantumjim Jan 19, 2024
433efa7
remove measuremed_logicals
quantumjim Jan 19, 2024
4ca1d7b
remove css decoding graph
quantumjim Jan 19, 2024
f2b2c0b
remove css decoding graph
quantumjim Jan 19, 2024
9bf482f
add graph conversions
quantumjim Jan 26, 2024
0d23dd6
make matching work for non-stim
quantumjim Jan 26, 2024
e77fffe
add matching tests
quantumjim Jan 26, 2024
a808c90
convert to edge graph only when needed
quantumjim Jan 26, 2024
bd6fc49
black
quantumjim Jan 26, 2024
e5beefb
update doc string
quantumjim Jan 31, 2024
c5952d2
correct logical nodes
quantumjim Feb 5, 2024
ce390ff
2 qubit paulis for cx gates
quantumjim Feb 5, 2024
6af880a
extend beyond cx
quantumjim Feb 5, 2024
2b02846
allow default check nodes to be used
quantumjim Feb 6, 2024
84117f0
rename pymatching decoder
quantumjim Feb 6, 2024
06c14e3
undo formatting changes
quantumjim Feb 16, 2024
2f07d47
Merge branch 'main' into 413-logical-nodes
quantumjim Feb 16, 2024
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
4 changes: 1 addition & 3 deletions extern/pybind11/noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,4 @@ def build(session: nox.Session) -> None:
session.log("Building normal files")
session.run("python", "-m", "build", *session.posargs)
session.log("Building pybind11-global files (PYBIND11_GLOBAL_SDIST=1)")
session.run(
"python", "-m", "build", *session.posargs, env={"PYBIND11_GLOBAL_SDIST": "1"}
)
session.run("python", "-m", "build", *session.posargs, env={"PYBIND11_GLOBAL_SDIST": "1"})
4 changes: 1 addition & 3 deletions extern/pybind11/pybind11/setup_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,7 @@ def cxx_std(self) -> int:
@cxx_std.setter
def cxx_std(self, level: int) -> None:
if self._cxx_level:
warnings.warn(
"You cannot safely change the cxx_level after setting it!", stacklevel=2
)
warnings.warn("You cannot safely change the cxx_level after setting it!", stacklevel=2)

# MSVC 2015 Update 3 and later only have 14 (and later 17) modes, so
# force a valid flag here.
Expand Down
16 changes: 4 additions & 12 deletions extern/pybind11/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
import setuptools.command.sdist

DIR = Path(__file__).parent.absolute()
VERSION_REGEX = re.compile(
r"^\s*#\s*define\s+PYBIND11_VERSION_([A-Z]+)\s+(.*)$", re.MULTILINE
)
VERSION_REGEX = re.compile(r"^\s*#\s*define\s+PYBIND11_VERSION_([A-Z]+)\s+(.*)$", re.MULTILINE)
VERSION_FILE = Path("pybind11/_version.py")
COMMON_FILE = Path("include/pybind11/detail/common.h")

Expand Down Expand Up @@ -52,9 +50,7 @@ def build_expected_version_hex(matches: Dict[str, str]) -> str:

global_sdist = os.environ.get("PYBIND11_GLOBAL_SDIST", False)

setup_py = Path(
"tools/setup_global.py.in" if global_sdist else "tools/setup_main.py.in"
)
setup_py = Path("tools/setup_global.py.in" if global_sdist else "tools/setup_main.py.in")
extra_cmd = 'cmdclass["sdist"] = SDist\n'

to_src = (
Expand Down Expand Up @@ -84,9 +80,7 @@ def build_expected_version_hex(matches: Dict[str, str]) -> str:


# TODO: use literals & overload (typing extensions or Python 3.8)
def get_and_replace(
filename: Path, binary: bool = False, **opts: str
) -> Union[bytes, str]:
def get_and_replace(filename: Path, binary: bool = False, **opts: str) -> Union[bytes, str]:
if binary:
contents = filename.read_bytes()
return string.Template(contents.decode()).substitute(opts).encode()
Expand Down Expand Up @@ -131,9 +125,7 @@ def remove_output(*sources: str) -> Iterator[None]:
]
if "CMAKE_ARGS" in os.environ:
fcommand = [
c
for c in os.environ["CMAKE_ARGS"].split()
if "DCMAKE_INSTALL_PREFIX" not in c
c for c in os.environ["CMAKE_ARGS"].split() if "DCMAKE_INSTALL_PREFIX" not in c
]
cmd += fcommand
subprocess.run(cmd, check=True, cwd=DIR, stdout=sys.stdout, stderr=sys.stderr)
Expand Down
10 changes: 2 additions & 8 deletions extern/pybind11/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ def _split_and_sort(s):

def _make_explanation(a, b):
"""Explanation for a failed assert -- the a and b arguments are List[str]"""
return ["--- actual / +++ expected"] + [
line.strip("\n") for line in difflib.ndiff(a, b)
]
return ["--- actual / +++ expected"] + [line.strip("\n") for line in difflib.ndiff(a, b)]


class Output:
Expand All @@ -75,11 +73,7 @@ def __str__(self):

def __eq__(self, other):
# Ignore constructor/destructor output which is prefixed with "###"
a = [
line
for line in self.string.strip().splitlines()
if not line.startswith("###")
]
a = [line for line in self.string.strip().splitlines() if not line.startswith("###")]
b = _strip_and_dedent(other).splitlines()
if a == b:
return True
Expand Down
34 changes: 8 additions & 26 deletions extern/pybind11/tests/extra_python_package/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,7 @@ def normalize_line_endings(value: bytes) -> bytes:
def test_build_sdist(monkeypatch, tmpdir):
monkeypatch.chdir(MAIN_DIR)

subprocess.run(
[sys.executable, "-m", "build", "--sdist", f"--outdir={tmpdir}"], check=True
)
subprocess.run([sys.executable, "-m", "build", "--sdist", f"--outdir={tmpdir}"], check=True)

(sdist,) = tmpdir.visit("*.tar.gz")

Expand All @@ -151,14 +149,9 @@ def test_build_sdist(monkeypatch, tmpdir):
setup_py = read_tz_file(tar, "setup.py")
pyproject_toml = read_tz_file(tar, "pyproject.toml")
pkgconfig = read_tz_file(tar, "pybind11/share/pkgconfig/pybind11.pc")
cmake_cfg = read_tz_file(
tar, "pybind11/share/cmake/pybind11/pybind11Config.cmake"
)
cmake_cfg = read_tz_file(tar, "pybind11/share/cmake/pybind11/pybind11Config.cmake")

assert (
'set(pybind11_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/include")'
in cmake_cfg.decode("utf-8")
)
assert 'set(pybind11_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/include")' in cmake_cfg.decode("utf-8")

files = {f"pybind11/{n}" for n in all_files}
files |= sdist_files
Expand Down Expand Up @@ -187,9 +180,7 @@ def test_build_sdist(monkeypatch, tmpdir):
def test_build_global_dist(monkeypatch, tmpdir):
monkeypatch.chdir(MAIN_DIR)
monkeypatch.setenv("PYBIND11_GLOBAL_SDIST", "1")
subprocess.run(
[sys.executable, "-m", "build", "--sdist", "--outdir", str(tmpdir)], check=True
)
subprocess.run([sys.executable, "-m", "build", "--sdist", "--outdir", str(tmpdir)], check=True)

(sdist,) = tmpdir.visit("*.tar.gz")

Expand All @@ -201,14 +192,9 @@ def test_build_global_dist(monkeypatch, tmpdir):
setup_py = read_tz_file(tar, "setup.py")
pyproject_toml = read_tz_file(tar, "pyproject.toml")
pkgconfig = read_tz_file(tar, "pybind11/share/pkgconfig/pybind11.pc")
cmake_cfg = read_tz_file(
tar, "pybind11/share/cmake/pybind11/pybind11Config.cmake"
)
cmake_cfg = read_tz_file(tar, "pybind11/share/cmake/pybind11/pybind11Config.cmake")

assert (
'set(pybind11_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/include")'
in cmake_cfg.decode("utf-8")
)
assert 'set(pybind11_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/include")' in cmake_cfg.decode("utf-8")

files = {f"pybind11/{n}" for n in all_files}
files |= sdist_files
Expand All @@ -235,9 +221,7 @@ def test_build_global_dist(monkeypatch, tmpdir):
def tests_build_wheel(monkeypatch, tmpdir):
monkeypatch.chdir(MAIN_DIR)

subprocess.run(
[sys.executable, "-m", "pip", "wheel", ".", "-w", str(tmpdir)], check=True
)
subprocess.run([sys.executable, "-m", "pip", "wheel", ".", "-w", str(tmpdir)], check=True)

(wheel,) = tmpdir.visit("*.whl")

Expand All @@ -263,9 +247,7 @@ def tests_build_global_wheel(monkeypatch, tmpdir):
monkeypatch.chdir(MAIN_DIR)
monkeypatch.setenv("PYBIND11_GLOBAL_SDIST", "1")

subprocess.run(
[sys.executable, "-m", "pip", "wheel", ".", "-w", str(tmpdir)], check=True
)
subprocess.run([sys.executable, "-m", "pip", "wheel", ".", "-w", str(tmpdir)], check=True)

(wheel,) = tmpdir.visit("*.whl")

Expand Down
8 changes: 2 additions & 6 deletions extern/pybind11/tests/extra_setuptools/test_setuphelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ def test_simple_setup_py(monkeypatch, tmpdir, parallel, std):
for item in tmpdir.listdir():
print(item.basename)

assert (
len([f for f in tmpdir.listdir() if f.basename.startswith("simple_setup")]) == 1
)
assert len([f for f in tmpdir.listdir() if f.basename.startswith("simple_setup")]) == 1
assert len(list(tmpdir.listdir())) == 4 # two files + output + build_dir

(tmpdir / "test.py").write_text(
Expand All @@ -103,9 +101,7 @@ def test_simple_setup_py(monkeypatch, tmpdir, parallel, std):
encoding="ascii",
)

subprocess.check_call(
[sys.executable, "test.py"], stdout=sys.stdout, stderr=sys.stderr
)
subprocess.check_call([sys.executable, "test.py"], stdout=sys.stdout, stderr=sys.stderr)


def test_intree_extensions(monkeypatch, tmpdir):
Expand Down
4 changes: 1 addition & 3 deletions extern/pybind11/tests/test_buffers.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ def test_from_python():

# https://foss.heptapod.net/pypy/pypy/-/issues/2444
# TODO: fix on recent PyPy
@pytest.mark.xfail(
env.PYPY, reason="PyPy 7.3.7 doesn't clear this anymore", strict=False
)
@pytest.mark.xfail(env.PYPY, reason="PyPy 7.3.7 doesn't clear this anymore", strict=False)
def test_to_python():
mat = m.Matrix(5, 4)
assert memoryview(mat).shape == (5, 4)
Expand Down
8 changes: 2 additions & 6 deletions extern/pybind11/tests/test_builtin_casters.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ def toobig_message(r):

assert m.ord_char("a") == 0x61 # simple ASCII
assert m.ord_char_lv("b") == 0x62
assert (
m.ord_char("é") == 0xE9
) # requires 2 bytes in utf-8, but can be stuffed in a char
assert m.ord_char("é") == 0xE9 # requires 2 bytes in utf-8, but can be stuffed in a char
with pytest.raises(ValueError) as excinfo:
assert m.ord_char("Ā") == 0x100 # requires 2 bytes, doesn't fit in a char
assert str(excinfo.value) == toobig_message(0x100)
Expand Down Expand Up @@ -108,9 +106,7 @@ def toobig_message(r):
if hasattr(m, "has_u8string"):
assert m.ord_char8("a") == 0x61 # simple ASCII
assert m.ord_char8_lv("b") == 0x62
assert (
m.ord_char8("é") == 0xE9
) # requires 2 bytes in utf-8, but can be stuffed in a char
assert m.ord_char8("é") == 0xE9 # requires 2 bytes in utf-8, but can be stuffed in a char
with pytest.raises(ValueError) as excinfo:
assert m.ord_char8("Ā") == 0x100 # requires 2 bytes, doesn't fit in a char
assert str(excinfo.value) == toobig_message(0x100)
Expand Down
14 changes: 4 additions & 10 deletions extern/pybind11/tests/test_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,17 @@ def test_cpp_callable_cleanup():
def test_cpp_function_roundtrip():
"""Test if passing a function pointer from C++ -> Python -> C++ yields the original pointer"""

assert (
m.test_dummy_function(m.dummy_function) == "matches dummy_function: eval(1) = 2"
)
assert m.test_dummy_function(m.dummy_function) == "matches dummy_function: eval(1) = 2"
assert (
m.test_dummy_function(m.roundtrip(m.dummy_function))
== "matches dummy_function: eval(1) = 2"
)
assert (
m.test_dummy_function(m.dummy_function_overloaded)
== "matches dummy_function: eval(1) = 2"
m.test_dummy_function(m.dummy_function_overloaded) == "matches dummy_function: eval(1) = 2"
)
assert m.roundtrip(None, expect_none=True) is None
assert (
m.test_dummy_function(lambda x: x + 2)
== "can't convert to function pointer: eval(1) = 3"
m.test_dummy_function(lambda x: x + 2) == "can't convert to function pointer: eval(1) = 3"
)

with pytest.raises(TypeError) as excinfo:
Expand Down Expand Up @@ -210,9 +206,7 @@ def test_custom_func():
assert m.roundtrip(m.custom_function)(4) == 36


@pytest.mark.skipif(
m.custom_function2 is None, reason="Current PYBIND11_INTERNALS_VERSION too low"
)
@pytest.mark.skipif(m.custom_function2 is None, reason="Current PYBIND11_INTERNALS_VERSION too low")
def test_custom_func2():
assert m.custom_function2(3) == 27
assert m.roundtrip(m.custom_function2)(3) == 27
9 changes: 2 additions & 7 deletions extern/pybind11/tests/test_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ def test_type():
with pytest.raises(RuntimeError) as execinfo:
m.check_type(0)

assert "pybind11::detail::get_type_info: unable to find type info" in str(
execinfo.value
)
assert "pybind11::detail::get_type_info: unable to find type info" in str(execinfo.value)
assert "Invalid" in str(execinfo.value)

# Currently not supported
Expand Down Expand Up @@ -482,7 +480,4 @@ class ClassScope:


def test_pr4220_tripped_over_this():
assert (
m.Empty0().get_msg()
== "This is really only meant to exercise successful compilation."
)
assert m.Empty0().get_msg() == "This is really only meant to exercise successful compilation."
10 changes: 2 additions & 8 deletions extern/pybind11/tests/test_docstring_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,10 @@ def test_docstring_options():
assert not m.DocstringTestFoo.value_prop.__doc__

# Check existig behaviour of enum docstings
assert (
m.DocstringTestEnum1.__doc__
== "Enum docstring\n\nMembers:\n\n Member1\n\n Member2"
)
assert m.DocstringTestEnum1.__doc__ == "Enum docstring\n\nMembers:\n\n Member1\n\n Member2"

# options.enable_enum_members_docstring()
assert (
m.DocstringTestEnum2.__doc__
== "Enum docstring\n\nMembers:\n\n Member1\n\n Member2"
)
assert m.DocstringTestEnum2.__doc__ == "Enum docstring\n\nMembers:\n\n Member1\n\n Member2"

# options.disable_enum_members_docstring()
assert m.DocstringTestEnum3.__doc__ == "Enum docstring"
Expand Down
40 changes: 10 additions & 30 deletions extern/pybind11/tests/test_eigen_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,15 @@ def test_partially_fixed():
np.testing.assert_array_equal(m.partial_copy_four_rm_c(ref2), ref2)
np.testing.assert_array_equal(m.partial_copy_four_rm_r(ref2[:, 1]), ref2[:, [1]])
np.testing.assert_array_equal(m.partial_copy_four_rm_c(ref2[0, :]), ref2[[0], :])
np.testing.assert_array_equal(
m.partial_copy_four_rm_r(ref2[:, (0, 2)]), ref2[:, (0, 2)]
)
np.testing.assert_array_equal(
m.partial_copy_four_rm_c(ref2[(3, 1, 2), :]), ref2[(3, 1, 2), :]
)
np.testing.assert_array_equal(m.partial_copy_four_rm_r(ref2[:, (0, 2)]), ref2[:, (0, 2)])
np.testing.assert_array_equal(m.partial_copy_four_rm_c(ref2[(3, 1, 2), :]), ref2[(3, 1, 2), :])

np.testing.assert_array_equal(m.partial_copy_four_cm_r(ref2), ref2)
np.testing.assert_array_equal(m.partial_copy_four_cm_c(ref2), ref2)
np.testing.assert_array_equal(m.partial_copy_four_cm_r(ref2[:, 1]), ref2[:, [1]])
np.testing.assert_array_equal(m.partial_copy_four_cm_c(ref2[0, :]), ref2[[0], :])
np.testing.assert_array_equal(
m.partial_copy_four_cm_r(ref2[:, (0, 2)]), ref2[:, (0, 2)]
)
np.testing.assert_array_equal(
m.partial_copy_four_cm_c(ref2[(3, 1, 2), :]), ref2[(3, 1, 2), :]
)
np.testing.assert_array_equal(m.partial_copy_four_cm_r(ref2[:, (0, 2)]), ref2[:, (0, 2)])
np.testing.assert_array_equal(m.partial_copy_four_cm_c(ref2[(3, 1, 2), :]), ref2[(3, 1, 2), :])

# TypeError should be raise for a shape mismatch
functions = [
Expand Down Expand Up @@ -241,9 +233,7 @@ def test_eigen_ref_to_python():
chols = [m.cholesky1, m.cholesky2, m.cholesky3, m.cholesky4]
for i, chol in enumerate(chols, start=1):
mymat = chol(np.array([[1.0, 2, 4], [2, 13, 23], [4, 23, 77]]))
assert np.all(
mymat == np.array([[1, 0, 0], [2, 3, 0], [4, 5, 6]])
), f"cholesky{i}"
assert np.all(mymat == np.array([[1, 0, 0], [2, 3, 0], [4, 5, 6]])), f"cholesky{i}"


def assign_both(a1, a2, r, c, v):
Expand Down Expand Up @@ -562,9 +552,7 @@ def test_both_ref_mutators():

y = np.array(range(100), dtype="float64").reshape(10, 10)
y2 = m.incr_matrix_any(y, 10) # np -> eigen -> np
y3 = m.incr_matrix_any(
y2[0::2, 0::2], -33
) # np -> eigen -> np slice -> np -> eigen -> np
y3 = m.incr_matrix_any(y2[0::2, 0::2], -33) # np -> eigen -> np slice -> np -> eigen -> np
y4 = m.even_rows(y3) # numpy -> eigen slice -> (... y3)
y5 = m.even_cols(y4) # numpy -> eigen slice -> (... y4)
y6 = m.incr_matrix_any(y5, 1000) # numpy -> eigen -> (... y5)
Expand All @@ -586,13 +574,9 @@ def test_nocopy_wrapper():
# get_elem requires a column-contiguous matrix reference, but should be
# callable with other types of matrix (via copying):
int_matrix_colmajor = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]], order="F")
dbl_matrix_colmajor = np.array(
int_matrix_colmajor, dtype="double", order="F", copy=True
)
dbl_matrix_colmajor = np.array(int_matrix_colmajor, dtype="double", order="F", copy=True)
int_matrix_rowmajor = np.array(int_matrix_colmajor, order="C", copy=True)
dbl_matrix_rowmajor = np.array(
int_matrix_rowmajor, dtype="double", order="C", copy=True
)
dbl_matrix_rowmajor = np.array(int_matrix_rowmajor, dtype="double", order="C", copy=True)

# All should be callable via get_elem:
assert m.get_elem(int_matrix_colmajor) == 8
Expand Down Expand Up @@ -743,14 +727,10 @@ def test_sparse_signature(doc):
def test_issue738():
"""Ignore strides on a length-1 dimension (even if they would be incompatible length > 1)"""
assert np.all(m.iss738_f1(np.array([[1.0, 2, 3]])) == np.array([[1.0, 102, 203]]))
assert np.all(
m.iss738_f1(np.array([[1.0], [2], [3]])) == np.array([[1.0], [12], [23]])
)
assert np.all(m.iss738_f1(np.array([[1.0], [2], [3]])) == np.array([[1.0], [12], [23]]))

assert np.all(m.iss738_f2(np.array([[1.0, 2, 3]])) == np.array([[1.0, 102, 203]]))
assert np.all(
m.iss738_f2(np.array([[1.0], [2], [3]])) == np.array([[1.0], [12], [23]])
)
assert np.all(m.iss738_f2(np.array([[1.0], [2], [3]])) == np.array([[1.0], [12], [23]]))


@pytest.mark.parametrize("func", [m.iss738_f1, m.iss738_f2])
Expand Down
Loading
Loading