Visualizing parameterized quantum classifiers.

The case of one qubit data.

Slimane Thabet
Towards Data Science

--

The goal of this post is to explain the parameterized binary classifier of a quantum state in the case of 1 qubit. This simple case allows us to have some nice visualizations and even some analytical expressions.

The first part will state the results and display the figures, whereas the technical proofs will be left to the second part. So if you don’t like equations, you can stop reading after the first part.

I encourage everyone not familiar with the spherical coordinates to have a look here, since it is the core of this post.

This post is not an introduction to quantum computing, here is one of the clearest video about it. Here is a more detailed article.

All the figures have been created with the library QuTip.

Visualizations and results

The Bloch sphere

A quantum state can be represented as a complex vector |Ψ> = 𝑎|0>+𝑏|1> such as |𝑎|² + |𝑏|² = 1. It is also defined up to a global phase, and we can write |Ψ> = cos(𝜃/2)|0> + e^(iϕ)sin(𝜃/2)|1> with 𝜃 ∈ [0, π] and ϕ∈ [0, 2π]. The couple (𝜃, ϕ) defines a point on the unit sphere of R^3, and such a representation of the qubit is called the Bloch sphere.

Here is an example of quantum states represented in the Bloch sphere. In blue the state |0>, in red the state |1> and in green the state 1/√2 (|0> + |1>).

Binary classifier of quantum states.

As in a classical classification problem, we suppose that for each quantum state is associated a label y in {0, 1}. We have this label observed for a set of states called the training set, and we wish to construct a function which predicts the label of a new quantum state. We wish to construct a parameterized unitary operator U(⍺) such as

U(⍺)|Ψ(x)> =√P(y=0)|0> + P(y=1)|1>

The probabilities are estimated by measuring the quantum state. One can then compute a cost function, and update the parameters with a classical optimizer.

We will not talk about that in this post, the objective is to visualize the effect of a parameterized classifier on the Bloch sphere.

Basic properties of the classifiers

Fortunately, in the one qubit case, the unitary operators are quite simple, and can be fully characterized by 3 parameters. The general form is given by the following formula.

It means that we only have to look at this family of matrices to find our candidate classifier. Moreover, we can prove that the parameter ϕ has no influence on the final probability. It reduces us to the final following form.

Properties of the border

The border is defined by the set of points for which P(y=0) = P(y=1) = 1/2. In the case of a binary classifier on one qubit, this border is a circle that cuts the Bloch sphere in two equal hemispheres. One hemisphere contains all the quantum states classified as 0 and the other contains all the quantum states classified as 1.

Visualizations

Let us now visualize what the results of the classifiers look like. For each following graph, we plot the classification regions in red and blue which have been computed by a quantum simulator. The border is drawn in black, knowing the equation of the circle.

Below are the results for 𝜃 = 0 and 𝜃 = π and in both cases λ = 0. Completely flipping 𝜃 doesn’t change the place of the border which is in the plan (x,y), but the labels are inverted.

We’ll now have a look at 𝜃 = π/2 still with λ = 0. The border has rotated from the plan (x,y) to the plan (y,z).

Now, more general values with 𝜃 = π/6, and λ = 0, λ = 3π/2. Modifying λ while keeping 𝜃 constant is like spinning the sphere around the z axis.

The maths

Let us now prove in details everything we’ve seen before.

Proof that ϕ doesn’t influence the probability.

Let |Ψ> =⍺|0> + β|1> be a general quantum state, and let us look at the effect of a general unitary U(𝜃, ϕ, λ).

U|Ψ> = cos(𝜃/2)|0> + e^(iϕ)sin(𝜃/2)|1> + (-sin(𝜃/2)e^(iλ)β)|0> + e^(iϕ+iλ)cos(𝜃/2)β|1> = [cos(𝜃/2)+ (-sin(𝜃/2)e^(iλ)β)]|0> + [e^(iϕ)sin(𝜃/2) + e^(iϕ+iλ)cos(𝜃/2)β]|1>

We now take the module square of the amplitude associated to |1>.

And we have P(y=1) = |e^(iϕ)sin(𝜃/2) + e^(iϕ+iλ)cos(𝜃/2)β|²= |e^(iϕ)|²|sin(𝜃/2) + e^(iλ)cos(𝜃/2)β|² =|sin(𝜃/2) + e^(iλ)cos(𝜃/2)β|²

Therefore, the classification probabilities are independent of ϕ.

Equation of the border.

Let |Ψ> = cos(𝜃/2)|0> + e^(iϕ)sin(𝜃/2)|1> and let us consider the unitary U(Θ, λ) defined the following way.

It is like setting ϕ=0 in the previous paragraph.

We then have that the probability to be classified 1 is:

P(y=1) = |sin(Θ/2)cos(𝜃/2) + e^(iλ+iϕ)cos(Θ/2)sin(𝜃/2)|² when replacing and β with their expressions. Please do not confuse this ϕ with the one in the previous paragraph.

Expanding the full expression gives us

We can reduce the last two terms using the fact that cos²+sin²=1, and we can reduce the second term by using the identity sin(2) = 2cos(⍺)sin(⍺).

We then use the identities sin(⍺/2) = (1-cos(⍺))/2 and cos(⍺/2) = (1+cos(⍺))/2 and we have

The border is such as P(y=1) = 1/2. Therefore, it is the set of (𝜃, ϕ) such as cos(λ+ϕ)sin(Θ)sin(𝜃) - cos(Θ)cos(𝜃) = 0.

Equation of the border:

cos(λ+ϕ)sin(Θ)sin(𝜃) — cos(Θ)cos(𝜃) = 0

We will then show that this equation characterizes a circle on the unit sphere centered in the origin.

Equation of a circle in spherical coordinates

A circle on the unit sphere centered in the origin can be fully characterized by a normal vector, as shown in the figure below. Let x = (𝜃ᵤ, ϕᵤ) the coordinates of this vector.

Let (𝜃, ϕ) a point of the circle. The orthogonality with xcan be written as:

sin(𝜃ᵤ)cos(ϕᵤ)sin(𝜃)cos(ϕ) + sin(𝜃ᵤ)sin(ϕᵤ)sin(𝜃)sin(ϕ) + cos(𝜃ᵤ)cos(𝜃) = 0

sin(𝜃ᵤ)sin(𝜃)(cos(ϕᵤ)cos(ϕ) + sin(ϕᵤ)sin(ϕ)) + cos(𝜃ᵤ)cos(𝜃) = 0

By using the trigonometry addition formulae,

sin(𝜃ᵤ)sin(𝜃)cos(ϕᵤ+ϕ) + cos(𝜃ᵤ)cos(𝜃) = 0

Our final circle equation is:

sin(𝜃ᵤ)sin(𝜃)cos(ϕᵤ+ϕ) + cos(𝜃ᵤ)cos(𝜃) = 0

By identifying the terms in cos(λ+ϕ)sin(Θ)sin(𝜃) — cos(Θ)cos(𝜃) = 0 (previous paragraph), we have ϕᵤ=λ, and 𝜃ᵤ=π-Θ.

Therefore, the border is a circle, for which we can compute the equation given the initial unitary parameters.

And this is it, some visualizations on quantum classifiers, and the proofs coming along. Parameterized quantum classifier are fully explained in this paper by Maria Schuld et al.

Feel free to share your feedback, you can contact me on LinkedIn, or post a response to the article.

--

--