How to find correct angle values for Parametrized Quantum U3 gates and Controlled U3 gates using Qiskit

Beginner-friendly tutorial encouraging baby-steps in Quantum Computing using Qiskit

Dr. Pragya Katyayan
7 min readOct 9, 2020
Source: Wikipedia. Bloch sphere representing different basis (x, y, z), states (0, 1, 𝜓) and relevant angle values (𝜃 and ϕ) as visualized for a single qubit.

In my previous tutorial-blog, I explained how to calculate the angle values for Rϕ gates with the help of a particular case. As promised, this one will explain how to calculate angle values for the U-gates and Controlled U3 gate.

General U Gates

General U gates are generic single-qubit rotation gates with 3 Euler angles (i.e. θ, ϕ, λ). It is called ‘general’ because any single qubit quantum gate can be represented by a U(θ, ϕ, λ) gate.

General U3 gates are given by:

Eq. (1)

Qiskit provides U2 and U1-gates, which are specific cases of the U3 gate. For U2 gate- θ=π/2, and for U1 gate- θ=ϕ=0, respectively. This makes the U1-gate equivalent to the Rϕ-gate. Here we will be dealing with a general U3 gate and will calculate it’s parameters to solve a particular problem.

Objective 1: Create the state given below using only one U3 gate:

Eq. (2)

We know that the U3 gate is given by the matrix given in Eq. (1). Also, we can write the value of |𝜓⟩ in the form of a column vector:

Eq. (3)

Just to visualize what a U3 gate looks like, let’s build a demo circuit:

Since this is a single qubit gate, the circuit has only one qubit whose initial value is |0⟩. This means, this U3 gate applied on state |0⟩ of our qubit should lead to the column matrix of Eq. (3).

Equating individual elements, we get:

Eq. (4)

Using the value of θ in next equation:

We can write this as:

Eq. (5)

Since, in this case, both the terms having λ were multiplied by 0, the value of λ can be anything. It doesn’t have any impact on the final state.

Implementing the circuit with calculated θ and 𝜙 values:

Executing and visualizing the circuit to find out the final state:

The statevector shows two complex values where the value is 0.5 for |0⟩ (with 0 imaginary part) and 0.8660j for |1⟩ (with negligible real part). This gives us the state we aimed for in our objective.

Finding the probability of measuring the states:

Probability of finding a particular output (|𝑥⟩) in a given state (|𝜓⟩) is given by: |⟨𝑥|𝜓⟩|² i.e. the square of their inner product. So, Let’s find the probabilities state-wise, starting with state |0⟩:

We know that, ⟨0|0⟩=1 and ⟨0|1⟩=0 [a useful thing to remember is that the inner product of two orthogonal vectors is 0], so:

Eq. (6)

Now, calculating for state |1⟩:

Eq. (7)

Now, plotting the probabilities of states on a histogram using get_counts():

Values match with what we calculated in Eq. (6) and (7)

Hence, here we saw a simple case of calculating the parameters of a U3 gate to achieve any given state. We also calculated the probabilities and checked via Qiskit programming. You can similarly try to generate different states based on the rules of Quantum Computing.

Controlled U3 Gates:

Controlled-U3 gate is a 3-parameter two-qubit gate. This is a controlled version of the U3 gate (generic single qubit rotation). It is restricted to 3 parameters (i.e. θ, ϕ, λ). It can be applied to any qubit controlled on the opposite qubit.

A CU3 gate controlled on q0 and q1 (Source: qiskit.circuit.library.CU3Gate)

Let’s try to solve a question to understand how to find the θ, ϕ and λ for our CU3 gate.

Objective 2: Modify the output of a given circuit such that the system is transformed to |↻⟩⊗|1⟩ using only a single ControlledU3 gate, where the state |↻⟩ is:

Given circuit visualization

According to the question, we need to apply a CU3 gate in the given circuit to get the resultant state |𝜓⟩=|↻⟩⊗|1⟩. Let us first solve and see the desired state in a simplified way:

Eq. (8)

So, this is the final column we are expected to have after applying the CU3 gate on given circuit. Now, let’s solve the given circuit. The initial state of both qubits, q0 and q1 is |0⟩. After applying Hadamard gate on q0 we get:

and applying an X gate on q1 we get:

Getting the combined state of both qubits in the given circuit:

Eq. (9)

Working on the transformation:

We know that, parametrized CU3 gate is given by the following matrix:

Applying CU3 gate on the given circuit (Eq.(9)) and equating with desired state (Eq.(8)):

Now we have two equations:

Solving the first equation for 1, we get 𝜃=0 or 𝜃=2𝜋.

In that case, solving second equation:

Using Euler’s formula, we can write it as:

Since we have only imaginary part on the RHS, LHS has to match up. So, (𝜙+𝜆) has to be a value that gives 0 for cos and 1 for sin.

i.e. (𝜙+𝜆)=3𝜋/2 (because cos(3𝜋/2)=0 and sin(3𝜋/2)=1)

This gives us several possibilities for both 𝜙 and 𝜆:

Case 1: 𝜙=3𝜋/2 and 𝜆=0

Case 2: 𝜙=0 and 𝜆=3𝜋/2

Case 3: 𝜙=𝜋 and 𝜆=𝜋/2

Case 4: 𝜙=𝜋/2 and 𝜆=𝜋

All these cases give the correct answer and can be tried as an exercise. We will see the circuit for Case 1 here:

Plotting the statevector on the bloch sphere:

The statevector values give us the desired state: 0.707 |0⟩ and -0.707j for |1⟩ which was our desired state (Eq. 8). Now let’s visualize the final circuit on the q-sphere:

Like the previous tutorial, this one is also done using Qiskit version 0.21.0. So, here we end our little tour about dealing with the parametrized general U3 gates and controlled U3 gates. I tried to explain both gates with particular cases, both of which I came across in the #QiskitIndia Challenge. Solving these was fun, I hope you enjoyed and learned too. If this tutorial helped you, please leave a clap. In case of any doubts, feel free to comment, I’ll try my best to answer.

Thanks for reading through!

P.S. The notebook having both of these exercises can be found here and can be viewed here. (It has solutions for all the cases discussed in the tutorial).

References:

  1. Abraham Asfaw, Luciano Bello, Yael Ben-Haim, Sergey Bravyi, Nicholas Bronn, Lauren Capelluto, Almudena Carrera Vazquez, Jack Ceroni, Richard Chen, Albert Frisch, Jay Gambetta, Shelly Garion, Leron Gil, Salvador De La Puente Gonzalez, Francis Harkins, Takashi Imamichi, David McKay, Antonio Mezzacapo, Zlatko Minev, Ramis Movassagh, Giacomo Nannicni, Paul Nation, Anna Phan, Marco Pistoia, Arthur Rattew, Joachim Schaefer, Javad Shabani, John Smolin, Kristan Temme, Madeleine Tod, Stephen Wood, James Wootton. 2020. The Qiskit Textbook. IBM Quantum. Chapters: 1.3 & 1.4.
  2. The Qiskit Circuit Library.

--

--

Dr. Pragya Katyayan

PhD (CS) with specialization in Quantum Computing and Natural Language Processing.