quantumgizmos / ldpc

A belief propagation decoder for low density parity check (LDPC) codes
MIT License
69 stars 25 forks source link

BeliefFind gets stuck in `peeling` mode. #30

Open timohillmann opened 8 months ago

timohillmann commented 8 months ago

For some syndromes, the BeliefFind decoder seems to get stuck in peeling mode and will not terminate. This error does occur in inversion mode. In particular, I find that for the example below the i = 8 that is the syndrome s = [0 0 1 0 0 0] is problematic.

To reproduce run


import numpy as np
from ldpc.belief_find_decoder import BeliefFindDecoder
from scipy.sparse import load_npz

def load_surface_code(d: int):
    hx = load_npz(
        f"/Users/timo/Documents/GitHub/ldpc/python_test/pcms/hx_surface_{d:d}.npz"
    )
    lx = load_npz(
        f"/Users/timo/Documents/GitHub/ldpc/python_test/pcms/lx_surface_{d:d}.npz"
    )

    return hx, lx

if __name__ == "__main__":
    d = 3
    hx, lx = load_surface_code(d)
    decoder = BeliefFindDecoder(
        hx,
        error_rate=0.05,
        max_iter=4,
        bp_method="ms",
        ms_scaling_factor=0.625,
        schedule="parallel",
        uf_method="peeling",
    )

    m, n = hx.shape

    # iterate through all possible syndrome strings
    for i in range(2**m):
        s = np.array([int(x) for x in list(f"{i:0{m}b}")])
        print(i, s)
        corr = decoder.decode(s)
quantumgizmos commented 8 months ago

Can you upload the surface code PCMs you are using?

timohillmann commented 8 months ago

It's the on-branch l4_dev pcms stored at python_test/pcms/hx_surface_3.npz

timohillmann commented 8 months ago

By the way, I saw it eventually terminated with

             Traceback (most recent call last):
               File "/Users/timo/.vscode/extensions/ms-python.debugpy-2023.3.13341006-darwin-x64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/launcher/debuggee.py", line 190, in kill
                 os.killpg(process.pid, signal.SIGKILL)
             PermissionError: [Errno 1] Operation not permitted

             Stack where logged:
               File "/Users/timo/.vscode/extensions/ms-python.debugpy-2023.3.13341006-darwin-x64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/launcher/debuggee.py", line 192, in kill
                 log.swallow_exception("Failed to kill {0}", describe())
               File "/Users/timo/.vscode/extensions/ms-python.debugpy-2023.3.13341006-darwin-x64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/common/log.py", line 215, in swallow_exception
                 _exception(format_string, *args, **kwargs)
quantumgizmos commented 8 months ago

All of d=3 surface code syndromes work for me.

quantumgizmos commented 8 months ago

I have found that error = np.array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0]) for d=5 causes the decoder to crash though in Peeling mode

quantumgizmos commented 8 months ago

It works in all cases for me if you set uf_method = "peeling" and bits_per_step = 1.

There is something going wrong with error = np.array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0]) on the d=5 surface code when the bits_per_step > 5. Will investigate.

timohillmann commented 8 months ago

I get stuck even with bits_per_step = 1. For the d=3 surface code, the following error causes a problem [0 0 0 0 0 0 0 0 1 0 0 1 0] Note that I am running python/3.11.7 on intel-mac.

quantumgizmos commented 8 months ago

Can you try in a fresh python virtual environment?

timohillmann commented 8 months ago

With a fresh environment, d = 3, 4, 5 work with bit_per_step = 1. Thanks