2
$\begingroup$

I am trying to implement the 4-qubit example outlined in showed in section 3 of the qiskit tutorial on the HHL algorithm. Does anyone know what are the 2 angles that the Ry gate needs to be applied with? They say what the values of C and the approximated values of the eigenvalues are ($\tilde {\lambda_1}$ and $\tilde {\lambda_2}$), but they don't mention the rotation angles. Are they just $\theta_1 = \arccos(\frac{C}{\tilde {\lambda_1}})$ and $\theta_2 = \arccos(\frac{C}{\tilde {\lambda_2}})$ ?

$\endgroup$
1
$\begingroup$

Just to be really precise, let's take the definition of the $R_y$ gate as

$$ R_y(\theta) = \exp(-i\frac{\theta}{2}Y) = \begin{pmatrix} \cos\frac{\theta}{2} & -\sin\frac{\theta}{2} \\ \sin\frac{\theta}{2} & \cos\frac{\theta}{2} \end{pmatrix} $$

from the Qiskit documentation, and the values from the textbook example. Then you would have to apply a $2$-controlled $R_y(\theta_1)$ by $01$ with $\theta_1 = -2\arcsin\left(\frac{3/8}{1/4}\right)$, and similarly, a $2$-controlled $R_y(\theta_2)$ by $10$ with $\theta_2 = -2\arcsin\left(\frac{3/8}{1/2}\right)$.

$\endgroup$
2
  • $\begingroup$ Thanks for your reply! So I would have to do a controlled rotation specifically on |01> and |10>? Why isn't it enough to do a controlled rotation on the entire register which contains the binary representations of the eigenvalues? $\endgroup$
    – Martin
    May 26 '20 at 9:04
  • $\begingroup$ That would be the 'lazy' and non-optimal but easiest to understand approach, but you can always optimise the gates. For example, here it would be enough to use 1-controlled rotations by either the first or second qubit since no representation contains two 1's. However, if you mean one single controlled rotation, that wouldn't work (exceptions aside) since for different values you have to rotate by different angles. In general, for n qubits and $2^n$ possible eigenvalues it is enough to use $2^n$ single controlled $R_y$'s, and the angles can be found using e.g. the UniversalQCompiler. $\endgroup$
    – user96233
    May 26 '20 at 16:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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