pygsti.baseobjs.basisconstructors.MatrixBasisConstructor#

class MatrixBasisConstructor(longname, matrixgen_fn, labelgen_fn, real, first_element_is_identity)#

Bases: object

A factory class for constructing builtin basis types whose elements are matrices.

Parameters:
  • longname (str) – The long name for the builtin basis.

  • matrixgen_fn (function) – A function that generates the matrix elements for this basis given the matrix dimension (i.e. the number of rows or columns in the matrices to produce).

  • labelgen_fn (function) – A function that generates the element labels for this basis given the matrix dimension (i.e. the number of rows or columns in the matrices to produce).

  • real (bool) – Whether vectors expressed in this basis are required to have real components.

Create a new MatrixBasisConstructor:

Parameters:
  • longname (str) – The long name for the builtin basis.

  • matrixgen_fn (function) – A function that generates the matrix elements for this basis given the matrix dimension (i.e. the number of rows or columns in the matrices to produce).

  • labelgen_fn (function) – A function that generates the element labels for this basis given the matrix dimension (i.e. the number of rows or columns in the matrices to produce).

  • real (bool) – Whether vectors expressed in this basis are required to have real components.

Methods

__init__(longname, matrixgen_fn, ...)

Create a new MatrixBasisConstructor:

constructor(dim, sparse)

Get the elements of a basis to be constructed.

labeler(dim, sparse)

Get the labels of a basis to be constructed.

matrix_dim(dim)

Helper function that converts a vector-space dimension dim to matrix-dimension by taking a sqrt.

sizes(dim, sparse)

Get some relevant sizes/dimensions for constructing a basis.

constructor(dim, sparse)#

Get the elements of a basis to be constructed.

Parameters:
  • dim (int) – The vector-space dimension of the basis.

  • sparse (bool) – Whether the basis is sparse or not.

Return type:

list of basis elements

labeler(dim, sparse)#

Get the labels of a basis to be constructed.

Parameters:
  • dim (int) – The vector-space dimension of the basis.

  • sparse (bool) – Whether the basis is sparse or not.

Return type:

list of labels (strs)

matrix_dim(dim)#

Helper function that converts a vector-space dimension dim to matrix-dimension by taking a sqrt.

Parameters:

dim (int) – Dimension

Return type:

int

sizes(dim, sparse)#

Get some relevant sizes/dimensions for constructing a basis.

This function is needed for constructing Basis objects because these objects want to know the size & dimension of a basis without having to construct the (potentially large) set of elements.

Parameters:
  • dim (int) – The vector-space dimension of the basis. e.g. 4 for a basis of 2x2 matrices and 2 for a basis of length=2 vectors.

  • sparse (bool) – Whether the basis is sparse or not.

Returns:

  • nElements (int) – The number of elements in the basis.

  • dim (int) – The vector-space dimension of the basis.

  • elshape (tuple) – The shape of the elements that might be constructed (if constructor was called).

Return type:

tuple[int, int, tuple[int, int]]