qnet.algebra.matrix_algebra module

Matrices of Operators

Summary

Exceptions:

NonSquareMatrix

Classes:

Matrix Matrix with Operator (or scalar-) valued elements.

Functions:

Im The imaginary part of a number or operator.
ImAdjoint The imaginary part of an OperatorMatrix, i.e.
ImMatrix The imaginary part of a number or operator.
Re The real part of a number or operator.
ReAdjoint The real part of an OperatorMatrix, i.e.
ReMatrix The real part of a number or operator.
block_matrix Generate the operator matrix with quadrants
diagm Generalizes the diagonal matrix creation capabilities of numpy.diag to OperatorMatrix objects.
hstackm Generalizes numpy.hstack to OperatorMatrix objects.
identity_matrix Generate the N-dimensional identity matrix.
permutation_matrix Return an orthogonal permutation matrix
vstackm Generalizes numpy.vstack to OperatorMatrix objects.
zerosm Generalizes numpy.zeros to Matrix objects.

__all__: ImAdjoint, ImMatrix, Matrix, NonSquareMatrix, ReAdjoint, ReMatrix, block_matrix, diagm, hstackm, identity_matrix, permutation_matrix, vstackm, zerosm

Reference

exception qnet.algebra.matrix_algebra.NonSquareMatrix[source]

Bases: Exception

class qnet.algebra.matrix_algebra.Matrix(m)[source]

Bases: qnet.algebra.abstract_algebra.Expression

Matrix with Operator (or scalar-) valued elements.

matrix = None
shape

The shape of the matrix (nrows, ncols)

block_structure

For square matrices this gives the block (-diagonal) structure of the matrix as a tuple of integers that sum up to the full dimension.

Type:tuple
args
is_zero

Are all elements of the matrix zero?

transpose()[source]

The transpose matrix

conjugate()[source]

The element-wise conjugate matrix, i.e., if an element is an operator this means the adjoint operator, but no transposition of matrix elements takes place.

T

Transpose matrix

adjoint()[source]

Return the adjoint operator matrix, i.e. transpose and the Hermitian adjoint operators of all elements.

dag()

Return the adjoint operator matrix, i.e. transpose and the Hermitian adjoint operators of all elements.

trace()[source]
H

Return the adjoint operator matrix, i.e. transpose and the Hermitian adjoint operators of all elements.

element_wise(method)[source]

Apply a method to each matrix element and return the result in a new operator matrix of the same shape. :param method: A method taking a single argument. :type method: FunctionType :return: Operator matrix with results of method applied element-wise. :rtype: Matrix

series_expand(param, about, order)[source]

Expand the matrix expression as a truncated power series in a scalar parameter.

Parameters:
  • param (sympy.core.symbol.Symbol) – Expansion parameter.
  • about (Any one of Operator.scalar_types) – Point about which to expand.
  • order (int >= 0) – Maximum order of expansion.
Returns:

tuple of length (order+1), where the entries are the expansion coefficients.

Return type:

tuple of Operator

expand()[source]

Expand each matrix element distributively. :return: Expanded matrix. :rtype: Matrix

all_symbols()[source]
space

Combined Hilbert space of all matrix elements.

simplify_scalar()[source]

Simplify all scalar expressions appearing in the Matrix.

qnet.algebra.matrix_algebra.hstackm(matrices)[source]

Generalizes numpy.hstack to OperatorMatrix objects.

qnet.algebra.matrix_algebra.vstackm(matrices)[source]

Generalizes numpy.vstack to OperatorMatrix objects.

qnet.algebra.matrix_algebra.diagm(v, k=0)[source]

Generalizes the diagonal matrix creation capabilities of numpy.diag to OperatorMatrix objects.

qnet.algebra.matrix_algebra.block_matrix(A, B, C, D)[source]

Generate the operator matrix with quadrants

\[\begin{split}\begin{pmatrix} A B \\ C D \end{pmatrix}\end{split}\]
Parameters:
  • A (Matrix) – Matrix of shape (n, m)
  • B (Matrix) – Matrix of shape (n, k)
  • C (Matrix) – Matrix of shape (l, m)
  • D (Matrix) – Matrix of shape (l, k)
Returns:

The combined block matrix [[A, B], [C, D]].

Type:

OperatorMatrix

qnet.algebra.matrix_algebra.identity_matrix(N)[source]

Generate the N-dimensional identity matrix.

Parameters:N (int) – Dimension
Returns:Identity matrix in N dimensions
Return type:Matrix
qnet.algebra.matrix_algebra.zerosm(shape, *args, **kwargs)[source]

Generalizes numpy.zeros to Matrix objects.

qnet.algebra.matrix_algebra.permutation_matrix(permutation)[source]

Return an orthogonal permutation matrix \(M_\sigma\) for a permutation \(\sigma\) defined by the image tuple \((\sigma(1), \sigma(2),\dots \sigma(n))\), such that

\[M_\sigma \vec{e}_i = \vec{e}_{\sigma(i)}\]

where \(\vec{e}_k\) is the k-th standard basis vector. This definition ensures a composition law:

\[M_{\sigma \cdot \tau} = M_\sigma M_\tau.\]

The column form of \(M_\sigma\) is thus given by

\[M = (\vec{e}_{\sigma(1)}, \vec{e}_{\sigma(2)}, \dots \vec{e}_{\sigma(n)}).\]
Parameters:permutation (tuple) – A permutation image tuple (zero-based indices!)
qnet.algebra.matrix_algebra.Im(op)[source]

The imaginary part of a number or operator. Acting on OperatorMatrices, it produces the element-wise imaginary parts.

Parameters:op (Operator or Matrix or any of Operator.scalar_types) – Anything that has a conjugate method.
Returns:The imaginary part of the operand.
Return type:Same as type of op.
qnet.algebra.matrix_algebra.ImMatrix(op)

The imaginary part of a number or operator. Acting on OperatorMatrices, it produces the element-wise imaginary parts.

Parameters:op (Operator or Matrix or any of Operator.scalar_types) – Anything that has a conjugate method.
Returns:The imaginary part of the operand.
Return type:Same as type of op.
qnet.algebra.matrix_algebra.Re(op)[source]

The real part of a number or operator. Acting on OperatorMatrices, it produces the element-wise real parts.

Parameters:op (Operator or Matrix or any of Operator.scalar_types) – Anything that has a conjugate method.
Returns:The real part of the operand.
Return type:Same as type of op.
qnet.algebra.matrix_algebra.ReMatrix(op)

The real part of a number or operator. Acting on OperatorMatrices, it produces the element-wise real parts.

Parameters:op (Operator or Matrix or any of Operator.scalar_types) – Anything that has a conjugate method.
Returns:The real part of the operand.
Return type:Same as type of op.
qnet.algebra.matrix_algebra.ImAdjoint(opmatrix)[source]

The imaginary part of an OperatorMatrix, i.e. a Hermitian OperatorMatrix :param opmatrix: The operand. :type opmatrix: Matrix :return: The matrix imaginary part of the operand. :rtype: Matrix

qnet.algebra.matrix_algebra.ReAdjoint(opmatrix)[source]

The real part of an OperatorMatrix, i.e. a Hermitian OperatorMatrix :param opmatrix: The operand. :type opmatrix: Matrix :return: The matrix real part of the operand. :rtype: Matrix