I am interested in generating collective Pauli X, Y and Z spin operators for the purpose of rotating $2^N$ dimensional state vectors $|\psi\rangle$ (in the computational basis) for a quantum protocol. To this end I need to generate large Pauli operators of the form \begin{align} \hat{J_{x}}:= \frac{1}{2}\sum_{i=1}^{N}\hat{\sigma}_{i}^{x}, \end{align} where $\hat{\sigma}_{i}^{x}$ denotes the Pauli-X operator acting on the $i$-th qubit. These collective operators are used for exponential matrix rotations of the form $\text{exp}\big(-i \theta \hat{J}_{x}\big)|\psi\rangle$. I am able to do this with Numpy:
from numpy import *
import numpy as np
import math
from sympy.physics.quantum import TensorProduct
from scipy.linalg import expm
# Set System Size
N = 4
# Pauli spin operators
I = np.identity(2)
px = array([[0, 1],
[1, 0]])
px = mat(px)
# Define initial spin up state as column vector S.
S = zeros((2**N, 1), dtype=np.complex_)
S[0, 0] = 1.0
S = mat(S)
# Defining collective spin X rotation operator
lists1 = [[] for _ in range(N)]
# List used for calculating the exponential factor of exponential matrix.
for i in range(N):
for j in range(N):
if i == j:
lists1[i].append(px)
else:
lists1[i].append(I)
# lists of tensor product exponential factors for collective spin X operator.
tenex = []
for i in range(N):
tens = TensorProduct(*lists1[i])
tenex.append(tens)
Jx = (1/2)*np.sum(tenex, 0)
Jx = mat(Jx)
# Rotation of state vector using the collective rotation.
S = expm((-1j*math.pi/2.)*Jx)*S
print(Jx)
print(S)
But for large N this becomes inefficient. To this end I am looking at the Qutip library. Can anyone advise on how to generate the collective operators $\{\hat{J}_x, \hat{J}_{y}, \hat{J}_z\}$ and convert them to NumPy arrays, or alternatively can I apply the rotations using the Qutip module directly to an arbitrary state vector NumPy array and then convert the final state to a NumPy state vector?
Lastly, is there maybe a different more efficient way of defining and executing these large collective rotations (maybe using sparse matrices)?
Thanks for any assistance.