pygsti.tools.matrixtools

pygsti.tools.matrixtools#

Matrix related utility functions

Functions

approximate_matrix_log(m, target_logm[, ...])

Construct an approximate logarithm of superoperator matrix m that is real and near the target_logm.

assert_hermitian(mat, tol)

assert_projector(mx[, tol])

Raise a ValueError if mx is not an orthogonal projector, per is_projector().

column_basis_vector(i, dim)

Returns the ith standard basis vector in dimension dim.

column_norms(m[, ord])

Compute the norms of the columns of a matrix.

columns_are_orthogonal(m[, tol])

Checks whether a matrix contains orthogonal columns.

columns_are_orthonormal(m[, tol])

Checks whether a matrix contains orthogonal columns.

complex_compare(a, b)

Comparison function for complex numbers that compares real part, then imaginary part.

compute_kite(eigenvalues)

Computes the "kite" corresponding to a list of eigenvalues.

csr_sum(data, coeffs, csr_mxs, csr_sum_indices)

Accelerated summation of several CSR-format sparse matrices.

csr_sum_flat(data, coeffs, ...)

Computation of the summation of several CSR-format sparse matrices.

csr_sum_flat_indices(csr_matrices)

Precomputes quantities allowing fast computation of linear combinations of CSR sparse matrices.

csr_sum_indices(csr_matrices)

Precomputes the indices needed to sum a set of CSR sparse matrices.

eigendecomposition(m, *[, assume_hermitian])

eigenvalues(m, *[, assume_hermitian, ...])

expm_multiply_fast(prep_a, v[, tol])

Multiplies v by an exponentiated matrix.

expm_multiply_prep(a[, tol])

Computes "prepared" meta-info about matrix a, to be used in expm_multiply_fast.

expop_multiply_prep(op[, a_1_norm, tol])

Returns "prepared" meta-info about operation op, which is assumed to be traceless (so no shift is needed).

find_zero_communtant_connection(u, u_inv, ...)

Find a matrix R such that u_inv R u0 is diagonal AND log(R) has no projection onto the commutant of G0.

gram_matrix(m[, adjoint])

If adjoint=False, then return m.T.conj() @ m, computed in a more efficient way.

independent_columns(m[, ...])

Computes the indices of the linearly-independent columns in a matrix.

induced_projector(mx[, tol, require_real])

Return the orthogonal projector onto range(mx), for mx proportional to a projector.

int64_parity(x)

Compute the partity of x.

intersection_space(space1, space2[, tol, ...])

TODO: docstring

is_hermitian(mx[, tol])

Test whether mx is a hermitian matrix.

is_pos_def(mx[, tol, attempt_cholesky])

Test whether mx is a positive-definite matrix.

is_projector(mx[, tol])

Test whether mx is an orthogonal projector, i.e. Hermitian and idempotent.

is_valid_density_mx(mx[, tol])

Test whether mx is a valid density matrix (hermitian, positive-definite, and unit trace).

jamiolkowski_angle(hamiltonian_mx)

TODO: docstring

matrix_sign(m)

Compute the matrix s = sign(m).

minweight_match(a, b[, metricfn, ...])

Matches the elements of two vectors, a and b by minimizing the weight between them.

minweight_match_realmxeigs(a, b[, metricfn, ...])

Matches the elements of a and b, whose elements are assumed to either real or one-half of a conjugate pair.

mx_to_string(m[, width, prec, withbrackets])

Generate a "pretty-format" string for a matrix.

mx_to_string_complex(m[, real_width, ...])

Generate a "pretty-format" string for a complex-valued matrix.

ndarray_base(a[, verbosity])

Get the base memory object for numpy array a.

near_identity_matrix_log(m[, tol])

Construct the logarithm of superoperator matrix m that is near the identity.

nice_nullspace(m[, tol, orthogonalize])

Computes the nullspace of a matrix, and tries to return a "nice" basis for it.

norm1(m)

Returns the Schatten 1-norm of a matrix

norm1to1(operator[, num_samples, mx_basis])

The Hermitian 1-to-1 norm of a superoperator represented in the standard basis.

normalize_columns(m[, return_norms, ord])

Normalizes the columns of a matrix.

nullspace(m[, tol])

Compute the nullspace of a matrix.

nullspace_qr(m[, tol])

Compute the nullspace of a matrix using the QR decomposition.

pinv_of_matrix_with_orthogonal_columns(m)

Return the matrix "pinv_m" so m @ pinvm and pinv_m @ m are orthogonal projectors onto subspaces of dimension rank(m).

pivot_indices_after_deflation(m_fixed, m)

m_fixed and m have the same number of rows.

prime_factors(n)

GCD algorithm to produce prime factors of n

print_mx(mx[, width, prec, withbrackets])

Print matrix in pretty format.

project_onto_antikite(mx, kite)

Project mx onto the complement of kite, so mx is zero everywhere on the kite.

project_onto_kite(mx, kite)

Project mx onto kite, so mx is zero everywhere except on the kite.

random_hermitian(dim)

Generates a random Hermitian matrix

real_matrix_log(m[, action_if_imaginary, tol])

Construct a real logarithm of real matrix m.

safe_norm(a[, part])

Get the frobenius norm of a matrix or vector, a, when it is either a dense array or a sparse matrix.

safe_onenorm(a)

Computes the 1-norm of the dense or sparse matrix a.

scale_columns(m, scale_values)

Scale each column of a matrix by a given value.

sign_fix_qr(q, r[, tol])

Change the signs of the columns of Q and rows of R to follow a convention.

sorted_eig(mx)

Similar to numpy.eig, but returns sorted output.

sparse_equal(a, b[, atol])

Checks whether two Scipy sparse matrices are (almost) equal.

sparse_onenorm(a)

Computes the 1-norm of the scipy sparse matrix a.

to_operatorlike(obj)

to_unitary(scaled_unitary)

Compute the scaling factor required to turn a scalar multiple of a unitary matrix to a unitary matrix.

union_space(space1, space2[, tol])

TODO: docstring

unitary_superoperator_matrix_log(m, mx_basis)

Construct the logarithm of superoperator matrix m.

vec(matrix_in)

Stacks the columns of a matrix to return a vector

zvals_int64_to_dense(zvals_int, nqubits[, ...])

Fills a dense array with the super-ket representation of a computational basis state.

zvals_to_dense(self, zvals[, superket])

Construct the dense operator or superoperator representation of a computational basis state.

Classes

IdentityOperator()

A representation of the identity operator on any and all vector spaces.

OperatorLike(*args, **kwargs)