I went through the link " https://learn.qiskit.org/course/ch-applications/hybrid-quantum-classical-neural-networks-with-pytorch-and-qiskit" where a hybrid of classical and quantum computation is used. As per my understanding the classical components is encoded using angle encoding for quantum computation. I could not understand that if I want to use some other encoding such as amplitude encoding...how would I go about.I am not sure how to implement angle encoding and amplitude encoding in pytorch. Thanks in Adv.


1 Answer 1


As for the angle encoding of single qubit:

Given a single-qubit state $|\psi\rangle$ and a factor $|\alpha| \le 1.0$, we know that we can write the state in the following form because adding up the norm of the probability amplitudes will add up to 1.0: \begin{equation} |\psi\rangle = \sqrt{1 - \alpha^2}\, |0\rangle+ \alpha\,|1\rangle. \end{equation}

In the following, we show how this can be achieved by a rotation about the y-axis by a specific angle $\theta$.

Let us remind ourselves of the $R_y$ operator to perform a rotation about the y-axis: $$ R_y(\theta) = \begin{bmatrix} \cos{\frac{\theta}{2}} & -\sin{\frac{\theta}{2}} \\[0.7mm] \sin{\frac{\theta}{2}} & \cos{\frac{\theta}{2}} \end{bmatrix}. $$ Applying $R_y$ to state $|0\rangle$: $$ R_y(\theta)|0\rangle = R_y(\theta) \begin{bmatrix} 1 \\ 0 \end{bmatrix} \\ = \begin{bmatrix} \cos \frac{\theta}{2} \\[0.7mm] \sin \frac{\theta}{2} \end{bmatrix} \\ =\begin{bmatrix} \sqrt{1 - \sin^2 \frac{\theta}{2}} \\[0.7mm] \sin \frac{\theta}{2} \end{bmatrix}. $$ Now we can simply define $\theta = 2\,\arcsin(\alpha)$ and use the $R_y(\theta)$ gate to get the state $|\psi\rangle$ as desired.

One can also use Amplitude Amplification (QAA) to encode a smaller number of similar amplitudes in a state (example here). The idea is to mark the states to encode as solutions for QAA and perform the Grover rotations. At the end, these states will have significantly higher probability than the other states. Alas, their amplitudes will all be the same.

As for general amplitude encoding, for multi-qubit states, I've recently implemented Moettoenen's algorithm (paper here, code here). It's quite complicated.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.