Sparse module

This module includes all of the implementation for creating Sparse and Lazy Matrices.

class Sparse.ColMatrix(dims)

Bases: MatrixInterface.SquareMatrix

A type of sparse matrix extending the Square Matrix class

multiply(m)

Multiplies self with another matrix

Parameters

m – (ColMatrix) other matriix on the right hand side of the multiplication

Returns

(ColMatrix) Product of the multiplication

tensorProduct(otherMatrix)

Calculates the tensor product of two Column Matrices.

Parameters

otherMatrix – (ColMatrix) the matrix on the right hand side of the tensor product

Return newMatrix

(ColMatrix) new matrix representing the tensor product

toDense()

Creates a dense numpy matrix representation of the matrix

Return dense

(numpy.ndarray) Numpy array representing the matrix

class Sparse.ColumnElement(j, val)

Bases: object

Column element ina sparse matrix

class Sparse.Gate(dims, sm, qbpos)

Bases: Sparse.LazyMatrix

Lazy representation of a quantum gate

apply(v)

Applies the Gate to a vector

Parameters

v – (array or Vector) The vector the gate will be applied to, must be the same dimesion as self

Return w

(Vector) The result of the application of the gate

class Sparse.LazyMatrix(dims)

Bases: MatrixInterface.SquareMatrix

Creates a lazy matrix

Evaluate()

Evaluates the entire matrix, not recommended to ever call it. Takes a long time and is useless for our purposes Puts the evaluated ColMatrix into self.Cache

multiply(m)

This operation is useless in our case and doesn’t actually work, so … yeah

Parameters

m – (LazyMatrix) matrix to multiply by (perhaps implemented in the future)

Returns

class Sparse.SparseMatrix(n, elements)

Bases: MatrixInterface.Matrix, object

Creates sparse matrix, assumes they are square matrices

Parameters
  • n – (int) dimensions of matrix

  • elements – (list) objects the requisite elements of the matrix

apply(v)

Applies the sparse Matrix to some vector V

Parameters

v – some vector of the Vector() class

Returns

(list) The resultant vector from applying the matrix to v

makedense()

makes a dense matrix

multiply(b)

Multiplies matrix with some other matrix b, will make this apply to none sparse matrices can be called by A*b where A is a sparse matrix

Parameters

b – SparseMatrix()

Returns

(list) the product of two matrices

tensorProduct(a)

Returns the tensor product of two matrices, currently applies to two sparse matrices

Parameters

a – (list) sparse matrix to operate on

Returns

(list) result of tensor product

Sparse.makeSparse(matrix)

Converts dense matrix into sparse matrix in (row, column, value) form

Parameters

matrix – (list) Matrix to be converted to Sparse

Returns

(list) Sparse matrix

Sparse.toColMat(mat)

Creates a ColMatrix representation from an numpy array

Parameters

mat – (numpy.ndarray) Array to be converted

Returns

(ColMatrix) Column matrix representation of mat