utils
- qmetro.utils.enhance_hermiticity(m)[source]
Enhances hermiticity of a matrix by replacing it with its hermitian part: (m + hc(m)) / 2.
- Parameters:
m (np.ndarray) – Matrix to be enhanced.
- Returns:
Hermitian matrix and the maximum difference from the original.
- Return type:
tuple[np.ndarray, float]
- qmetro.utils.flatten(seq, depth=1)[source]
- Parameters:
seq (Iterable[Iterable[T | Iterable[T | Iterable[S]]]])
depth (int)
- Return type:
list[T | Iterable[T | Iterable[S]]]
- qmetro.utils.get_random_den_mat(d)[source]
Returns random positive matrix with trace one.
- Parameters:
d (int) – Matrix dimension.
- Returns:
Random density matrix.
- Return type:
np.ndarray
- qmetro.utils.get_random_positive_matrix(d, trace=1.0)[source]
Returns random positive matrix with a given trace.
- Parameters:
d (int) – Matrix dimension.
trace (float) – Trace.
- Returns:
Random density matrix.
- Return type:
np.ndarray
- qmetro.utils.matrix_exp_derivative(x, y, t0=0.0)[source]
Compute derivative of the function:
t -> exp(x + t * y),
where x and y are matrices. Derivative is computed at point t0.
- Parameters:
x (NDArray[np.complex128]) – matrix
y (NDArray[np.complex128]) – matrix
t0 (float) – Point at which derivative will be computed.
0.0. (Defaults to)
- Returns:
Derivative.
- Return type:
np.ndarray
- qmetro.utils.schmidt(state, dims, eps=1e-05)[source]
Gives Schmidt decomposition of the state.
It returns tuple of lists (a, s) such that a[i] is the amplitude of the i-th superpostion term which is a tensor product of states s[i][0], …, s[i][len(dims) - 1]. In other words, first index of s corresponds to the term in the superposition, while the second index corresponds to the subsystem.
The states are normalized and orthogonal in the sense np.inner(s[i][k].conjugate(), s[j][k]) = int(i == j).
- Parameters:
state (np.ndarray) – One-dimensional (len(state.shape) == 1) array representing the state.
dims (list[int]) – Dimensions of the spaces in the decomposition.
eps (float) – Cut-off for small Schmidt coefficients (singular values).
- Returns:
a (list[float]) – Amplitudes.
s (list[list[np.ndarray]]) – States.
- Return type:
tuple[list, list[list[ndarray]]]