Why is declared that $0 \le \theta \le \pi$ for Qiskit's U3 gate?

It stated in Qiskit's documentation.

This question arose after I accidentally called the U3 gate with parameter $$\theta$$=$$2\pi$$ in the program and Qiskit executed the program without error:

tetha = 2 * np.pi
qc.u3(theta, phi, lam, reg)

I checked other values out of bounds and every time it worked (including looping at a distance of $$4\pi$$) according to the formula for U from the documentation (judging by the resulting unitary operator) but ignoring violation of declared boundaries for $$\theta$$, e.g:

print(Operator(U3Gate(1.5 * np.pi, 0, 0)))
print(Operator(U3Gate(5.5 * np.pi, 0, 0)))
print(Operator(U3Gate(-.5 * np.pi, 0, 0)))
print(Operator(U3Gate(3.5 * np.pi, 0, 0)))

Operator([[-0.70710678+0.j, -0.70710678+0.j],
[ 0.70710678+0.j, -0.70710678+0.j]],
input_dims=(2,), output_dims=(2,))
Operator([[-0.70710678+0.j, -0.70710678+0.j],
[ 0.70710678+0.j, -0.70710678+0.j]],
input_dims=(2,), output_dims=(2,))
Operator([[ 0.70710678+0.j,  0.70710678+0.j],
[-0.70710678+0.j,  0.70710678+0.j]],
input_dims=(2,), output_dims=(2,))
Operator([[ 0.70710678+0.j,  0.70710678+0.j],
[-0.70710678+0.j,  0.70710678+0.j]],
input_dims=(2,), output_dims=(2,))

But do $$\theta$$ values outside the declared range make any real sense in quantum computing?

Or is it just a little flaw in Qiskit?

Just in case, the formula for the U3 gate is $$\mathrm{U3}= \begin{pmatrix} \cos(\theta/2) & -\mathrm{e}^{i\lambda}\sin(\theta/2) \\ \mathrm{e}^{i\phi}\sin(\theta/2) & \mathrm{e}^{i(\phi+\lambda)}\cos(\theta/2) \end{pmatrix}.$$

• Hi @Psanfi! Could you tell: 1. what kind of checks did you make? 2. your question has only theoretical meaning or were you planning to somehow use the U3 gate with out-of-range θ values (if the latter, then how exactly?). Aug 14 '20 at 6:10
• Psanfi sent me an answer to my questions: 1. I checked e.g. whether the matrices correspond to the formula, as well as unitarity. 2. In addition to theoretical interest, I would like e.g. to construct a global phase shift gate I need by using a single U3 gate. But this is possible if θ is allowed to go out of the declared range (i.e. θ=2π). Then use it when construct a controlled version of gates. Aug 14 '20 at 9:48
• I advise you to look at the source code of the corresponding Qiskit's module, where the matrix is formed according to the formula you specified without any checks for ranges, in addition, the matrix formed according to this formula is a priori unitary. Aug 14 '20 at 10:09
• Thanks for the advice, I also checked the difference in the global phase at the intervals π and 2π (with 4π, everything is clear anyway). What else can I check? PS. Thanks for helping post my previous answer! Aug 14 '20 at 10:25
• By the way, why is the gate U3 (π, π, 0) not suitable as a "sign flip" gate? In this case, you do not have to be afraid to violate the declared range for θ! Aug 14 '20 at 12:20

1 Answer

You use the mathematical representation of the gate to generate something you can apply to your qubit. Nothing breaks if you input $$\theta$$ higher that the range given. We can see this with some examples : With $$\theta = 0$$ and not thinking about the phase, $$U3 = \begin{pmatrix} 1 & 0 \\ 0 & 1 \\ \end{pmatrix}$$ With $$\theta = \frac{\pi}{2}$$ and not thinking about the phase, $$U3 = \begin{pmatrix} 0.7071 & 0.7071 \\ 0.7071 & 0.7071 \\ \end{pmatrix}$$ With $$\theta = \pi$$ and not thinking about the phase, $$U3 = \begin{pmatrix} 0 & 1 \\ 1 & 0 \\ \end{pmatrix}$$ With $$\theta = \frac{3\pi}{2}$$ and not thinking about the phase, $$U3 = \begin{pmatrix} -0.7071 & 0.7071 \\ 0.7071 & -0.7071 \\ \end{pmatrix}$$ With $$\theta = 2\pi$$ and not thinking about the phase, $$U3 = \begin{pmatrix} -1 & 0 \\ 0 & -1 \\ \end{pmatrix}$$ The process then continues alternating a global phase of -1 and 1. As you can see the only thing changing are the pbases and not the complex amplitudes so there is no problem with the quantum computation.

• The tan() function is not used in the formula for the U3 gate in the link I gave. In addition, my question is not about repeatability, I am interested in whether something is broken in the sense of quantum computation if you use values outside the declared range Aug 11 '20 at 9:57
• The action of U3 is determined by the matrix you provided. Since you can plug in any value in sine/cosine this definition holds for any input angles. However if you restrict the inputs to the interval [0,pi] the mapping from theta to the matrix of U3 is bijective, for values outside of this interval the matrix U3 “repeats itself” (which is what @Jonathcraft meant I think) Aug 11 '20 at 10:24
• @psanfi I changed my answer. Is it answering your question now ? Aug 11 '20 at 14:06
• Thanks for your attention to this topic! I also previously calculated matrix variants with even smaller steps and checked the correctness. This certainly gives some confidence, but I think that it is not complete. If you look at the section in the documentation for the link I mentioned, then there are conditions and restrictions (including for theta) under which the formula for the gate is derived. I am wondering if something is violated in this derivation of the formula (and if so, what exactly) when theta goes out of range. Or reasonable arguments, then nothing is violated. Aug 12 '20 at 2:47
• Have you heard about the bloch sphere ? Changing $\theta$ will make you rotate around it. This will maybe convince that nothing breaks. The qiskit documentation team probably put this bound because, as I calculated, increasing it past the bound may change the phase, you would have to counter this fact by changing $\phi$ or $\lambda$ which can be tedious and extra, unnecessary math. Aug 12 '20 at 8:28