I know that U1 equivalent gate of Qiskit in Q# is R1, but I would like to implement U2 and U3 gate of Qiskit in Q#, what is the best way ?

Thank you.

  • $\begingroup$ Do you need to implement U2 directly or do you have a specific unitary in mind? What I mean by that is that U2/U3 are more general forms for unitaries, but algorithms typically only require a restricted gate that doesn't need to be expressed as U2/U3 $\endgroup$
    – C. Kang
    Sep 8, 2020 at 0:26

1 Answer 1


The gates Rx, Ry and Rz in Q# have the same definition as RXGate, RYGate and RZGate in Qiskit, and the U2Gate and U3Gate documentation offers decomposition of these gates into Rx, Ry and Rz, so I would just use that decomposition:

operation U2(psi : Double, lambda : Double, q : Qubit) : Unit is Adj + Ctl {
    Rz(lambda, q);
    Ry(0.5 * PI(), q);
    Rz(psi, q);

and a similar one for U3.

  • $\begingroup$ Thank you Mariaa, this is what I have tested but I have seen something : If I simulate U2 or Rz/Ry/Rz gate with both Pi/4 for lambda and psi in Qiskit, then my state vectors are [ 0.707+0j, 0.5+0.5j ] Then if I simulate Rz/Ry/Rz with Q#, then I dumpmachine to get state vectors, I got : ∣0❭: 0,500000 + -0,500000 i == ********** [ 0,500000 ] \ [ -0,78540 rad ] ∣1❭: 0,707107 + 0,000000 i == *********** [ 0,500000 ] --- [ 0,00000 rad ] So there is a minus sign wich is different from Qiskit, is it normal ? $\endgroup$
    – user12910
    Sep 8, 2020 at 7:23
  • $\begingroup$ These states are the same up to a global phase (1-i)/√2 - multiply Qiskit state by this number and you'll get the expression Q# gives you. So yes, this is normal $\endgroup$ Sep 8, 2020 at 7:32
  • 2
    $\begingroup$ Thank you Mariia, answer clear and complete as usual ! $\endgroup$
    – user12910
    Sep 8, 2020 at 8:20

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.