Change the basis of a general interaction tensor.

Used in the notebooks

Used in the tutorials

M'^{p_1p_2...p_n} = R^{p1}{a_1} R^{p2}{a_2} ... R^{pn}{a_n} M^{a_1a_2...a_n} R^{pn}{a_n}^T ... R^{p2}{a2}^T R{p1}{a_1}^T

where R is the rotation matrix, M is the general tensor, M' is the transformed general tensor, and a_k and p_k are indices. The formula uses the Einstein notation (implicit sum over repeated indices).

In case R is complex, the k-th R in the above formula need to be conjugated if key has a 1 in the k-th place (meaning that the corresponding operator is a creation operator).

general_tensor A square numpy array or matrix containing information about a general interaction tensor.
rotation_matrix A square numpy array or matrix having dimensions of n_qubits by n_qubits. Assumed to be unitary.
key A tuple indicating the type of general_tensor. Assumed to be non-empty. For example, a tensor storing coefficients of \(a^\dagger_p a_q\) would have a key of (1, 0) whereas a tensor storing coefficients of \(a^\dagger_p a_q a_r a^\dagger_s\) would have a key of (1, 0, 0, 1).

transformed_general_tensor general_tensor in the rotated basis.