entanglish.utilities module¶
-
entanglish.utilities.
clip
(x, limits)[source]¶ This method clips x between limits[0] and limits[1]
Parameters: - x (int|float) –
- limits (list[int|float]) –
Returns: Return type: int|float
-
entanglish.utilities.
clipped_log_of_vec
(vec, eps=1e-10, clip_to_zero=False)[source]¶ This method takes as input a int|float or a 1D array of floats. It returns the log element-wise of that array, except when an element of the array is < eps, where eps is a positive but << 1 float. In that exceptional case, the method “clips the log”, meaning that it returns log(eps) if clip_to_zero=False and 0 if clip_to_zero=True
Parameters: - vec (int|float|np.ndarray) –
- eps (float) –
- clip_to_zero (bool) –
Returns: Return type: np.ndarray
-
entanglish.utilities.
comb
(n, k)[source]¶ This method returns the number of combinations of k picks (with return) out of n possible choices, “n choose k” = n!/[(n-k)! k!]
Parameters: - n (int) –
- k (int) –
Returns: Return type: int
-
entanglish.utilities.
fun_of_herm_arr
(fun_of_evas, herm_arr, **fun_kwargs)[source]¶ This method does the same as the method ut.fun_of_herm_arr_from_eigen(), except that it calculates evas and eigen_cols from the matrix herm_arr which it has as input.
Parameters: - fun_of_evas (function) – np function acting on 1d array
- herm_arr (np.ndarray) – Hermitian array
- fun_kwargs (dict) – dict of keyword args that fun depends on
Returns: Return type: np.ndarray
-
entanglish.utilities.
fun_of_herm_arr_from_eigen_sys
(fun_of_evas, evas, evec_cols, **fun_kwargs)[source]¶ eigen_sys= eigensystem= (eigenvalues, eigenvectors as columns)= (evas, evec_cols)
This method returns a function fun of a Hermitian matrix mat. This is calculated as fun(mat) = U.D.U^dag, where U=evec_cols is a unitary matrix with the eigenvectors of mat as columns, U^dag is the Hermitian conjugate of U, D= diag(fun(evas)) is a diagonal matrix whose diagonal is obtained by applying element-wise the function fun=fun_of_evas to the 1D array of eigenvalues evas.
Parameters: - fun_of_evas (function) –
- evas (np.ndarray) –
- evec_cols (np.ndarray) –
- fun_kwargs (dict) – dict of keyword arguments that fun depends on
Returns: Return type: np.ndarray
-
entanglish.utilities.
get_entropy_from_probs
(probs)[source]¶ This method returns the classical entropy of the probability distribution probs. It checks that probs is a prob distribution.
Parameters: probs (np.ndarray) – Returns: Return type: float
-
entanglish.utilities.
get_equiv_classes
(li)[source]¶ This method is given as input a list li of floats, some of which may be equal within epsilon = 1e-6. The method then returns a list of equivalence classes, where each equivalence class is a list of the int positions in li of those floats that are equal to each other within epsilon.
Parameters: li (list[float]|np.ndarray) – Returns: Return type: list[list[int]]
-
entanglish.utilities.
herm_arr_from_eigen_sys
(evas, evec_cols)[source]¶ Same as fun_of_herm_arr_from_eigen_sys() but for special case when fun_of_evas() is identity.
Parameters: - evas (np.ndarray) –
- evec_cols (np.ndarray) –
Returns: Return type: np.ndarray
-
entanglish.utilities.
is_hermitian_arr
(arr)[source]¶ Returns True iff arr is a Hermitian matrix.
Returns: Return type: bool
-
entanglish.utilities.
is_nonnegative_arr
(arr)[source]¶ This method checks that all elements of arr are > -1e-6.
Parameters: arr (np.ndarray) – Returns: Return type: bool
-
entanglish.utilities.
is_positive_arr
(arr)[source]¶ This method checks that all elements of arr are > 0.
Parameters: arr (np.ndarray) – Returns: Return type: bool
-
entanglish.utilities.
is_prob_dist
(prob_dist)[source]¶ This method checks that the elements of arr define a probability distribution.
Parameters: prob_dist (np.ndarray) – Returns: Return type: bool
-
entanglish.utilities.
is_unitary_arr
(umat)[source]¶ Returns True iff umat is a unitary matrix
Parameters: umat (np.ndarray) – Returns: Return type: bool
-
entanglish.utilities.
kron_prod
(mat_list)[source]¶ This method returns the Kronecker product of the list of matrices which is has as input.
Parameters: mat_list (list[np.ndarray]) – Returns: Return type: np.ndarray
-
entanglish.utilities.
mat_elem
(v1, a, v2)[source]¶ This method returns the matrix element
<v1|a|v2>
, where v1 and v2 are column vectors and ‘a’ a matrix.Parameters: - v1 (np.ndarray) –
- a (np.ndarray) –
- v2 (np.ndarray) –
Returns: Return type: complex
-
entanglish.utilities.
positive_part
(x)[source]¶ This method returns max(0, x)
Parameters: x (int|float) – Returns: Return type: int|float
-
entanglish.utilities.
positive_part_of_vec
(vec)[source]¶ This method takes as input a int|float or a 1D array of floats. It returns the array, with negative items replaced by zero
Parameters: vec (int|float|np.ndarray) – Returns: Return type: np.ndarray
-
entanglish.utilities.
prob_hypergeometric
(x, xx, n, nn)[source]¶ This method returns
P(x | xx, n, nn) = comb(xx, x)*comb(nn-xx, n-x)/comb(nn, n)
where:
0 <= x <= xx 0 <= n-x <= nn-xx 0 <= n <= nn
This P(x | ) defines the hypergeometric distribution
References
Parameters: - x (int) –
- xx (int) –
- n (int) –
- nn (int) –
Returns: Return type: float
-
entanglish.utilities.
random_st_vec
(dim)[source]¶ This method returns a random complex 1D numpy array, normalized, of size dim.
Parameters: dim (int) – Returns: Return type: np.ndarray
-
entanglish.utilities.
random_unitary
(dim)[source]¶ This method returns a random unitary matrix of size dim x dim
Parameters: dim (int) – Returns: Return type: np.ndarray
-
entanglish.utilities.
scalar_prod
(scalars_list)[source]¶ This method returns the product of the list of scalars which it has as input.
Parameters: scalars_list (list[int|float|complex] | tuple[int|float|complex]) – Returns: Return type: complex|float|int
-
entanglish.utilities.
switch_arr_basis
(arr, umat, reverse=False)[source]¶ This method takes as input a square array ‘arr’ and returns a new array which is a similarity transformation U^dag(arr)U of ‘arr’ that changes the basis of arr from inbasis to sbasis (or the reverse, U(arr)U^dag, from sbasis to inbasis if the input bool parameter ‘reverse’ is set to True.) U = umat , U^dag = Hermitian conjugate of U
Parameters: - arr (np.ndarray) –
- umat (np.ndarray) –
- reverse (bool) –
Returns: Return type: np.ndarray