BP+OSD
Project description
BP+OSD: A decoder for quantum LDPC codes
A Python 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 ldpc.codes import rep_code
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="ms",
ms_scaling_factor=0, #min sum scaling factor. If set to zero the variable scaling factor method is used
osd_method="osd_cs", #the OSD method. Choose from: 1) "osd_e", "osd_cs", "osd0"
osd_order=7 #the osd search depth
)
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.osdw_decoding)
#Decoding is successful if the residual error commutes with the logical operators
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]
Logical Error: No
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.5-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f5d4ed973ddd910a370fe314702f9619e90c429cc1476537142f560a596481ff |
|
MD5 | 6af10fd92b86581800bb9fb8bb6d9a3d |
|
BLAKE2b-256 | 4ca0b45f946b753a06a17e52da2db9a1d120521107159c37c545fb5c46aa43ab |
Hashes for bposd-0.0.5-cp39-cp39-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97e7a9193d472a15e2b5f27e2e9546010cd0b309ea295e26768c964e60e4fc3e |
|
MD5 | d17d900e3812ab27bc7d9ce5d73de92d |
|
BLAKE2b-256 | 0907e996d7ac9b224bf9b33bf808365b5b01c3feb48a01e7495041f7f7f4cd62 |
Hashes for bposd-0.0.5-cp39-cp39-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22f456a44eae2af9dc7a1eecca1d50f1cc229772230a987d2a9707da7eb988d4 |
|
MD5 | feb438d2ccbae9cfacff75373fe2bcb5 |
|
BLAKE2b-256 | d3c5a3226c971007a2c9586a52435e18876c1d128e875e70042c9e3472da339b |
Hashes for bposd-0.0.5-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2020da3e42a1c5b07d509366052be0a51b24a6be710d2de8ff75232ddcec1972 |
|
MD5 | 85d0de534b4806ca2adfddccd2ebcd0a |
|
BLAKE2b-256 | 3b5fbf0d824282d9e6cd4c7cc976994b86e7e68b57ff3da4c2c4f8418f10e815 |
Hashes for bposd-0.0.5-cp39-cp39-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 330fa3ee4ad0ff2e67fe282eef101e31371ebe2cd1f673bd7c4e837381bed553 |
|
MD5 | 3f1141a978baef317b3370c51016e226 |
|
BLAKE2b-256 | 568520c71dde5d2c7ed5e575dceb9d134e8b0413ca3117881eeec05edc212c38 |
Hashes for bposd-0.0.5-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe6e5e6a7d9b7ac599c8ae077f9aa2b71787f3331a8eacf3cd972eaddebd9a52 |
|
MD5 | 62e9d13e0985a21771e5581658b95507 |
|
BLAKE2b-256 | 19cac6f863c155b89c5d292c2656e6d8683f5c5c7dbf9ff413d1baf0dae97715 |
Hashes for bposd-0.0.5-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c2160e65c0da38462bd2b5b9f60db57c4c2e8dabef9509b06ca0ea70521c883 |
|
MD5 | fcd77dada72d3bf08fbcc9ca74517a47 |
|
BLAKE2b-256 | 3cbb7d22bf0073791b213c6fe9971980f9dee70963bed59c88100f536c68d0b4 |
Hashes for bposd-0.0.5-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2895ad5c3cc6bf064a76c37d042022856229a10ccbeff2a4ecd0817480390b36 |
|
MD5 | 52e5e281f5de9e570648c012645fc6f9 |
|
BLAKE2b-256 | 62ebb979ec7e09dd4b13393b497848848f2fdffb4d27bc83b312b21e6a8ea4b5 |
Hashes for bposd-0.0.5-cp38-cp38-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 94cbee5deaeea21f5f9771c1728a5a530a2f262eec852bfbba1e164d62211271 |
|
MD5 | fc8718a78b16bc8f1f89d6f21ac91341 |
|
BLAKE2b-256 | d3a2bbd34507dd35bf42f6137d8a05f378bc74e94de6e9a0d8888360870c285d |
Hashes for bposd-0.0.5-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ef50d3932cd16c73bf985c5fbbef70e855c9cf79de24636d6ce85d6b6f14260 |
|
MD5 | 8474a577d5828f38b2415fdbd09800e6 |
|
BLAKE2b-256 | 9169268b7b15009bbe71be0b29e87ec4b6a57df56e42159830ce8b7cd53cf83c |
Hashes for bposd-0.0.5-cp38-cp38-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 58e9b9e8c77879133c250868e5744840d9130b83f98f57140604b248d047c4cd |
|
MD5 | 0234d9762c10f69141d4fc20b106cac6 |
|
BLAKE2b-256 | 798efe926add68f49b3acb0a3d34fc6f63de5d654b2212c54f061fcad316e6fc |
Hashes for bposd-0.0.5-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d736f69fe6345971b2849b2369043a639b9c433105a06ddafe44fa435fe9c76f |
|
MD5 | 434056acf33c3962927be8b5a4b608c3 |
|
BLAKE2b-256 | 4b5b56eb4016d89deabfe62d56405a948ac8f6a9994004af5ad0c71dc9ed6e82 |
Hashes for bposd-0.0.5-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 394aaf938dc094bdfa179bc6f0c3076c7d341e62340285c2763f977844ab55ec |
|
MD5 | 00eab4a0fe87ff09064dd2de6ea3a121 |
|
BLAKE2b-256 | d08485c2dfa2092b003d17d3e462ba218eed0bf34dc90cbc3e516fc189cedc76 |
Hashes for bposd-0.0.5-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ff5e512572a0892157d8805a38e63780839a4c2b0fffac71b640b4b4b56dcc0 |
|
MD5 | e39d9551023c77d98df504d25e5d62ba |
|
BLAKE2b-256 | c7f365346d74730fb7377764eebcf371c8fcfbb30b076f3e76f4977131e6b846 |
Hashes for bposd-0.0.5-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 292dcea399a81c7478751c565470ed0bfcef6b849f1abe5a5b734fc31c60d4c4 |
|
MD5 | 81fc1a35d73d75f96865962f05ee0379 |
|
BLAKE2b-256 | 5253ec08ec597da31e7d1a8bfbc218e79e067ca8d65938ac9391fd4a0371b37e |
Hashes for bposd-0.0.5-cp37-cp37m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0712eb62c888ad210d21614a80450da55cdb08a07927dff403480bf8d3046d7d |
|
MD5 | 2a1e16a251df7852df220e6ef29b2b6c |
|
BLAKE2b-256 | 7124c0ca692ac801b6cf558d69a376a01ea8970a68b00f5fba95cc24c7d3b7a9 |
Hashes for bposd-0.0.5-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2fd86cc81ad0a3030c195d633f7604ef40b73bfcb6157daab59be9c313086ef2 |
|
MD5 | add2680bf9fa830a2b68591c27980c43 |
|
BLAKE2b-256 | f8b140903e4ca940ef651ec500c27a7b0f59e5797e5b60670de90602913471bc |
Hashes for bposd-0.0.5-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 593471fd7d87fc32a4ca526be744303505d4deb174cff16c11a83875bb2f8836 |
|
MD5 | 044055595f27d61e622d95de6d063943 |
|
BLAKE2b-256 | 81e912bc7764b485413d8215b2db16b97164a00a2ef4bbb09befb39b419671c9 |
Hashes for bposd-0.0.5-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12a93552875ea014a0006f25ab6c38a2f7ff220995b075f250af8d93858889a2 |
|
MD5 | d6a8c188e81a4ffd3c5fbf472706f202 |
|
BLAKE2b-256 | 87220f1b2bbf9d0e7d11f25f41dc5a08d75e105911b7ba8e95d09ffeb36aa17d |
Hashes for bposd-0.0.5-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a3e5780916e92dcb5d035378aa476ab34ba012d3d0b336a6c8c4b8f370c902c2 |
|
MD5 | 10dd25548c55cb1acb1c0997eb8a7a67 |
|
BLAKE2b-256 | 232a64dc80b234a49bb9f13bc016476c103acdebd768932d03c0be0b59ce04ba |
Hashes for bposd-0.0.5-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ea57044099a53c02ffbbbdfc2c19d08b0ae908f95825a61168fcd1df424e26e |
|
MD5 | 12b3e6b5dce4093b870167b1d0a510cc |
|
BLAKE2b-256 | cb2090208b8e6ef85bff4558018137adb8c7993d20329419b9e80033fb5b3bb7 |
Hashes for bposd-0.0.5-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 34dc4a8ff96b8f93d198b8def082668cd4435c664f0e66da2779c79daf6909ab |
|
MD5 | 9afc4b532c04e4d726a65fc3e899a0f8 |
|
BLAKE2b-256 | eea5e51cf13819048133fd56e56acbaba64d679566867091de92b5b7e9800e7c |
Hashes for bposd-0.0.5-cp36-cp36m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf61caffec301c8dbf343320194e99102fb64589af02b5c0de8ac5e8c8f9a9db |
|
MD5 | a83bb2bcb5018e3478da5ddc2b4a68ea |
|
BLAKE2b-256 | e1e82cda50216043aa9dc71444bfda41469d4588cc2d63e1c4ae45e1046e35bb |
Hashes for bposd-0.0.5-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd1adc36daf208f037e28d38bd9209a4af6b21247d9b40572bbc83957e95c09f |
|
MD5 | 37916d2297a4d4f8f4c354e1fb05191a |
|
BLAKE2b-256 | e397aa1d93e0207f2fc521a1bcf9914eab3f2a55b55a1c5828f1e25d41a3eed0 |
Hashes for bposd-0.0.5-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6943d0f68b4a384b5c125025bf388aa5269920551a8c548c9e35b180601c3e78 |
|
MD5 | dec6e83f6ce092a7788c3cf2835f497c |
|
BLAKE2b-256 | 5cd942bd47c3cb7ec39fcafe3dc470b04fb1a70ffc16187c0af53678bddf99bf |
Hashes for bposd-0.0.5-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b166cba224de8f6a6b1cd855ebd7975cc4f53bbba8a35bc1278766205191a450 |
|
MD5 | c251d32ce337030d36c1353eeea7ff90 |
|
BLAKE2b-256 | de0bee69cfe83cfcf367622435ad419b173b9bdb7b6b23605aa9659dacbe4d6f |