qc2.algorithms.utils.helper_funcs ================================= .. py:module:: qc2.algorithms.utils.helper_funcs .. autoapi-nested-parse:: Module containing general helper functions. Functions --------- .. autoapisummary:: qc2.algorithms.utils.helper_funcs.vector_to_skew_symmetric qc2.algorithms.utils.helper_funcs.skew_symmetric_to_vector qc2.algorithms.utils.helper_funcs.reshape_2 qc2.algorithms.utils.helper_funcs.get_non_redundant_indices Module Contents --------------- .. py:function:: vector_to_skew_symmetric(vector: Union[List[float], numpy.ndarray]) -> numpy.ndarray Map a vector to an anti-symmetric matrix with np.tril_indices. :param vector: 1d tensor :type vector: Union[List[float], np.ndarray] :returns: A skew-symmetric matrix corresponding to the input vector. :rtype: np.ndarray **Example** The resulting matrix for `np.array([1,2,3,4,5,6])` is: .. math:: \begin{pmatrix} 0 & -1 & -2 & -4\\ 1 & 0 & -3 & -5\\ 2 & 3 & 0 & -6\\ 4 & 5 & 6 & 0 \end{pmatrix} .. py:function:: skew_symmetric_to_vector(kappa_matrix: numpy.ndarray) -> numpy.ndarray Converts a skew-symmetric matrix to a 1D vector. This function extracts the lower triangular part of a skew-symmetric matrix and flattens it to a 1D vector. :param kappa_matrix: A skew-symmetric matrix. :type kappa_matrix: np.ndarray :returns: A 1-dimensional vector containing the elements of the lower triangular part of the input matrix. :rtype: np.ndarray .. py:function:: reshape_2(arr: Union[List[float], numpy.ndarray], dim: int, dim_2: Optional[int] = None) -> numpy.ndarray Reshapes a flattened 2D array into a 2D array with specified dimensions. :param arr: A flattened array or list to be reshaped. :type arr: Union[List[float], np.ndarray] :param dim: The first dimension of the reshaped array. :type dim: int :param dim_2: The second dimension of the reshaped array. If None, it is set equal to dim. :type dim_2: int, optional :returns: A 2-dimensional array reshaped according to the specified dimensions. :rtype: np.ndarray .. py:function:: get_non_redundant_indices(occ_idx: numpy.ndarray, act_idx: numpy.ndarray, virt_idx: numpy.ndarray, freeze_active: bool) -> numpy.ndarray Calculates the non-redundant indices for orbital parameters. :param occ_idx: Indices of occupied orbitals. :type occ_idx: np.ndarray :param act_idx: Indices of active orbitals. :type act_idx: np.ndarray :param virt_idx: Indices of virtual orbitals. :type virt_idx: np.ndarray :param freeze_active: If True, active orbitals are frozen. :type freeze_active: bool :returns: Indices of non-redundant orbital rotation parameters. :rtype: np.ndarray