quara.objects.matrix_basis module
- class MatrixBasis(basis)[source]
Bases:
quara.objects.matrix_basis.Basis- Parameters
basis (List[numpy.ndarray]) –
- property dim: int
Returns dim of matrix.
- Returns
dim of matrix.
- Return type
int
- is_0thpropI()[source]
Returns whether first matrix is constant multiple of identity matrix.
- Returns
True where first matrix is constant multiple of identity matrix, False otherwise.
- Return type
bool
- is_hermitian()[source]
Returns whether matrices are Hermitian.
- Returns
True where matrices are Hermitian, False otherwise.
- Return type
bool
- is_normal()[source]
Returns whether matrices are normalized.
- Returns
True where matrices are normalized, False otherwise.
- Return type
bool
- is_orthogonal()[source]
Returns whether matrices are orthogonal.
- Returns
True where matrices are orthogonal, False otherwise.
- Return type
bool
- is_trace_less()[source]
Returns whether matrices are traceless except for first matrix.
- Returns
True where matrices are traceless except for first matrix, False otherwise.
- Return type
bool
- size()[source]
Returns shape(=size) of basis.
- Returns
shape(=size) of basis.
- Return type
Tuple[int, int]
- class SparseMatrixBasis(basis)[source]
Bases:
quara.objects.matrix_basis.MatrixBasis- Parameters
basis (List[numpy.ndarray]) –
- is_0thpropI()[source]
Returns whether first matrix is constant multiple of identity matrix.
- Returns
True where first matrix is constant multiple of identity matrix, False otherwise.
- Return type
bool
- is_hermitian()[source]
Returns whether matrices are Hermitian.
- Returns
True where matrices are Hermitian, False otherwise.
- Return type
bool
- class VectorizedMatrixBasis(source)[source]
Bases:
quara.objects.matrix_basis.Basis- Parameters
source (quara.objects.matrix_basis.MatrixBasis) –
- property dim: int
Returns dim of matrix.
- Returns
dim of matrix
- Return type
int
- is_hermitian()[source]
Returns whether matrices are Hermitian.
- Returns
True where matrices are Hermitian, False otherwise.
- Return type
bool
- is_normal()[source]
Returns whether matrices are normalized.
- Returns
True where matrices are normalized, False otherwise.
- Return type
bool
- is_orthogonal()[source]
Returns whether matrices are orthogonal.
- Returns
True where matrices are orthogonal, False otherwise.
- Return type
bool
- is_scalar_mult_of_identity()[source]
Returns whether first matrix is constant multiple of identity matrix.
- Returns
True where first matrix is constant multiple of identity matrix, False otherwise.
- Return type
bool
- is_trace_less()[source]
Returns whether matrices are traceless except for first matrix.
- Returns
True where matrices are traceless except for first matrix, False otherwise.
- Return type
bool
- property org_basis: quara.objects.matrix_basis.MatrixBasis
Original matrix basis.
- Returns
Original matrix basis.
- Return type
- calc_hermitian_matrix_expansion_coefficient_hermitian_basis(from_mat, basis)[source]
return expansion coefficients of an Hermitian matrix w.r.t. the Hermitian matrix basis.
- Parameters
from_mat (np.ndarray((dim, dim), np.complex128)) – An Hermitian matrix
basis (MatrixBasis) – An Hermitian orthonormal matrix basis
- Returns
- Return type
np.ndarray((dim * dim, 1), np.float)
- calc_mat_from_coefficient_basis(coeff, basis)[source]
return a matrix corresponding to the coefficient and matrix basis.
- Parameters
coeff (np.ndarray) – A coefficient vector. The shape of np.ndarray is
(dim * dim, 1).basis (MatrixBasis) – A square matrix basis with dimension dim.
- Returns
A square matrix The shape of np.ndarray is
(dim, dim).- Return type
np.ndarray
- calc_matrix_expansion_coefficient(from_mat, basis)[source]
return expansion coefficients of a matrix w.r.t. the matrix basis.
- Parameters
from_mat (np.ndarray((dim, dim), np.complex128)) – A square complex matrix
basis (MatrixBasis) – A orthonormal matrix basis
- Returns
- Return type
np.ndarray((dim * dim, 1), np.complex)
- convert_vec(from_vec, from_basis, to_basis)[source]
converts vector representation from
from_basistoto_basis.- Parameters
from_vec (np.ndarray) – vector representation before converts vector representation.
from_basis (MatrixBasis) – basis before converts vector representation.
to_basis (MatrixBasis) – basis after converts vector representation.
- Returns
vector representation after converts vector representation.
dtypeisfloat64.- Return type
np.ndarray
- get_comp_basis(dim=2, mode='row_major')[source]
Returns computational basis.
- Parameters
dim (int, optional) – dim of computational basis, by default 2.
mode (str, optional) – specify whether the order of basis is “row_major” or “column_major”, by default “row_major”.
- Returns
computational basis with specific dim.
- Return type
- Raises
ValueError –
modeis unsupported.
- get_gell_mann_basis()[source]
Returns Gell-Mann matrices basis.
- Returns
Gell-Mann matrices basis
- Return type
- get_generalized_gell_mann_basis(n_qubit=1, dim=2)[source]
Returns Generalized Gell-Mann matrices basis.
- Parameters
n_qubit (int, optional) – number of qubit for Generalized Gell-Mann matrices basis, by default 1.
dim (int, optional) – dim of Generalized Gell-Mann matrices basis, by default 2.
- Returns
Generalized Gell-Mann matrices basis. see https://mathworld.wolfram.com/GeneralizedGell-MannMatrix.html
- Return type
- get_hermitian_basis(dim=2)[source]
Returns Hermitian basis.
- Parameters
dim (int, optional) – dim of Hermitian basis, by default 2.
- Returns
Hermitian basis.
- Return type
- get_normalized_gell_mann_basis()[source]
Returns normalized Gell-Mann matrices basis.
- Returns
Normalized Gell-Mann matrices basis
- Return type
- get_normalized_generalized_gell_mann_basis(n_qubit=1, dim=2)[source]
Returns Normalized Generalized Gell-Mann matrices basis.
- Parameters
n_qubit (int, optional) – number of qubit for Normalized Generalized Gell-Mann matrices basis, by default 1.
dim (int, optional) – dim of Normalized Generalized Gell-Mann matrices basis, by default 2.
- Returns
Normalized Generalized Gell-Mann matrices basis. see https://mathworld.wolfram.com/GeneralizedGell-MannMatrix.html
- Return type
- get_normalized_hermitian_basis(dim=2)[source]
Returns normalized Hermitian basis.
- Parameters
dim (int, optional) – dim of normalized Hermitian basis, by default 2.
- Returns
normalized Hermitian basis.
- Return type
- get_normalized_pauli_basis(n_qubit=1)[source]
Returns normalized Pauli basis.
- Parameters
n_qubit (int, optional) – number of qubit for normalized Pauli basis, by default 1.
- Returns
n_qubitof Pauli basis \(\frac{1}{\sqrt{2}}[I, X, Y, Z]\)- Return type
- get_pauli_basis(n_qubit=1)[source]
Returns Pauli basis.
- Parameters
n_qubit (int, optional) – number of qubit for Pauli basis, by default 1.
- Returns
Pauli basis \([I, X, Y, Z]\)
- Return type
- to_vect(source)[source]
Convert MatrixBasis to VectorizedMatrixBasis
- Returns
VectorizedMatrixBasis converted from MatrixBasis.
- Return type
- Parameters
source (quara.objects.matrix_basis.MatrixBasis) –