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.9-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 60ac2926ec09454e871aa864c9fe2e84dc36363dccf7120b0f98256317dfbc64 |
|
MD5 | e14883fb6afcc8f86894546a1cf2e135 |
|
BLAKE2b-256 | a7f9a2e495e903ae537498b0df86ab310e5ed673ba4885c2b325ada8af794d95 |
Hashes for bposd-0.0.9-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33e9c26c32b7f2cd7e576343c7cd19289f066a1b5657f3df8948003b024ac6f2 |
|
MD5 | 8b311d09c78a56747d9a53f3327ab6c3 |
|
BLAKE2b-256 | 86946e867a5a311e015729f59d59f9a2a5bbbdf760be2d4c982a58ea308b5638 |
Hashes for bposd-0.0.9-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 196ebc5ab1d24846ce58bd744a2d0fb163d5c5837a4088f9df0bedefb12cdbd6 |
|
MD5 | f6c68b403592a4f031ff7aab62255f37 |
|
BLAKE2b-256 | 558d493432b0c848eb859f3d8757778cf382438f1cb498b2620a6ea7c0abf825 |
Hashes for bposd-0.0.9-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1eb042d8369c84128ff27fd7b318204e07f3143815b255b4f76f1c2e0175e7c3 |
|
MD5 | 20f636dca9d1dd48e1c2765135144453 |
|
BLAKE2b-256 | 53308c75a45a2dee1ad9d1ab369492c3196527b28aea61304b7c31a848975d61 |
Hashes for bposd-0.0.9-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59fdebc81a6b107a55dabc5d8449a6418c8e6c4afd891bc83b0d0427edf5766e |
|
MD5 | 624970c4f68df4485a580ba2ea8c333a |
|
BLAKE2b-256 | ff6fb65752d10c1b72362edd786d25132c58ba328fd531aac963658c4f3ac806 |
Hashes for bposd-0.0.9-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92064c82a7bea7e1ccd77d643e96c34e719d751c3b30bbb0cadf10973d51aedb |
|
MD5 | 90cc5068149cd0784ee967aedc85aa96 |
|
BLAKE2b-256 | 2676d4a1d69b464a3150e9a61ca90222a9aebc64fb70a953bab5a4c83b2a01bc |
Hashes for bposd-0.0.9-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf713744c40112c95950b0ccc4161aea3b75d1ff29d498063e9bc8380c27b588 |
|
MD5 | c46211bba5a70c3ee6cc5260e1a1e054 |
|
BLAKE2b-256 | 1bd4d4421fb7a94113bfa4a0c256fa8a24e15d1de0f8bf34c06711aca3da5af5 |
Hashes for bposd-0.0.9-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d7c699b1e479b727f1b2a4559dd5001ddf2c712f69b9099c2d1b4f81fc2ff859 |
|
MD5 | f39b71033a63fe32a2e91bc5f8d9f474 |
|
BLAKE2b-256 | 65827b2f4ab364df69f6fbe04c95453c67583c9ec509fa1070c1794688178445 |
Hashes for bposd-0.0.9-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 21e009beb0ad27b447f195de1b3e4700364511fe2371e1d42f7493b7ba9bcd41 |
|
MD5 | 40d71dfbdd2983b45c9a4e72949904e2 |
|
BLAKE2b-256 | e5858f9e0d4070360d4459edf38b45ac17e5d15266c1e0e1797b9cb9d2265318 |
Hashes for bposd-0.0.9-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81a271f513af4244e384364575f5ebd15fcc13805e971a1357ce97a31c871575 |
|
MD5 | a03bc686a89042753ded865da37a3f56 |
|
BLAKE2b-256 | 57dbc9b5f2b0018d52da9ec5f501d18164a21b8418426680eb8c0812df4a0b79 |
Hashes for bposd-0.0.9-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa65f7ce2913878edab75cb110b2b1ef588b1c4c2a5b9d116990ec1dbae34813 |
|
MD5 | 3c75805a616ec6b6abbc8879fd56e301 |
|
BLAKE2b-256 | bc4bf4e3924a48ab06f4e7aee4e4e070d99ea4d38ffffb8f44888bc2ae843a0a |
Hashes for bposd-0.0.9-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ecf298a9bcf40fe76da0518abc487e8fa334a36119ec55b2350cc56ba8df088 |
|
MD5 | 7e34025596d955442d9b7bbeaaf29c16 |
|
BLAKE2b-256 | 2ba6077efecb0613d490f19d8e7eadec23fc6bdf4f9c822e08a3274c7b8ccc89 |
Hashes for bposd-0.0.9-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f46c3c45b84e642e8c89e187c08715df400a62fc03df3a352aa3b4365fdef19f |
|
MD5 | 7e85cfce5c06afcbb29eace836a363b4 |
|
BLAKE2b-256 | c3e6ad33747edab4a270648eed8e5af5f8c8e87ea40b35c7c44266f9caad33f4 |
Hashes for bposd-0.0.9-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b47adc1c1dd96fec032ff25e8d52de96358fa09de90dada57d71dbb2abd9463 |
|
MD5 | 87e5fc6098a066c0f6de8576f23b0af4 |
|
BLAKE2b-256 | 0db962d75b2d4d694126c355b442a4491ed46db844be2544784513ab905f2abe |