I am trying to make a operator for S-Box for AES. The matrix is non-unitary. When I use Operator command for declaring it as a function. It gives error, the matrix is non-unitary. Thus, the qiskit does not allow non-unitary operators to be implemented. Is there any way to implement the non-unitary operator in qiskit or cirq etc?
1 Answer
There are several ways to apply a classical function in quantum computing. Here, I think you're interested in one of the following two.
The first one is the standard oracle: $$U_f|x,y\rangle=|x,y\oplus f(x)\rangle$$ where $\oplus$ is the bitwise-XOR. This is the most common, as it allows to apply quantum functions even if they're not bijective.
However, there's another type of oracle, called erasing oracle or minimal oracle: $$V_f|x\rangle=|f(x)\rangle$$ Because of the requirement of unitarity, in order to use this oracle the function must be injective (though bijective is easier).
The thing is, the AES S-BOX is bijective, since it is essentially a lookup table with unique values. Since it takes an 8-bit number and returns another 8-bit number, you can build a $2^8\times2^8$ matrix where the first column is all $0$ except in $S(0)=$0x63
$=99$, the second column is all zeros except in $S(1)=$0x7c
$=124$, etc...
You can then apply this matrix, which is unitary since it's a permutation matrix, which corresponds in this case to an erasing oracle.
The standard oracle is a bit different, but similar in the process. You take a $2^{16}\times2^{16}$ matrix, where the $256x+y$ column is all zeros except in $256x+(y\oplus S(x)$, for all $x$ and $y$ being between $0$ and $255$ included. Once again, it is unitary since it's a permutation matrix.
As a side note, you probably don't want to implement the actual AES in Qiskit. AES' state being 128-bit long, you'd need a $2^{128}$ statevector to represent it with Qiskit, which clearly won't fit in your computer memory, not to mention the $2^{128}\times2^{128}$ matrices you'd have to apply. These numbers are for an erasing oracle, while you probably want a standard one in order to apply Grover's algorithm, in which case replace the $2^{128}$ by $2^{256}$.
Thus, you probably want to design an "AES" that acts on very small states, where a case of your state is only represented on 1 bit or two. This would still allow you to understand how you could implement such a function in Qiskit.
-
$\begingroup$ thankyou, actually i am just doing it for a 8-qubit code, which i will repeat multiple times to complete a 256 bit input. So, the S-box is 8x8 but no-unitary, Now, i have used linear GF for constructing a unitary S-box (which i check by multiplying s-box matrix with its transpose) but the qiskit Operator commands gives error still. claiming its a non-unitary matrix. $\endgroup$ Sep 15 at 6:58
-
$\begingroup$ @SyedShahmirKazmi Can you pour the code you've used to create this matrix in your question, along with how you try to append it to your circuit? $\endgroup$ Sep 15 at 7:38