Module pyqec.pyqec
A toolbox for classical (and soon quantum) error correction.
Functions
def random_regular_code(...)
-
Samples a random regular codes.
Parameters
block_size
:int
, default= 4
- The number of bits in the code.
number_of_checks
:int
, default= 3
- The number of checks in the code.
bit_degree
:int
, default= 3
- The number of checks connected to each bit.
check_degree
:int
, default= 4
- The number of bits connected to each check.
random_seed
:int
, optional- A seed to feed the random number generator. By default, the rng is initialize from entropy.
tag
:string, option
- An identifier for the code.
Returns
LinearCode
- A random linear code with the given parameters.
Raises
ValueError
- If
block_size * bit_degree != number_of_checks * check_degree
.
Classes
class BinaryMatrix (...)
-
Static methods
def empty(...)
def identity(...)
def zeros(...)
Methods
def dimensions(...)
def dot_with_matrix(...)
def dot_with_vector(...)
def echelon_form(...)
def horizontal_concat_with(...)
def is_empty(...)
def is_one_at(...)
def is_zero(...)
def is_zero_at(...)
def nullspace(...)
def number_of_columns(...)
def number_of_ones(...)
def number_of_rows(...)
def number_of_zeros(...)
def rank(...)
def transposed(...)
def vertical_concat_with(...)
class BinarySymmetricChannel (...)
-
An implementation of a binary symmetric channel.
A binary symmetric channel flips the value of each bits according to a given error probability.
Methods
def error_probability(self)
def sample_error_of_length(self, length)
class BinaryVector (...)
-
Static methods
def empty(...)
def zeros(...)
Methods
def concat(...)
def dot_with(...)
def is_empty(...)
def is_one_at(...)
def is_zero(...)
def is_zero_at(...)
def weight(...)
class FlipDecoder (...)
-
Methods
def decode(...)
def to_json(...)
class LinearCode (parity_check_matrix, generator_matrix, /)
-
An implementation of linear codes optimized for LDPC codes.
A code can be defined from either a parity check matrix
H
or a generator matrixG
. These matrices have the property thatH G^T = 0
.Example
This example shows 2 way to define the Hamming code.
From a parity check matrix
code_from_checks = LinearCode.from_checks( 7, [[0, 1, 2, 4], [0, 1, 3, 5], [0, 2, 3, 6]] )
From a generator matrix
code_from_generators = LinearCode.from_generators( 7, [[0, 4, 5, 6], [1, 4, 5], [2, 4, 6], [3, 5, 6]] )
Comparison
Use the
==
if you want to know if 2 codes have exactly the same parity check matrix and generator matrix. However, since there is freedom in the choice of parity check matrix and generator matrix for the same code, usehas_same_codespace_as
method if you want to know if 2 codes define the same codespace even if they may have different parity check matrix or generator matrix.>>> code_from_checks == code_from_generators False >>> code_from_checks.has_same_codespace_as(code_from_generators) True
Methods
def dimension(self, /)
-
The number of encoded qubits.
def generator_matrix(self)
-
The generator matrix of the code.
def has_codeword(self, message)
-
Checks if the given message is a codeword of the code.
Parameters
message
:list
ofint
- The positions with value 1 in the message.
Returns
bool
- True if the message has the right length and a zero syndrome or False otherwise.
def has_same_codespace_as(self, other)
-
Checks if the other code defined the same codespace as this code.
Parameters
other
:LinearCode
- The code to compare.
Returns
bool
- True if other codewords are exactly the same as this code codewords.
def length(self, /)
-
The number of bits in the code.
def minimal_distance(self)
-
The weight of the small non trivial codeword.
Returns
The minimal distance of the code if the dimension is at least 1 or -1 if the dimension is 0.
Notes
This function execution time scale exponentially with the dimension of the code. Use at your own risk!
def number_of_checks(self)
-
The number of checks in the code.
def number_of_generators(self)
-
The number of codeword generators in the code.
def parity_check_matrix(self)
-
The parity check matrix of the code.
def syndrome_of(self, message)
-
The syndrome of a given message.
Parameters
message
:list
ofint
- The positions with value 1 in the message.
Returns
list
ofint
- The positions where
H y
is 1 whereH
is the parity check matrix of the code andy
the input message.
Raises
ValueError
- If a position in the message is greater or equal to the length of the code.
def tag(self, /)
-
The tag of the code.