pygsti.tools.matrixmod2

General matrix utilities. Some, but not all, are specific to matrices over the ints modulo 2.

Module Contents

Functions

dot_mod2(m1, m2)

Returns the product over the integers modulo 2 of two matrices.

multidot_mod2(mlist)

Returns the product over the integers modulo 2 of a list of matrices.

det_mod2(m)

Returns the determinant of a matrix over the integers modulo 2 (GL(n,2)).

matrix_directsum(m1, m2)

Returns the direct sum of two square matrices of integers.

inv_mod2(m)

Finds the inverse of a matrix over GL(n,2)

Axb_mod2(A, b)

Solves Ax = b over GF(2)

gaussian_elimination_mod2(a)

Gaussian elimination mod2 of a.

diagonal_as_vec(m)

Returns a 1D array containing the diagonal of the input square 2D array m.

strictly_upper_triangle(m)

Returns a matrix containing the strictly upper triangle of m and zeros elsewhere.

diagonal_as_matrix(m)

Returns a diagonal matrix containing the diagonal of m.

albert_factor(d[, failcount, rand_state])

Returns a matrix M such that d = M M.T for symmetric d, where d and M are matrices over [0,1] mod 2.

random_bitstring(n, p[, failcount, rand_state])

Constructs a random bitstring of length n with parity p

random_invertable_matrix(n[, failcount, rand_state])

Finds a random invertable matrix M over GL(n,2)

random_symmetric_invertable_matrix(n[, failcount, ...])

Creates a random, symmetric, invertible matrix from GL(n,2)

onesify(a[, failcount, maxfailcount, rand_state])

Returns M such that M a M.T has ones along the main diagonal

permute_top(a, i)

Permutes the first row & col with the i'th row & col

fix_top(a)

Computes the permutation matrix P such that the [1:t,1:t] submatrix of P a P is invertible.

proper_permutation(a)

Computes the permutation matrix P such that all [n:t,n:t] submatrices of P a P are invertible.

pygsti.tools.matrixmod2.dot_mod2(m1, m2)

Returns the product over the integers modulo 2 of two matrices.

Parameters

m1numpy.ndarray

First matrix

m2numpy.ndarray

Second matrix

Returns

numpy.ndarray

pygsti.tools.matrixmod2.multidot_mod2(mlist)

Returns the product over the integers modulo 2 of a list of matrices.

Parameters

mlistlist

A list of matrices.

Returns

numpy.ndarray

pygsti.tools.matrixmod2.det_mod2(m)

Returns the determinant of a matrix over the integers modulo 2 (GL(n,2)).

Parameters

mnumpy.ndarray

Matrix to take determinant of.

Returns

numpy.ndarray

pygsti.tools.matrixmod2.matrix_directsum(m1, m2)

Returns the direct sum of two square matrices of integers.

Parameters

m1numpy.ndarray

First matrix

m2numpy.ndarray

Second matrix

Returns

numpy.ndarray

pygsti.tools.matrixmod2.inv_mod2(m)

Finds the inverse of a matrix over GL(n,2)

Parameters

mnumpy.ndarray

Matrix to take inverse of.

Returns

numpy.ndarray

pygsti.tools.matrixmod2.Axb_mod2(A, b)

Solves Ax = b over GF(2)

Parameters

Anumpy.ndarray

Matrix to operate on.

bnumpy.ndarray

Vector to operate on.

Returns

numpy.ndarray

pygsti.tools.matrixmod2.gaussian_elimination_mod2(a)

Gaussian elimination mod2 of a.

Parameters

anumpy.ndarray

Matrix to operate on.

Returns

numpy.ndarray

pygsti.tools.matrixmod2.diagonal_as_vec(m)

Returns a 1D array containing the diagonal of the input square 2D array m.

Parameters

mnumpy.ndarray

Matrix to operate on.

Returns

numpy.ndarray

pygsti.tools.matrixmod2.strictly_upper_triangle(m)

Returns a matrix containing the strictly upper triangle of m and zeros elsewhere.

Parameters

mnumpy.ndarray

Matrix to operate on.

Returns

numpy.ndarray

pygsti.tools.matrixmod2.diagonal_as_matrix(m)

Returns a diagonal matrix containing the diagonal of m.

Parameters

mnumpy.ndarray

Matrix to operate on.

Returns

numpy.ndarray

pygsti.tools.matrixmod2.albert_factor(d, failcount=0, rand_state=None)

Returns a matrix M such that d = M M.T for symmetric d, where d and M are matrices over [0,1] mod 2.

The algorithm mostly follows the proof in “Orthogonal Matrices Over Finite Fields” by Jessie MacWilliams in The American Mathematical Monthly, Vol. 76, No. 2 (Feb., 1969), pp. 152-164

There is generally not a unique albert factorization, and this algorthm is randomized. It will general return a different factorizations from multiple calls.

Parameters

darray-like

Symmetric matrix mod 2.

failcountint, optional

UNUSED.

rand_statenp.random.RandomState, optional

Random number generator to allow for determinism.

Returns

numpy.ndarray

pygsti.tools.matrixmod2.random_bitstring(n, p, failcount=0, rand_state=None)

Constructs a random bitstring of length n with parity p

Parameters

nint

Number of bits.

pint

Parity.

failcountint, optional

Internal use only.

rand_statenp.random.RandomState, optional

Random number generator to allow for determinism.

Returns

numpy.ndarray

pygsti.tools.matrixmod2.random_invertable_matrix(n, failcount=0, rand_state=None)

Finds a random invertable matrix M over GL(n,2)

Parameters

nint

matrix dimension

failcountint, optional

Internal use only.

rand_statenp.random.RandomState, optional

Random number generator to allow for determinism.

Returns

numpy.ndarray

pygsti.tools.matrixmod2.random_symmetric_invertable_matrix(n, failcount=0, rand_state=None)

Creates a random, symmetric, invertible matrix from GL(n,2)

Parameters

nint

Matrix dimension.

failcountint, optional

Internal use only.

rand_statenp.random.RandomState, optional

Random number generator to allow for determinism.

Returns

numpy.ndarray

pygsti.tools.matrixmod2.onesify(a, failcount=0, maxfailcount=100, rand_state=None)

Returns M such that M a M.T has ones along the main diagonal

Parameters

anumpy.ndarray

The matrix.

failcountint, optional

Internal use only.

maxfailcountint, optional

Maximum number of tries before giving up.

rand_statenp.random.RandomState, optional

Random number generator to allow for determinism.

Returns

numpy.ndarray

pygsti.tools.matrixmod2.permute_top(a, i)

Permutes the first row & col with the i’th row & col

Parameters

anumpy.ndarray

The matrix to act on.

iint

index to permute with first row/col.

Returns

numpy.ndarray

pygsti.tools.matrixmod2.fix_top(a)

Computes the permutation matrix P such that the [1:t,1:t] submatrix of P a P is invertible.

Parameters

anumpy.ndarray

A symmetric binary matrix with ones along the diagonal.

Returns

numpy.ndarray

pygsti.tools.matrixmod2.proper_permutation(a)

Computes the permutation matrix P such that all [n:t,n:t] submatrices of P a P are invertible.

Parameters

anumpy.ndarray

A symmetric binary matrix with ones along the diagonal.

Returns

numpy.ndarray