qldpc.math
Miscellaneous mathematical and linear algebra methods.
Attributes
Functions
|
Build a block matrix. |
|
Get the first nonzero column for every row in a matrix. |
|
Construct a dual basis, for which |
|
An orthonormal basis for the row space of a matrix over a finite field. |
|
Natural logarithm of |
|
Convert an integer array that represents a Pauli string into a stim.PauliString. |
|
Convert a stim.PauliString into an integer array, inverting qldpc.math.op_to_string. |
|
Take symplectic vectors to their duals. |
|
Reduce vectors to symplectic hyperbolic pairs and a symplectic radical. |
|
The symplectic weight of vectors. |
Module Contents
- qldpc.math.block_matrix(blocks: collections.abc.Sequence[collections.abc.Sequence[numpy.typing.NDArray[numpy.generic] | int | object]]) numpy.typing.NDArray[numpy.int_][source]
Build a block matrix.
Literal 0 entries are replaced by zero matrices, and literal 1 entries are replaced by an identity matrix (padded below and to the right with zeros, if necessary).
- qldpc.math.first_nonzero_cols(matrix: numpy.typing.NDArray[numpy.generic] | collections.abc.Sequence[numpy.typing.NDArray[numpy.generic]]) numpy.typing.NDArray[numpy.int_][source]
Get the first nonzero column for every row in a matrix.
If all columns are zero in a particular row, the column value is set to the number of columns.
If the input
matrixhas more than two dimensions, return anoutputvector of lengthmatrix.shape[0], whereoutput[r]is the first “column”cfor whichnp.any(matrix[r, c])is nonzero; (or setoutput[r] = matrix.shape[1]ifnot np.any(matrix[r])).
- qldpc.math.get_dual_basis(basis: galois.FieldArray, *, validate: bool = True) galois.FieldArray[source]
Construct a dual basis, for which
dual_basis @ basis.T = identity_matrix.The rows of
basismust be linearly independent, and it must have at least as many columns as rows; a dual basis exists only in that case.- Parameters:
basis – A full-row-rank matrix with at least as many columns as rows, whose rows form the basis to dualize.
validate – If True (default), check the precondition above and raise a
ValueErrorwhen it fails. Pass False to skip the check when the precondition is already guaranteed.
- qldpc.math.get_orthonormal_basis(matrix: galois.FieldArray, *, promise_full_rank: bool = False) galois.FieldArray | None[source]
An orthonormal basis for the row space of a matrix over a finite field.
Given a matrix whose rows span a subspace V of
GF(q)^n, return a matrix L whose rows are a basis for V withL @ L.T = identity– that is, a basis of V whose vectors each have self-overlapv @ v = 1and are pairwise orthogonal under the dot product. If V has no such basis, return None.The rows of the matrix may be linearly dependent; they are first reduced to a basis of V. Pass promise_full_rank=True to skip this reduction when the rows are already independent.
An orthonormal basis for V exists if and only if (a) V is nondegenerate, meaning no nonzero vector of V is orthogonal to all of V, and (b), according to the field’s characteristic:
over a field of characteristic 2, some vector of V has nonzero self-overlap
v @ v;over a field of odd characteristic, an even number of the vectors in any mutually orthogonal basis of V have a self-overlap with no square root in
GF(q).
The construction is a variant of Gram-Schmidt orthogonalization; the characteristic-2 case follows Algorithm 1 and Lemma 2 of https://arxiv.org/abs/2503.19790.
- qldpc.math.log_choose(n: int, k: int) float[source]
Natural logarithm of
(n choose k) = n! / ( k! * (n-k)! ).
- qldpc.math.op_to_string(op: numpy.typing.NDArray[numpy.int_]) stim.PauliString[source]
Convert an integer array that represents a Pauli string into a stim.PauliString.
The (first, second) half the array indicates the support of (X, Z) Paulis.
- qldpc.math.string_to_op(string: stim.PauliString, num_qubits: int | None = None) numpy.typing.NDArray[numpy.int_][source]
Convert a stim.PauliString into an integer array, inverting qldpc.math.op_to_string.
The (first, second) half the array indicates the support of (X, Z) Paulis.
- qldpc.math.symplectic_conjugate(vectors: DenseIntegerArrayType) DenseIntegerArrayType[source]
Take symplectic vectors to their duals.
The symplectic conjugate of a Pauli string swaps its X and Z support, and multiplies its Z sector by -1, taking
Q = [Q_x|Q_z] -> [Q_z|-Q_x], such that the symplectic inner product between Pauli strings P and Q is⟨P,Q⟩_s = P_x @ Q_z - P_z @ Q_x = P @ symplectic_conjugate(Q).
- qldpc.math.symplectic_gram_schmidt(vectors: galois.FieldArray, *, promise_full_rank: bool = False) tuple[galois.FieldArray, galois.FieldArray][source]
Reduce vectors to symplectic hyperbolic pairs and a symplectic radical.
The rows of
vectorsspan a subspace V ofGF(q)^(2n)equipped with the symplectic inner product⟨a, b⟩_s = a @ symplectic_conjugate(b)(see symplectic_conjugate). Return a pair(hyperbolic, radical):hyperbolichas shape(2m, 2n)and holdsmmutually orthogonal hyperbolic pairs. Its rows are ordered[b_0, ..., b_{m-1}, c_0, ..., c_{m-1}], so thathyperbolic @ symplectic_conjugate(hyperbolic).Tis the block matrix[[0, I], [-I, 0]]:⟨b_i, c_j⟩_s = δ_ijand all other products vanish.radicalspans the symplectic radical of V – the vectors of V that are orthogonal to all of V. Its rows are isotropic and orthogonal to every row ofhyperbolicandradical.
Together the rows of
hyperbolicandradicalform a basis for V. The rows ofvectorsmay be linearly dependent; they are first reduced to a basis of V. Pass promise_full_rank=True to skip this reduction when the rows are already independent; passing it for dependent rows leaves the dependent directions inradicalas spurious (possibly zero) rows, though thehyperbolicpairs stay correct.Because the symplectic form is alternating,
⟨v, v⟩_s = 0for every vector in every characteristic, so – unlike get_orthonormal_basis – there is no unit-vector case: the construction peels off one hyperbolic pair at a time and collects the leftover radical.
- qldpc.math.symplectic_weight(vectors: numpy.typing.NDArray[numpy.int_]) numpy.typing.NDArray[numpy.int_][source]
The symplectic weight of vectors.
The symplectic weight of a Pauli string is the number of qudits that it addresses nontrivially. Returns one weight per input vector (a 0-dimensional array for a single vector).
- qldpc.math.DenseIntegerArray
- qldpc.math.DenseIntegerArrayType
- qldpc.math.IntegerArray
- qldpc.math.SparseIntegerArray