Linopt
Linear optics circuit calculator
|
Various matrix-related functions. More...
Functions | |
Complex | linopt::permanent (const Matrix &M) |
Calculates permanent of a square matrix. More... | |
void | linopt::hurwitzParametrization (Matrix &M, const Point &x) |
Fills a unitary matrix according to the Hurwitz parametrization. More... | |
Matrix | linopt::hurwitzParametrization (const Point &x) |
Returns a matrix parametrized according to the Hurwitz parametrization. More... | |
void | linopt::expHermiteParametrization (Matrix &M, const Point &x) |
Fills a unitary matrix according to the exponential-Hermitian parametrization. More... | |
Matrix | linopt::expHermiteParametrization (const Point &x) |
Returns a matrix parametrized according to the exponential-Hermitian parametrization. More... | |
Real | linopt::matrixFidelity (const Matrix &A, const Matrix &B) |
Calculates normalized fidelity between two matrices. More... | |
bool | linopt::isColumnUnitary (const Matrix &M, Real eps=defaultEpsilon) |
Tests whether a matrix is column-unitary. More... | |
bool | linopt::isRowUnitary (const Matrix &M, Real eps=defaultEpsilon) |
Tests whether a matrix is row-unitary. More... | |
bool | linopt::isUnitary (const Matrix &M, Real eps=defaultEpsilon) |
Tests whether a matrix is unitary. More... | |
Variables | |
constexpr Real | linopt::defaultEpsilon = 1e-15 |
Default precision for numeric comparison operations. | |
Various matrix-related functions.
void linopt::expHermiteParametrization | ( | Matrix & | M, |
const Point & | x | ||
) |
Fills a unitary matrix according to the exponential-Hermitian parametrization.
[out] | M | – an \( N \times N \) matrix to store the result. If it has improper size it will be resized. |
[in] | x | – an array of \( N^2 \) parameters. |
The exponential-Hermitian parametrization of a unitary matrix is based on the relation
\[ M = \exp(i H(x)). \]
If \( H \) is Hermitian then \( M \) is unitary. Since \( H \) is Hermitian it can be parametrized by its matrix elements. First elements of x
contain the real-valued diagonal of \( H \), then the upper triangular part is specified. For example, \( 4 \times 4 \) Hermitian matrix is parametrized in the following way
\[ H(x) = \begin{pmatrix} x[0] & x[4]+ix[5] & x[6]+ix[7] & x[8]+ix[9] \\ x[4]-ix[5] & x[1] & x[10]+ix[11] & x[12]+ix[13] \\ x[6]-ix[7] & x[10]-ix[11] & x[2] & x[14]+ix[15] \\ x[8]-ix[9] & x[12]-ix[13] & x[14]-ix[15] & x[3] \end{pmatrix}. \]
If | size of x is not a square of some integer number \( N \), then WrongSize is thrown. |
Matrix linopt::expHermiteParametrization | ( | const Point & | x | ) |
Returns a matrix parametrized according to the exponential-Hermitian parametrization.
[in] | x | – an array of parameters. |
x
.This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
void linopt::hurwitzParametrization | ( | Matrix & | M, |
const Point & | x | ||
) |
Fills a unitary matrix according to the Hurwitz parametrization.
[out] | M | – an \( N \times N \) matrix to store the result. If it has an improper size it will be resized. |
[in] | x | – an array of \( N^2 \) parameters. |
Hurwitz parametrization is capable to parametrize any unitary matrix of size \( N \times N \) with \( N^2 \) parameters x
. The essential feature of this parametrization is that a uniform ensemble of random points inside a unit hypercube \( 0 \le x_i < 1, i = 1, \dots, N^2 \) is mapped onto a Haar-uniform ensemble of random unitary matrices. Therefore this parametrization can be used, for example, to sample random matrices from a circular unitary ensemble (CUE). Or it can be used when optimizing over the space of all unitary matrices. In some sense it maps the space of unitary matrices onto a unit hypercube with least possible "distorsion".
Parameters x
may lie outside the unit hypercube. If so, they are effectively moved back to the hypercube by means of a peridic function. The parametrization is continuous on boundaries, but not smooth.
If | size of x is not a square of some integer number \( N \), then WrongSize is thrown. |
Matrix linopt::hurwitzParametrization | ( | const Point & | x | ) |
Returns a matrix parametrized according to the Hurwitz parametrization.
[in] | x | – an array of parameters. |
x
.This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
bool linopt::isColumnUnitary | ( | const Matrix & | M, |
Real | eps = defaultEpsilon |
||
) |
Tests whether a matrix is column-unitary.
[in] | M | – matrix to test. |
[in] | eps | – accuracy within test is performed. |
true
if the matrix M
is a column-unitary one with the given accuracy, false
otherwise.A matrix \( M \) is called column unitary if \( M^\dagger M = 1 \).
bool linopt::isRowUnitary | ( | const Matrix & | M, |
Real | eps = defaultEpsilon |
||
) |
Tests whether a matrix is row-unitary.
[in] | M | – matrix to test. |
[in] | eps | – accuracy within test is performed. |
true
if the matrix M
is a row-unitary one with the given accuracy, false
otherwise.A matrix \( M \) is called row unitary if \( M M^\dagger = 1 \).
bool linopt::isUnitary | ( | const Matrix & | M, |
Real | eps = defaultEpsilon |
||
) |
Tests whether a matrix is unitary.
[in] | M | – matrix to test. |
[in] | eps | – accuracy within test is performed. |
true
if the matrix M
is a unitary one with the given accuracy, false
otherwise.A square matrix \( M \) is called unitary if it is both column and row unitary.
Real linopt::matrixFidelity | ( | const Matrix & | A, |
const Matrix & | B | ||
) |
Calculates normalized fidelity between two matrices.
[in] | A | – first matrix. |
[in] | B | – second matrix. |
Normalized fidelity \( F(A, B) \) between two matrices \( A \) and \( B \) is defined as follows:
\[ \newcommand{\Tr}{\mathrm{Tr}} F(A, B) = \frac{|\Tr(A^\dagger B)|^2}{\Tr(A^\dagger A) \Tr(B^\dagger B)}. \]
If | matrix sizes do not match WrongSize is thrown. |
Complex linopt::permanent | ( | const Matrix & | M | ) |
Calculates permanent of a square matrix.
[in] | M | – matrix to calculate its permanent. |
Calculates permanent of a square \( N \times N \) matrix M
. Internally the function uses Glynn formula with Gray code summation technique. Complexity is \( O(N \times 2^N) \).