# 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?). Commented Aug 14, 2020 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. Commented Aug 14, 2020 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. Commented Aug 14, 2020 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! Commented Aug 14, 2020 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 θ! Commented Aug 14, 2020 at 12:20

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.
• 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. Commented Aug 12, 2020 at 8:28