If we have a composite system over five qubits ($|\psi\rangle = |a\rangle|b\rangle|c\rangle|d\rangle|e\rangle$), and I want to project into a specific subspace of the first three systems, I can build a projector of the form $|011\rangle\langle011| \otimes I_{de}$ (for example). Before projecting, state $|\psi\rangle$ can be thought of as an array with length $2^5 = 32$. My goal is to do the projection and reduce the size of my vector appropriately (so now I only have an array over the final two qubits). I'm doing this in Qiskit (after I get the statevector and am done evolving). My projectors will always have the form above, just perhaps with a different bitstring (in my example, I had "011"). This is what I've done so far:
Since the projectors are diagonal, I convert the string "011" into an integer. In this case, it's 3. The corresponding matrix will look like: $$ \begin{pmatrix} 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ \end{pmatrix} .$$
Because the subspace is like this, the identity matrix $I_{de}$ will just be a matrix of size $2^2\times2^2$ and when we take the tensor product, we will get a matrix similar to the one above, but now the size of the matrix will be bigger, and the $1$ that's above will be the only place where the identity shows up (since everywhere else will be zero). I won't write down the matrix because it has size $32\times32$.
If I have my state $|\psi\rangle$ and I want to project down, I figured I just had to find the components of my 32-element array which correspond to this subspace.
If the position of the 1 in my matrix above is given by $p$ and my state is an array called
psi
, then I want to say that the projection is given by simply slicing my array as such:projected = psi[(2**2)p:(2**2)*(p+1)]
My question is: Am I doing the right slicing in step 4? I think I am, but it's easy to get tripped up with these subspaces. I know that this won't work in general since the projection operator could be more involved, but in the case where it's diagonal like the above matrix and is only one element, do I have the steps involved correct?