Matrix
This class is used to represent both numeric and symbolic complex matrices. Every matrix in perceval is an instance of this class.
>>> import perceval as pcvl
>>> M = pcvl.Matrix("1 2 3\n4 5 6\n7 8 9")
>>> pcvl.pdisplay(M)
⎡1 2 3⎤
⎢4 5 6⎥
⎣7 8 9⎦
>>> M.is_unitary()
False
It also comes with utility methods to create unitary matrices
>>> random_unitary = pcvl.Matrix.random_unitary(6) # 6*6
>>> deterministic_unitary = pcvl.Matrix.parametrized_unitary(list(range(8))) # 2*2 (requires 2*m**2 parameters)
>>> from_array_unitary = pcvl.Matrix.get_unitary_extension(numpy_2d_array) # Size (row+col) * (row+col)
- class perceval.utils.matrix.Matrix(source, use_symbolic=None)
This parent class is the gateway
MatrixN
orMatrixS
- based onuse_symbolic
, and checking if input contains any parameter, it will create an instance of one or the other class.MatrixS
is a subclass ofsympy.Matrix
with slight API augmentations for compatibility with numpyMatrixN
is a subclass ofnumpy.ndarray
Both classes have additional utility functions - while Matrix class is also presenting additional static utility functions
- static __new__(cls, source, use_symbolic=None)
Constructor for Matrix class
- Parameters:
source – can be a string, a file, a list, a ndarray, another Matrix, or a integer
use_symbolic – True to force use of symbolic, False to force use of numeric, None to select based on source
- static eye(n, use_symbolic=False)
Returns an identity matrix
- Parameters:
n (
int
) – size of the matrixuse_symbolic (
bool
) – defines if matrix will be symbolic or numeric
- Return type:
- Returns:
an identity matrix
- static get_unitary_extension(M)
Embed the input matrix M into a unitary matrix U
- U = | M/σ * |
- * * |
\[\begin{split}U = \begin{matrix} M/σ & * \\ * & * \end{matrix}\end{split}\]- Parameters:
M (
ndarray
) – np.ndarray describing a row x col complex matrix- Return type:
MatrixN
- Returns:
numeric matrix describing a (row + col) x (row + col) complex unitary matrix
- abstract is_symbolic()
check if matrix is symbolic or numeric
- Return type:
bool
- abstract is_unitary()
check if matrix is unitary
- Return type:
bool
- static parametrized_unitary(n, parameters)
static method generating a parametrized unitary matrix
- Parameters:
n (int) – size of the Matrix
parameters (np.ndarray | list) – \(2n^2\) parameters to use as generator
- Return type:
MatrixN
- Returns:
a numeric Matrix
- static random_unitary(n)
static method generating a random unitary matrix
- Parameters:
n (
int
) – size of the Matrix- Return type:
MatrixN
- Returns:
a numeric Matrix
- simp()
Simplify the matrix - only implemented for symbolic matrix