hqs_quantum_solver.util#
Miscellaneous utility functions.
Functions
| 
 | Computes the commutator of two matrices. | 
| Splits a 2d array into diagonal and off-diagonal elements. | |
| 
 | Creates a cannonical unit vector. | 
| 
 | Given a canonical unit vector, returns the index of the one in the vector. | 
- commutator(A: ndarray, B: ndarray) ndarray#
- Computes the commutator of two matrices. 
- split_diagonal(a: ndarray) tuple[ndarray, ndarray]#
- Splits a 2d array into diagonal and off-diagonal elements. - Parameters:
- a (ndarray) – The input array. Must be a 2d array. 
- Returns:
- Returns (diag, offdiag), the diagonal and off-diagonal
- elements, respectively. 
 
- Returns 
- Return type:
- tuple[ndarray,ndarray] 
- Raises:
- ValueError – When the array is of invalid shape. 
 
- unit_vector(dim: int, i: int, dtype: DTypeLike = None) np.ndarray#
- Creates a cannonical unit vector. - The i-th cannonical unit vector \(\mathbf{e}_i\) is defined by \[\begin{split}\big(\mathbf{e}_i\big)_j = \begin{cases} 1 & \text{if $i = j$,} \\ 0 & \text{otherwise.} \end{cases}\end{split}\]- Parameters:
- dim (int) – The length of the vector. 
- i (int) – The position of the non-zero element. 
- dtype (DTypeLike) – The dtype of the vector to be constructed. 
 
 
- unit_vector_index(v: ArrayLike, *, decimal: int = 7) int#
- Given a canonical unit vector, returns the index of the one in the vector. - Parameters:
- v (ArrayLike) – The unit vector. 
- decimal (int) – The number of decimal places to which to compare the given vector. 
 
- Returns:
- The index. 
- Return type:
- int 
 
