qc2.algorithms.utils.helper_funcs

Module containing general helper functions.

Functions

vector_to_skew_symmetric(→ numpy.ndarray)

Map a vector to an anti-symmetric matrix with np.tril_indices.

skew_symmetric_to_vector(→ numpy.ndarray)

Converts a skew-symmetric matrix to a 1D vector.

reshape_2(→ numpy.ndarray)

Reshapes a flattened 2D array into a 2D array with specified dimensions.

get_non_redundant_indices(→ numpy.ndarray)

Calculates the non-redundant indices for orbital parameters.

Module Contents

qc2.algorithms.utils.helper_funcs.vector_to_skew_symmetric(vector: List[float] | numpy.ndarray) numpy.ndarray[source]

Map a vector to an anti-symmetric matrix with np.tril_indices.

Parameters:

vector (Union[List[float], np.ndarray]) – 1d tensor

Returns:

A skew-symmetric matrix corresponding to the input vector.

Return type:

np.ndarray

Example

The resulting matrix for np.array([1,2,3,4,5,6]) is:

\[\begin{split}\begin{pmatrix} 0 & -1 & -2 & -4\\ 1 & 0 & -3 & -5\\ 2 & 3 & 0 & -6\\ 4 & 5 & 6 & 0 \end{pmatrix}\end{split}\]
qc2.algorithms.utils.helper_funcs.skew_symmetric_to_vector(kappa_matrix: numpy.ndarray) numpy.ndarray[source]

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.

Parameters:

kappa_matrix (np.ndarray) – A skew-symmetric matrix.

Returns:

A 1-dimensional vector containing the elements of the lower triangular part of the input matrix.

Return type:

np.ndarray

qc2.algorithms.utils.helper_funcs.reshape_2(arr: List[float] | numpy.ndarray, dim: int, dim_2: int | None = None) numpy.ndarray[source]

Reshapes a flattened 2D array into a 2D array with specified dimensions.

Parameters:
  • arr (Union[List[float], np.ndarray]) – A flattened array or list to be reshaped.

  • dim (int) – The first dimension of the reshaped array.

  • dim_2 (int, optional) – The second dimension of the reshaped array. If None, it is set equal to dim.

Returns:

A 2-dimensional array reshaped according to the specified dimensions.

Return type:

np.ndarray

qc2.algorithms.utils.helper_funcs.get_non_redundant_indices(occ_idx: numpy.ndarray, act_idx: numpy.ndarray, virt_idx: numpy.ndarray, freeze_active: bool) numpy.ndarray[source]

Calculates the non-redundant indices for orbital parameters.

Parameters:
  • occ_idx (np.ndarray) – Indices of occupied orbitals.

  • act_idx (np.ndarray) – Indices of active orbitals.

  • virt_idx (np.ndarray) – Indices of virtual orbitals.

  • freeze_active (bool) – If True, active orbitals are frozen.

Returns:

Indices of non-redundant orbital rotation parameters.

Return type:

np.ndarray