qldpc.codes.classical

Classical error-correcting codes.

Classes

BCHCode

Classical BCH (Bose-Chaudhuri-Hocquenghem) code.

CyclicCode

Classical cyclic code.

ExtendedHammingCode

Classical extended Hamming code: the ordinary Hamming code with an extra parity bit.

GolayCode

Classical binary [23, 12, 7] Golay code.

HammingCode

Classical Hamming code.

ReedMullerCode

Classical Reed-Muller code.

ReedSolomonCode

Classical Reed-Solomon code.

RepetitionCode

Classical repetition code: the [n, 1, n] code whose code words are constant vectors.

RingCode

Classical ring code: repetition code with periodic boundary conditions.

SimplexCode

Classical simplex code: the dual of the Hamming code.

TannerCode

Classical Tanner code.

Module Contents

class qldpc.codes.classical.BCHCode(length: int, dimension: int, field: int | type[galois.FieldArray] | None = None)[source]

Bases: qldpc.codes.common.ClassicalCode

Classical BCH (Bose-Chaudhuri-Hocquenghem) code.

Source: https://mhostetter.github.io/galois/latest/api/galois.BCH

References:

class qldpc.codes.classical.CyclicCode(bits: int, poly: sympy.Basic, field: int | type[galois.FieldArray] | None = None)[source]

Bases: qldpc.codes.common.ClassicalCode

Classical cyclic code.

A CyclicCode is determined by an integer block length and an integer polynomial in one variable. The parity check matrix of a CyclicCode is obtained by interpreting the polynomial as an element of a cyclic group algebra, and lifting this polynomial to a square matrix. The multiplicative identity and the generator of the group correspond, respectively, to the identity and shift matrices.

The CyclicCode with polynomial 1 - x is a RingCode.

References:

class qldpc.codes.classical.ExtendedHammingCode(size: int)[source]

Bases: qldpc.codes.common.ClassicalCode

Classical extended Hamming code: the ordinary Hamming code with an extra parity bit.

The extended Hamming code of size m is also equal to ReedMullerCode(m - 2, m).

References:

class qldpc.codes.classical.GolayCode[source]

Bases: CyclicCode

Classical binary [23, 12, 7] Golay code.

A famous “perfect” cyclic code: every 23-bit word lies within distance 3 of a unique codeword, so it corrects any 3 bit-flip errors. As a cyclic code, its codewords are the multiples (mod x^23 - 1) of the Golay generator polynomial g(x), a degree-11 factor of x^23 - 1.

The parity checks are the cyclic shifts of the weight-8 polynomial h(x) = (x + 1) g(x), which generates the dual code G^perp = [23, 11, 8].

References:

class qldpc.codes.classical.HammingCode(size: int, field: int | type[galois.FieldArray] | None = None)[source]

Bases: qldpc.codes.common.ClassicalCode

Classical Hamming code.

When working over the binary field (0s and 1s), the parity check matrix of the HammingCode is built by stacking together (as columns) all nonzero bitstrings. More generally, the parity check matrix is built from a maximal set of linearly independent nonzero vectors over a finite field; equivalently, from all vectors whose first nonzero element is a 1.

References:

class qldpc.codes.classical.ReedMullerCode(order: int, size: int, field: int | type[galois.FieldArray] | None = None)[source]

Bases: qldpc.codes.common.ClassicalCode

Classical Reed-Muller code.

A Reed-Muller code with order r and size m, denoted RM(r, m), has code parameters

[2**m, k, 2**(m-r)]

where

k = sum_(j = 0)^r (m choose j).

References:

static get_generator(order: int, size: int) → numpy.typing.NDArray[numpy.int_][source]

Get the generator matrix for the specified Reed-Muller code.

property order: int

The order parameter of this code.

property size: int

The size parameter of this code.

class qldpc.codes.classical.ReedSolomonCode(bits: int, dimension: int)[source]

Bases: qldpc.codes.common.ClassicalCode

Classical Reed-Solomon code.

Source: https://mhostetter.github.io/galois/latest/api/galois.ReedSolomon

References:

class qldpc.codes.classical.RepetitionCode(bits: int, field: int | type[galois.FieldArray] | None = None)[source]

Bases: qldpc.codes.common.ClassicalCode

Classical repetition code: the [n, 1, n] code whose code words are constant vectors.

References:

class qldpc.codes.classical.RingCode(bits: int, field: int | type[galois.FieldArray] | None = None)[source]

Bases: qldpc.codes.common.ClassicalCode

Classical ring code: repetition code with periodic boundary conditions.

The periodic boundary adds one (redundant) parity check, so a RingCode has the same code words as a RepetitionCode of the same block length, and hence the same [n, 1, n] parameters.

References:

class qldpc.codes.classical.SimplexCode(dim: int, field: int | type[galois.FieldArray] | None = None)[source]

Bases: qldpc.codes.common.ClassicalCode

Classical simplex code: the dual of the Hamming code.

A simplex code of dimension k over a field of order q has code parameters

[(q**k - 1) / (q - 1), k, q ** (k - 1)].

Its generator matrix has one column for each point of the projective space PG(k - 1, q), that is, one representative of each family of nonzero vectors of F_q**k that are scalar multiples of one another. Those columns are precisely the parity checks of a Hamming code of the same rank, which is what makes a simplex code the dual of a Hamming code.

Over the binary field the scalar multiples of a nonzero vector are just the vector itself, so the block length is 2**k - 1 and the code has a cyclic presentation: its parity checks are the cyclic shifts of a three-term polynomial, and therefore all have weight 3. That presentation is used here for binary codes, since low-weight parity checks are what make simplex codes attractive as the building blocks of a SHYPSCode. It does not carry over to q > 2, where a cyclic code of length q**k - 1 would instead be the (q - 1)-fold repetition of the simplex code.

Over the binary field the automorphism group of this code is the general linear group GL(k, 2).

References:

static get_defining_polynomial(dim: int, field: int | type[galois.FieldArray] | None = None) → galois.Poly[source]

The polynomial defining the cyclic presentation of a simplex code.

The cyclic code of length field.order**dim - 1 with this check polynomial is a simplex code when field.order == 2, and the (field.order - 1)-fold repetition of one otherwise.

Returns a three-term polynomial of the form h(x) = 1 + a * x**c + b * x**d, where

  • the coefficients a and b are elements of a finite field,

  • the exponents c and d are integers, and

  • gcd(h(x), x ** (field**dim - 1) - 1) is a primitive polynomial of degree dim.

A dimension of at least 2 is required: a one-dimensional simplex code has block length field.order - 1 == 1, for which no nontrivial check polynomial exists.

class qldpc.codes.classical.TannerCode(subgraph: qldpc._util.networkx.Graph, subcode: qldpc.codes.common.ClassicalCode)[source]

Bases: qldpc.codes.common.ClassicalCode

Classical Tanner code.

A Tanner code T(G,C) is constructed from: [1] A bipartite “half-regular” graph G. That is, a graph…

… with two sets of nodes, V and W. … in which all nodes in V have degree n.

[2] A classical code C on n bits.

For convenience, we make G directed, with edges directed from V to W. The node sets V and W can then be identified, respectively, by the sources and sinks of G.

The Tanner code T(G,C) is defined on |W| bits. A |W|-bit string x is a code word of T(G,C) iff, for every node v in V, the bits of x incident to v are a code word of C.

This construction requires an ordering of the edges E(v) adjacent to each vertex v. This class sorts E(v) by the value of the “sort” attribute attached to each edge. If there is no “sort” attribute, its value is treated as the corresponding neighbor of v.

Tanner codes can similarly be defined on regular (undirected) graphs G' = (V',E') by placing checks on V’ and bits on E’.

Notes:

  • If the subcode C has m checks, its parity matrix has shape (m,n).

  • The code T(G,C) has |W| bits and |V|m checks.

References:

static as_directed_subgraph(subgraph: qldpc._util.networkx.Graph) → qldpc._util.networkx.DiGraph[source]

Convert an undirected graph for a Tanner code into a directed graph for the same code.

subcode: qldpc.codes.common.ClassicalCode
subgraph: qldpc._util.networkx.DiGraph