BP+OSD
Project description
BP+OSD: A decoder for quantum LDPC codes
A C library implementing belief propagation with ordered statistics post-processing for decoding sparse quantum LDPC codes as described in arXiv:2005.07016.
Installation from PyPi (recommended method)
Installtion from PyPi requires Python>=3.6. To install via pip, run:
pip install bposd
Installation (from source)
Installation from source requires Python>=3.6 and a local C compiler (eg. 'gcc' in Linux or 'clang' in Windows). The LDPC package can then be installed by running:
git clone https://github.com/quantumgizmos/bposd.git
cd bposd
pip install -e bposd
Dependencies
This package makes use of the mod2sparse
data structure from Radford Neal's Software for Low Density Parity Check Codes C package.
Basic usage
Constructing CSS codes
The bposd.css.css_code
class can be used to create a CSS code from two classical codes. As an example, we can create a [[7,4,3]] Steane code from the classical Hamming code
from ldpc.codes import hamming_code
from bposd.css import css_code
h=hamming_code(3) #Hamming code parity check matrix
steane_code=css_code(hx=h,hz=h) #create Steane code where both hx and hz are Hamming codes
print("Hx")
print(steane_code.hx)
print("Hz")
print(steane_code.hz)
Hx
[[0 0 0 1 1 1 1]
[0 1 1 0 0 1 1]
[1 0 1 0 1 0 1]]
Hz
[[0 0 0 1 1 1 1]
[0 1 1 0 0 1 1]
[1 0 1 0 1 0 1]]
The bposd.css.css_code
class automatically computes the logical operators of the code.
print("Lx Logical")
print(steane_code.lx)
print("Lz Logical")
print(steane_code.lz)
Lx Logical
[[1 1 1 0 0 0 0]]
Lz Logical
[[1 1 1 0 0 0 0]]
Not all combinations of the hx
and hz
matrices will produce a valid CSS code. Use the bposd.css.css_code.test
function to check whether the code is valid. For example, we can easily check that the Steane code passes all the CSS code tests:
steane_code.test()
<Unnamed CSS code>, (3,4)-[[7,1,nan]]
-Block dimensions: Pass
-PCMs commute hz@hx.T==0: Pass
-PCMs commute hx@hz.T==0: Pass
-lx \in ker{hz} AND lz \in ker{hx}: Pass
-lx and lz anticommute: Pass
-<Unnamed CSS code> is a valid CSS code w/ params (3,4)-[[7,1,nan]]
True
As an example of a code that isn't valid, consider the case when hx
and hz
are repetition codes:
from ldpc.codes import rep_code
hx=hz=rep_code(7)
qcode=css_code(hx,hz)
qcode.test()
<Unnamed CSS code>, (2,2)-[[7,-5,nan]]
-Block dimensions incorrect
-PCMs commute hz@hx.T==0: Fail
-PCMs commute hx@hz.T==0: Fail
-lx \in ker{hz} AND lz \in ker{hx}: Pass
-lx and lz anitcommute: Fail
False
Hypergraph product codes
The hypergraph product can be used to construct a valid CSS code from any pair of classical seed codes. To use the the hypergraph product, call the bposd.hgp.hgp
function. Below is an example of how the distance-3 surface code can be constructed by taking the hypergraph product of two distance-3 repetition codes.
from bposd.hgp import hgp
h=rep_code(3)
surface_code=hgp(h1=h,h2=h,compute_distance=True) #nb. set compute_distance=False for larger codes
surface_code.test()
<Unnamed CSS code>, (2,4)-[[13,1,3]]
-Block dimensions: Pass
-PCMs commute hz@hx.T==0: Pass
-PCMs commute hx@hz.T==0: Pass
-lx \in ker{hz} AND lz \in ker{hx}: Pass
-lx and lz anticommute: Pass
-<Unnamed CSS code> is a valid CSS code w/ params (2,4)-[[13,1,3]]
True
BP+OSD Decoding
BP+OSD decoding is useful for codes that do not perform well under standard-BP. To use the BP+OSD decoder, we first call the bposd.bposd_decoder
class:
import numpy as np
from bposd import bposd_decoder
bpd=bposd_decoder(
surface_code.hz,#the parity check matrix
error_rate=0.05,
max_iter=surface_code.N, #the maximum number of iterations for BP)
bp_method="ps",
osd_method="osd_cs", #the OSD method
osd_order=-1)
We can then decode by passing a syndrome to the bposd.bposd_decoder.decode
method:
error=np.zeros(surface_code.N).astype(int)
error[[5,12]]=1
syndrome=surface_code.hz@error %2
bpd.decode(syndrome)
print("Error")
print(error)
print("BP+OSD Decoding")
print(bpd.bp_decoding)
print(bpd.osd0_decoding)
print(bpd.osdw_decoding)
residual_error=(bpd.osdw_decoding+error) %2
a=(surface_code.lz@residual_error%2).any()
if a: a="Yes"
else: a="No"
print(f"Logical Error: {a}\n")
Error
[0 0 0 0 0 1 0 0 0 0 0 0 1]
BP+OSD Decoding
[0 0 0 0 0 0 0 0 1 0 0 0 0]
[0 0 0 0 0 0 0 0 1 0 0 0 0]
Logical Error: No
def random_error(N,error_rate):
error=np.zeros(N).astype(int)
for i in range(N):
if np.random.random()<error_rate: error[i]=1
else: error[i]=0
return error
error_rate=0.10
bpd=bposd_decoder(
surface_code.hz,#the parity check matrix
error_rate=0.05,
max_iter=3, #the maximum number of iterations for BP)
bp_method="ps",
osd_method="osd_e", #the OSD method
osd_order=7)
for i in range(3):
error=random_error(N=surface_code.N,error_rate=error_rate)
syndrome=surface_code.hz@error%2
bpd.decode(syndrome)
print("Error")
print(error)
print("BP+OSD Decoding")
print(bpd.osdw_decoding)
print(bpd.converge)
a=(surface_code.lz@((bpd.osdw_decoding+error) %2)%2).any()
if a: a="Yes"
else: a="No"
print(f"Logical Error: {a}\n")
Error
[0 0 0 0 0 0 0 0 0 0 0 0 0]
BP+OSD Decoding
[0 0 0 0 0 0 0 0 0 0 0 0 0]
1
Logical Error: No
Error
[0 0 0 0 0 0 0 0 0 0 0 0 0]
BP+OSD Decoding
[0 0 0 0 0 0 0 0 0 0 0 0 0]
1
Logical Error: No
Error
[0 0 0 0 0 0 0 0 0 0 0 0 0]
BP+OSD Decoding
[0 0 0 0 0 0 0 0 0 0 0 0 0]
1
Logical Error: No
surface_code.hz
array([[1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0],
[0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0],
[0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0],
[0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1],
[0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0],
[0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1]])
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Hashes for bposd-0.0.3-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9187b97062caac562d5958e467ecd5647b23b2b772af78130e436fe16c94f2a0 |
|
MD5 | db7977ec74bfbd338181bdb80512abff |
|
BLAKE2b-256 | c2fcc1811ae14593f2d1d529e3acc38815c52513443797c7f92a60af0617258d |
Hashes for bposd-0.0.3-cp39-cp39-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d5cdfd7b29716feb69e15160daf392a9a7a6a717d8a7b18ad8c72d46dd5394fe |
|
MD5 | 6394740ed8f9f0a5c13cea1ffcb220fb |
|
BLAKE2b-256 | 1b6bfd584b8a3a6635d60a8f087f96b6939273a329d900b1a91322786e7c44bf |
Hashes for bposd-0.0.3-cp39-cp39-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ffd7fc36b33883e7fe43a8f8b18e23ca02adcbd500bd2c3bbd7069e15bbfe33 |
|
MD5 | 7b72344fca3e7e7d7d4c4d9174f6ae5a |
|
BLAKE2b-256 | 898fe8dc13641a557c886efc358b7e67b36aa3554c50a9a6418f6debf9bb89db |
Hashes for bposd-0.0.3-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 36700ba85ed18a532bab1614d28e73126fccef45d52e9974fc37bf1314da0c5f |
|
MD5 | 96af0d261a3e5df136367a3844c72ae5 |
|
BLAKE2b-256 | 8e8068597eb6be3963cc8c41c34f4f1cb1fea689a35ec49e24c141261ae908a9 |
Hashes for bposd-0.0.3-cp39-cp39-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ffabf803c530a5f76fc17144812279bd3ffd9e241026da83a8e3a7c4a763a01 |
|
MD5 | 676ded9e745b54dda18166e2b85c9901 |
|
BLAKE2b-256 | d1ea1ac93da1b1b74019188787642eb46280e2cd926707389576cd03aa3020c8 |
Hashes for bposd-0.0.3-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 466cd437b058d9b31305e02af30f8722874d0f399c549763a0c997f7dcd8cea2 |
|
MD5 | 6dc9c35f4828c01dc85333b5f168b8e7 |
|
BLAKE2b-256 | 3be54045a1ff879a43d0490cbc04664e70777b48e00505ffc78788299485ee3a |
Hashes for bposd-0.0.3-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a344abdf0ebc8dd702ddcaa003d2bab30e0cb78f8228f553352622e6673ccb7 |
|
MD5 | 63b3d73fe47472734d2fc5a159a5a1b5 |
|
BLAKE2b-256 | 7a6c6c4de7522d4c8e26437958764827a414f7f9d2bd23ba716672da60cc4314 |
Hashes for bposd-0.0.3-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b81fdb86ac9939913bda19efef1029d6ee93d957bb622db928b98698d67ae92 |
|
MD5 | aa25276136d259889d8415d36d05e819 |
|
BLAKE2b-256 | 1663fa2c7acab754cc96fdbb0301d3fa437b1fa32f18dd0a5ff40f302de11618 |
Hashes for bposd-0.0.3-cp38-cp38-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 965f4ff9dcd362f9715eee2cffde25c4857f68b619392e7ad097af00cca73a69 |
|
MD5 | 9914ea8f4b4e53bfec3e460002b57d58 |
|
BLAKE2b-256 | 34534975efe7543ebeed07789eeab0759a7d30a97c5fb2f4b1540d3a6323a777 |
Hashes for bposd-0.0.3-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 503bb5590ae829fd6f41aa0bcaadbfa02e9f13c882118f6072676a21688d39be |
|
MD5 | f5b3f9de27323e58f204911bc43e94cf |
|
BLAKE2b-256 | 95d216d4a33d8d01f55725e5d62a69415c143c0ddd4b5b275386cd447476398a |
Hashes for bposd-0.0.3-cp38-cp38-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 187214719838e7fcb6cbbc5d4129858b9ccf66c864414403369a24a2af1b786f |
|
MD5 | cd611aad7532ca66896ae34a2b644758 |
|
BLAKE2b-256 | cda4d9e79182ed56201b18b894b3fe4467df793657e29c0614d99c2136d76c90 |
Hashes for bposd-0.0.3-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8ecbcbc6a4d39e6ef4bb7373b3b85351e3fc25a88f080e8a011c6168d77e025 |
|
MD5 | 6cbfa211247c0eb012fa713a644f6046 |
|
BLAKE2b-256 | 89f8d33f3782ebef158fe043651c28a27920b53ac9070702126c673269d3567e |
Hashes for bposd-0.0.3-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01aaa3ace1c4e4f7c2e70c40fc34c4c1ef40612fdb289f3a25e94f0081ee9307 |
|
MD5 | 2ea6a90457f6f724718905613bfd070f |
|
BLAKE2b-256 | 5126690822d8cdeca9f689fe04b5b42506f2a17c7f204213c20146853fb9b4a4 |
Hashes for bposd-0.0.3-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 221135cea5cf0affffcaaaefb9addae54868b14768dbef8a13c3159bcd605652 |
|
MD5 | 1455b7896e71efad1c32aec6c96072a7 |
|
BLAKE2b-256 | 3bceaf5bf74737f5ed20157952b929d505bf67c0c012d647c7f07182352e2b80 |
Hashes for bposd-0.0.3-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b9a2d66001b325d6257e8b173b02d4106edc6fe2cf78aa268a8b86ad2a151523 |
|
MD5 | 0725834e9ae9da640d58f2b4a3434276 |
|
BLAKE2b-256 | 89f3696ebd9c59e3bdfcf80b9f331e1993684b67a30fabc85e1d7de3c399e6bd |
Hashes for bposd-0.0.3-cp37-cp37m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 18ba3c5ef1fe140e63835a47cd086590cf0e56397a864f965b4e5171ab4e557c |
|
MD5 | e72fa4195402f187d36459b11342824f |
|
BLAKE2b-256 | c24240dd94276a542abb991716a8ca4298dae5e2287840325dd706c2392851ec |
Hashes for bposd-0.0.3-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa62575b718cee55310870d62fde1f7b1cb017aae5f44e6cd474ed8d42235775 |
|
MD5 | 28f89dfde3bef0de2bd4defaf4292364 |
|
BLAKE2b-256 | eafe006a433ee121e07d626c4e9a6429924fbcd8ce66a69438b1eceb5c3f2838 |
Hashes for bposd-0.0.3-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e95a570486e8bcc4eb0587495a9120fca150a8c443f6a047236c58784afcbac1 |
|
MD5 | d5c281caa8b7cd54673babd595600a7c |
|
BLAKE2b-256 | e39424609d08b78b8202b103e679015e2e8ac7d2d5e81734418075b12e618e8e |
Hashes for bposd-0.0.3-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 17a47e257bd1eb7969475683434fdaa0c9761331b05783fdca66e97dad720b20 |
|
MD5 | 98623af3ae25b02f35796e0004018ddd |
|
BLAKE2b-256 | 2ab86e3d59bff7724eae1931ea4468eab5ab58be966c9f5634de36c03444ab39 |
Hashes for bposd-0.0.3-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f3c4e3b9eb02b83835261fd0ac97ba260bfd1a60fabe43b7d0ca9e435cd5023 |
|
MD5 | b42bdfdf12e94d120a121b01c42fa71b |
|
BLAKE2b-256 | 39364ee3115c870b0e8257922829c7aef2f01528585bf22e11749f1f778bfaf7 |
Hashes for bposd-0.0.3-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b8e53b41e51e19da17dc597377fe201606f63f43ee74b08ab9e6f16ecff41cc |
|
MD5 | 4433654ee7e854cb359c77eb4a3b1816 |
|
BLAKE2b-256 | a5076bbce91ef7ddbb279da9037559c1a20c1b65306a42e5536ad573a2f03b2e |
Hashes for bposd-0.0.3-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 130bc9aeb747ca8400da29b7c271a0f83b2467214888102aa86e5efaf645a129 |
|
MD5 | a57646d2aa540aba186d8a6608243fb8 |
|
BLAKE2b-256 | 430bb21a401ddf0f5d2d0e99b7bfff7a9686ac8fb9da50621485fa66b2b24e23 |
Hashes for bposd-0.0.3-cp36-cp36m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 624aba540b4031da847447386808138fd28dca9871ebb54a3728db33290f06ed |
|
MD5 | 447eaadff9c015e631e3b6544999a85d |
|
BLAKE2b-256 | 6e6258e0cca28a5af4ddb3dc7a466888aea40b42104e883a11667eac7add1ad9 |
Hashes for bposd-0.0.3-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 577f140f09f38f93fdcb32b0f55aeed6f420503dff3ec2f2cb7621983c9863ff |
|
MD5 | ebeed8973050f8f67d1bd4ef9bd2fe05 |
|
BLAKE2b-256 | dfcddf43d93c65f8a2bbc19e449b317b6efe26fdda6dea6b01558f73eeef5504 |
Hashes for bposd-0.0.3-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 96707ed4168edf4106f2f16ab56fd16d7178fdc4b8ff32928af1f7bb57142d7e |
|
MD5 | 748483a39b25f84df7e5b10fae24ffc5 |
|
BLAKE2b-256 | 9d6501c4cc948f231b10baa021cb30fc940ad07668ec9d5038495509debe5ee8 |
Hashes for bposd-0.0.3-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca44a9ecbdebdc25457ac6a9d2948fac527acb7208b15250907d7224c50977ff |
|
MD5 | 138cabaa2342b88f238c8d667e22dc91 |
|
BLAKE2b-256 | 759a4786af40da941ad370b048c52bd0033af6e9d96e77f584e75b7bc7f012e0 |