qnet.algebra.core.matrix_algebra module¶
Matrices of Operators
Summary¶
Classes:
Matrix |
Matrix of Expressions |
Functions:
block_matrix |
Generate the operator matrix with quadrants |
diagm |
Generalizes the diagonal matrix creation capabilities of numpy.diag to Matrix objects. |
hstackm |
Generalizes numpy.hstack to Matrix objects. |
identity_matrix |
Generate the N-dimensional identity matrix. |
permutation_matrix |
Return orthogonal permutation matrix for permutation tuple |
vstackm |
Generalizes numpy.vstack to Matrix objects. |
zerosm |
Generalizes numpy.zeros to Matrix objects. |
__all__
: Matrix
, block_matrix
, diagm
, hstackm
, identity_matrix
, vstackm
, zerosm
Reference¶
-
class
qnet.algebra.core.matrix_algebra.
Matrix
(m)[source]¶ Bases:
qnet.algebra.core.abstract_algebra.Expression
Matrix of Expressions
Matrices of
Operator
expressions are required for the SLH formalism.-
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.
Return type: tuple
-
args
¶ The tuple of positional arguments for the instantiation of the Expression
-
is_zero
¶ Are all elements of the matrix zero?
-
conjugate
()[source]¶ The element-wise conjugate matrix
This is defined only if all the entries in the matrix have a defined conjugate (i.e., they have a conjugate method). This is not the case for a matrix of operators. In such a case, only an
elementwise()
adjoint()
would be applicable, but this is mathematically different from a complex conjugate.Raises: NoConjugateMatrix
– if any entries have no conjugate method
-
real
¶ Element-wise real part
Raises: NoConjugateMatrix
– if entries have no conjugate method and no other way to determine the real partNote
A mathematically equivalent way to obtain a real matrix from a complex matrix
M
is:(M.conjugate() + M) / 2
However, the result may not be identical to
M.real
, as the latter tries to convert elements of the matrix to real values directly, if possible, and only uses the conjugate as a fall-back
-
imag
¶ Element-wise imaginary part
Raises: NoConjugateMatrix
– if entries have no conjugate method and no other way to determine the imaginary partNote
A mathematically equivalent way to obtain an imaginary matrix from a complex matrix
M
is:(M.conjugate() - M) / (I * 2)
with same same caveats as
real
.
-
T
¶ Alias for
transpose()
-
adjoint
()[source]¶ Adjoint of the matrix
This is the transpose and the Hermitian adjoint of all elements.
-
dag
()¶ Adjoint of the matrix
This is the transpose and the Hermitian adjoint of all elements.
-
element_wise
(func, *args, **kwargs)[source]¶ Apply a function to each matrix element and return the result in a new operator matrix of the same shape.
Parameters: - func (FunctionType) – A function to be applied to each element. It must take the element as its first argument.
- args – Additional positional arguments to be passed to func
- kwargs – Additional keyword arguments to be passed to func
Returns: Matrix with results of func, applied element-wise.
Return type:
-
series_expand
(param, about, order)[source]¶ Expand the matrix expression as a truncated power series in a scalar parameter.
Parameters: Returns: tuple of length (order+1), where the entries are the expansion coefficients.
-
expand
()[source]¶ Expand each matrix element distributively.
Returns: Expanded matrix. Return type: Matrix
-
free_symbols
¶ Set of free SymPy symbols contained within the expression.
-
space
¶ Combined Hilbert space of all matrix elements.
-
-
qnet.algebra.core.matrix_algebra.
hstackm
(matrices)[source]¶ Generalizes numpy.hstack to
Matrix
objects.
-
qnet.algebra.core.matrix_algebra.
vstackm
(matrices)[source]¶ Generalizes numpy.vstack to
Matrix
objects.
-
qnet.algebra.core.matrix_algebra.
diagm
(v, k=0)[source]¶ Generalizes the diagonal matrix creation capabilities of numpy.diag to
Matrix
objects.
-
qnet.algebra.core.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: Returns: The combined block matrix
[[A, B], [C, D]]
.Return type:
-
qnet.algebra.core.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.core.matrix_algebra.
zerosm
(shape, *args, **kwargs)[source]¶ Generalizes
numpy.zeros
toMatrix
objects.
-
qnet.algebra.core.matrix_algebra.
permutation_matrix
(permutation)[source]¶ Return orthogonal permutation matrix for permutation tuple
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!)