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.4-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0998c52bd68700d722381a0428d262abcc799f5cf15d3517949dc59808362853 |
|
MD5 | 16ba3a66bbe236abca5e5045af4f1e15 |
|
BLAKE2b-256 | bf851924498918c6ad36f2da5d71ec376d198b27c56a9b32c6acae4083f0aeec |
Hashes for bposd-0.0.4-cp39-cp39-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 94008e148a495199d66c1e1c3f0da87ab7c4a2a5ce2b0b90e5fd7712e46292f1 |
|
MD5 | 4ec9f097b449c92b3ca10fe88ffcdf12 |
|
BLAKE2b-256 | ef6a84e13a1618f4de86845b6b20c9d1f4e10bd5a141cb118856640a8bbee0cf |
Hashes for bposd-0.0.4-cp39-cp39-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5bcca1cb7a1f979782a9c0825500a0cec413cbb196a4c683d834fbda172a6f1d |
|
MD5 | 480318087623cd76ee033d3c1e590ba2 |
|
BLAKE2b-256 | 00f3a59b306662c9b5ddec0c403608e2ce9f5a5d83f9b02c8986637374f2e5c4 |
Hashes for bposd-0.0.4-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 52976605acf4b757d9673d19b18b24cb601c8f94bc3d965d34d42999ae787d29 |
|
MD5 | 95bcf451cbe9561855d4b8a02a06cd2a |
|
BLAKE2b-256 | a82280f2c815dcb029d371e33517025f19c701f105f8bc2efd34f77e52432234 |
Hashes for bposd-0.0.4-cp39-cp39-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 001eb2fed9bd14dab0f8f15ecf52b5fa4b4f378f5e284c733102d54957945c30 |
|
MD5 | ea6dbf0d3ae60e0443192360cc49cd4c |
|
BLAKE2b-256 | 24a7a6ea872fb8e4a0d126259ec9be22bcd53f4aa5162928c46956d8dcddff3e |
Hashes for bposd-0.0.4-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 05a95c72ec4b24246d2b3f36c12ec9cb1e44e2bf4d1fc6a03b423ec9745ae7cb |
|
MD5 | 3752c7decd0c6e6da34590262ee8a138 |
|
BLAKE2b-256 | d0cfbd4b747d5d68735d1f33ee01b53e90cff1b20fa7c6831518cb23fc230284 |
Hashes for bposd-0.0.4-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 13dbaff3e9e4d8d9973092ca8d50cd908273de0b50d510cc033e3f400424f3c4 |
|
MD5 | 22dfa3334140b905f8a631dd150e6f21 |
|
BLAKE2b-256 | b6fed5dc82a4e3ee99b3c18f3c2fdab6113ed4dc859cbe6bb1710c96fe7f4e02 |
Hashes for bposd-0.0.4-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0629faf5236970d5abcf959d3b3477aa787f89f3a69aafa35aa431876a341f36 |
|
MD5 | a03b947858392f82cc84d0354fe4b2f1 |
|
BLAKE2b-256 | 8437cb9dff31c9537606c3cedee8eda134147047f7769f4864c60d7f9657b0e0 |
Hashes for bposd-0.0.4-cp38-cp38-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f18a1920ce78e43f057ac778cc7c41f4d9314dec63798f6244a958ebc9fd43d |
|
MD5 | ed904fe238d2945c98f7304b586e76ed |
|
BLAKE2b-256 | 0d452be83456d14037804a64e206ee0e00a94b69521da197b582a3e639eca656 |
Hashes for bposd-0.0.4-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 80a3458ece5b23548f95db1d1d42200df237890f14f43c21503799090c8589c9 |
|
MD5 | e68eb7dedba95bf0adf3570a45622b3d |
|
BLAKE2b-256 | ec3003a031caf6bb6974f3ba825d2e0e97883308dd61fa606dca7f1c83f7a937 |
Hashes for bposd-0.0.4-cp38-cp38-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ef4baaed090a35758f668b1066a6b9ab460fc8b9a543ff9fee3a9871381851ae |
|
MD5 | dd2486e0bc6097ea25d66f59196d04fd |
|
BLAKE2b-256 | aa928e9d359134352c7a95370ffe16ce62563365167a21d2b37018a5a48b26eb |
Hashes for bposd-0.0.4-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d755a30cc9fb6ff9a797c0e35a25210aa7a56e6193712d1f444a675023d5c0dd |
|
MD5 | b7272639e0d2ec79b96922825f5e50f3 |
|
BLAKE2b-256 | 6b32627c8251f5150fd8f295f03acfb25a80264e844628ca713446f5d0a6b649 |
Hashes for bposd-0.0.4-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8598b09597d4b790ec6536227837d068e6a6318638e5c48644476cc85f2b9bd1 |
|
MD5 | 6fae4dd20fcb3010af9cdbb4f577a5bd |
|
BLAKE2b-256 | ed04579bf4d2e266ad667a6c5f5e324185b0242a395d06ed98c6a008397229df |
Hashes for bposd-0.0.4-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 02714256c2290e153fe352a62e7d71141841d28d6e0264abe5f7e0b0f30741d8 |
|
MD5 | c003313887375553b9ce0fc101d8c16d |
|
BLAKE2b-256 | 4ad6b073547c08275c94d20456b2ee9f32b44ed5b0f0964548712a08b1f0a735 |
Hashes for bposd-0.0.4-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2205361950f067c34a710a786c93677bc29129abcefad18883d79e84b3dc444c |
|
MD5 | c070660a1d4fbcc0825eac66e763a705 |
|
BLAKE2b-256 | 51299ae90593af2be17fba13f1bfbeeaf914428b3a26b8d40ae487ee7dec4866 |
Hashes for bposd-0.0.4-cp37-cp37m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f10306ba197955ee512f4d7a6dca65f29944479ca69c83c59f1f4a15e9697aea |
|
MD5 | 91a5ecd052a75aae6ec654bab423e502 |
|
BLAKE2b-256 | b7ba68516fbfa124a381711d6483bafba40e9e1f203acb80b19b1e2b02771aba |
Hashes for bposd-0.0.4-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6a4caeeae0280d5e5cdeb270bf5140f7e9a7f863d8b88199ccc58051c6ebb28 |
|
MD5 | a8ebabc3e5a4c4c7b3da02b78a0b241d |
|
BLAKE2b-256 | 35292a7db8f545a9b1c1fa1606806a5f181360e45dad7c0ee64d17649d211c50 |
Hashes for bposd-0.0.4-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e4a1523fc1768c7cf1155c62500d3537d6e791f888b6d135b384d407e5710af3 |
|
MD5 | ec2a2ec44791ab41a6d210c6015a3168 |
|
BLAKE2b-256 | 4da79e09909baf5f9517da32199231c509a1d8e8eab214e8b595d9a203554636 |
Hashes for bposd-0.0.4-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 676106de2fca6134a5a38748b5441a7bf13b356697eeabd2e4ba7b04519dc4c1 |
|
MD5 | daa55032e9416cbb8bbd2617bbe86bf1 |
|
BLAKE2b-256 | 58674f81b2cc7273facbad02ba80610e6833d43db4c4ccd1db3ff3a1fd5d4ac5 |
Hashes for bposd-0.0.4-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 817ae9d666bf4443eac7ff6cf555acd34fa1064b88c61c7d203041bd57d88d29 |
|
MD5 | b9bb145231185c70a55438939ba5f6fa |
|
BLAKE2b-256 | ebabff6142786a74d1f12e4594f434d7a6bf91f1990dae2fb0dd0d827800ebe3 |
Hashes for bposd-0.0.4-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fc9e73a751a4dca3219a939b73888d0342983e29f52278c258a46e49bf47d6ac |
|
MD5 | 72315a05a54c64e053ee85e777cbf049 |
|
BLAKE2b-256 | 6a954c383aa894ecaf99862ce88230b984cf01d0b95651b658c552537eeaab7b |
Hashes for bposd-0.0.4-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04d76b596480089207807681b8f8daa7e0fefa91a6bcf7ba9e0b8e444e700d72 |
|
MD5 | 178035cdf855049ce7b664f56b4cebce |
|
BLAKE2b-256 | 0d2eec14b06f677133e930d174dd9737d7818633abe20a6131c912ab24749da3 |
Hashes for bposd-0.0.4-cp36-cp36m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 189cb1fa6e54868922d6342aa3608b7b09a0d6cdfa143c8cc17ff04c080b00b0 |
|
MD5 | b65723edd3d022a6e0d814ac19e3a92e |
|
BLAKE2b-256 | e6f22e089bfad4cde6661d25a4ff840d33661f2888fa160549626ac4405b996f |
Hashes for bposd-0.0.4-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 435fcd3312725639339ef7c21692a57a64c3d059ec5d15854f6f7644b4ea3031 |
|
MD5 | 45aa716ff9197a6c17a0605ac9787856 |
|
BLAKE2b-256 | 888d286063c610ee4736c256f2883979ed1ac9bb18f54baa07167d8bda4063b8 |
Hashes for bposd-0.0.4-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c3936607cf1009c5a9c1b19636a1fda98d0fe45f9907d41e2b989246c7702745 |
|
MD5 | ed11ff3a63aeb644812f41d8d257718b |
|
BLAKE2b-256 | ce2a474ea3067df86c9423438bf5c9322c49d9c18cfce9215e591b200a160d14 |
Hashes for bposd-0.0.4-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d66c1c87b8c127a2a21f40338666923ebaedbf1c19e30763941b35c2d6d098d |
|
MD5 | 4076195cb58972a3261bc037a31135c1 |
|
BLAKE2b-256 | 6a7cda639eae94f02d57839d188e8d4665b9cb8a791ce3a3cc149a93ca13b4f4 |