 Home

Account

Service

Company

Overview
Service overview

Contact # Internship lecture 3 : QAOA

#### Yuichiro Minato

2022/09/03 12:54

1

This is the third internship lecture. Finally, we are going to start quantum computation.

## Quantum States and State Vectors.css-1yssqf7{opacity:0.6;border:0;border-color:inherit;border-style:solid;border-bottom-width:1px;width:100%;margin-top:var(--chakra-space-2);}

Unlike today's computers, the data used in a quantum computer is handled differently: a single qubit is represented using a sphere. A qubit has a |0> state and a |1> state, which can be represented by a vector.

$\mid 0 \rangle = \begin{bmatrix} 1 \\ 0 \end{bmatrix}, \mid 1 \rangle = \begin{bmatrix} 0 \\ 1 \end{bmatrix}$
$\mid \psi \rangle = \alpha \mid 0 \rangle + \beta \mid 1 \rangle = \alpha \begin{bmatrix} 1 \\ 0 \end{bmatrix} + \beta \begin{bmatrix} 0 \\ 1 \end{bmatrix} = \begin{bmatrix} \alpha \\ \beta \end{bmatrix}$

The following conditions are satisfied

$|\alpha|^2+|\beta|^2 = 1$

$\mid \psi \rangle$ is called the state vector (wave function) and represents the quantum state of a qubit. The $\alpha$ and $\beta$ are complex numbers and are called "amplitudes", and squaring them gives the probability of occurrence of the corresponding computational basis, and $|\alpha|^2$ and $|\beta|^2$ can be obtained by "measurement".

## Polar coordinate representation of quantum states

The Bloch sphere is a notation for representing quantum states on the unit sphere that can be expressed as a superposition of two orthogonal pure states. $\mid \psi \rangle = \begin{bmatrix} cos\theta & -sin\theta e^{-i\phi}\\ sin\theta e^{i\phi} & cos\theta \end{bmatrix} \begin{bmatrix} 1\\0 \end{bmatrix} = \begin{bmatrix} cos\theta \\ sin\theta e^{i\phi} \end{bmatrix}$

You can also use angle-based parameter notation, such as Remember that quantum data is expressed in terms of angles.

## Manipulating state vectors and quantum gates

To manipulate state vectors, quantum gates are used. The basic Pauli gate, arbitrary rotation gate, and Hadamar gate are mainly used in variational algorithms.

There are three types of Pauli gates, XYZ, each of which implies a 180-degree rotation around the XYZ axis in the Bloch sphere, and the corresponding matrices are

$X= \begin{bmatrix} 0&1 \\ 1&0 \end{bmatrix} , Y= \begin{bmatrix} 0&-i \\ i&0 \end{bmatrix} , Z= \begin{bmatrix} 1&0 \\ 0&-1 \end{bmatrix}$

Also, arbitrary rotation around the XYZ axes is made with the RX, RY, and RZ gates, and

$Rx(\theta) = \begin{bmatrix} \cos\left(\frac{\theta}{2}\right) & -i\sin\left(\frac{\theta}{2}\right)\\ -i\sin\left(\frac{\theta}{2}\right) & \cos\left(\frac{\theta}{2}\right) \end{bmatrix}, Ry(\theta) = \begin{bmatrix} \cos\left(\frac{\theta}{2}\right) & -\sin\left(\frac{\theta}{2}\right)\\ \sin\left(\frac{\theta}{2}\right) & \cos\left(\frac{\theta}{2}\right) \end{bmatrix}, Rz(\theta) = \begin{bmatrix} e^{-i\frac{\theta}{2}} & 0\\ 0 & e^{i\frac{\theta}{2}} \end{bmatrix}$

The quantum state can be changed by acting these quantum gates on the state vector.

$X \begin{bmatrix} 1 \\ 0 \end{bmatrix} = \begin{bmatrix} 0&1 \\ 1&0 \end{bmatrix} \begin{bmatrix} 1 \\ 0 \end{bmatrix} = \begin{bmatrix} 0 \\ 1 \end{bmatrix}$

The Hadamar gate is a convenient gate that rotates around the XZ axis.

$H= \frac{1}{\sqrt{2}} \begin{bmatrix} 1&1 \\ 1&-1 \end{bmatrix}$

## Eigenvalue and eigenvector problems

Various problems can be solved if eigenvalues and eigenvectors for a given matrix can be found. For a given matrix $H$ (called the Hamiltonian), if the eigenvalues are $E_0$ and the eigenvectors are $\mid \psi \rangle$.

$H \mid \psi \rangle = E_0 \mid \psi \rangle$

The objective is to find $E_0$ and $\mid \psi \rangle$ such that The $\mid \psi \rangle$ is called the state vector (wave function).

Most quantum computer problems correspond to this eigenvalue problem. We set the problem on the matrix H and look for the eigenvalues E.

## Quantum Variational Principle

Finding eigenvalues is the main optimization used in NISQ. We learned how to use numerical optimization on the seconde lecture.

$\langle \psi (\theta) \mid H \mid \psi (\theta) \rangle \geq E_0$

Since it is tough to find the eigenvalues directly, we drop indirectly into an optimization calculation that brings us as close as possible to the expected value of the eigenvalues. Since the Hamiltonian $H$ is a given expression, all we can do is to find a state vector $\mid \psi (\theta) \rangle$ as close as possible to the eigenstates as an optimization calculation of the angle is the goal of this project. The search for the state vector is achieved by creating a circuit called ansatz.

## Hamiltonian and its expectation value

The Hamiltonian $H$ is a Hermitian matrix consisting of a Pauli gate XYZ and a unit matrix I. The expected value $E$ of the Hamiltonian $H$, given a certain quantum state $\mid \psi \rangle$, is obtained by multiplying both of the above equations by $\langle \psi \mid$ from the left

$\langle \psi \mid H \mid \psi \rangle = \langle \psi \mid E \mid \psi \rangle\\ \langle \psi \mid H \mid \psi \rangle = E \langle \psi \mid \psi \rangle\\ \langle \psi \mid H \mid \psi \rangle = E$

As an example of a single qubit, from any quantum state $\mid \psi \rangle$ and any Hamiltonian $H$, we have

$\langle \psi \mid H \mid \psi \rangle = \begin{bmatrix} \alpha^* & \beta^* \end{bmatrix} \begin{bmatrix} a&b\\ c&d \end{bmatrix} \begin{bmatrix} \alpha\\ \beta \end{bmatrix}$

## Find the expected value of the Hamiltonian Z

The expected value of the Hamiltonian at any state vector when $H = Z$ is

$\langle \psi \mid H \mid \psi \rangle = \begin{bmatrix} \alpha^* & \beta^* \end{bmatrix} \begin{bmatrix} 1&0\\ 0&-1 \end{bmatrix} \begin{bmatrix} \alpha\\ \beta \end{bmatrix} = |\alpha|^2 - |\beta|^2$

The expected value of the Hamiltonian $H$ when $H = X$ is

$\langle \psi \mid H \mid \psi \rangle = \begin{bmatrix} \alpha^* & \beta^* \end{bmatrix} \begin{bmatrix} 0&1\\ 1&0 \end{bmatrix} \begin{bmatrix} \alpha\\ \beta \end{bmatrix} = \alpha^* \beta + \alpha \beta^*$

but this value cannot be obtained by ordinary measurement, so the solution is obtained through a deformation of the Hamiltonian.

## Transformation of Hamiltonian

If the Hamiltonian $H$ is $Z$, we can calculate the expected value, but we cannot find it for X or Y. Therefore, we use a deformation of the Hamiltonian.

$X = HZH$
$\langle \psi \mid X \mid \psi \rangle \\ = \langle \psi \mid HZH \mid \psi \rangle\\ = \langle \psi' \mid Z \mid \psi' \rangle$

In the case of Y, this can be handled by transforming the state vector as in

$Y = RX(-\pi/2) Z RX(\pi/2)$
$\langle \psi \mid Y \mid \psi \rangle \\ = \langle \psi \mid RX(-\pi/2) Z RX(\pi/2) \mid \psi \rangle\\ = \langle \psi'' \mid Z \mid \psi'' \rangle$

These can be used to calculate the expected values by putting the above H and RX gates in the measurement just before the quantum circuit measurement.

## Linear Combining

In fact, the Hamiltonian $H$ is given by the Hermitian matrix, in the form of a unitary matrix sum, which can be decomposed as follows

$\langle \psi \mid aH_1 + bH_2 \mid \psi \rangle \\ = \langle \psi \mid aH_1 \mid \psi \rangle + \langle \psi \mid bH_2 \mid \psi \rangle \\ = a\langle \psi \mid H_1 \mid \psi \rangle + b\langle \psi \mid H_2 \mid \psi \rangle$

Let's see an example

$H = 1.2 X_0 Z_2 + 2.5 Z_0 X_1 Y_2 - 3.4 Z_2 X_1$

Expectation value is,

$\langle \psi \mid 1.2 X_0 Z_2 + 2.5 Z_0 X_1 Y_2 - 3.4 Z_2 X_1 \mid \psi \rangle\\ = 1.2\langle \psi \mid X_0 Z_2 \mid \psi \rangle + 2.5 \langle \psi \mid Z_0 X_1 Y_2\mid \psi \rangle - 3.4 \langle \psi \mid Z_2 X_1 \mid \psi \rangle$

can be calculated by doing the calculations individually and finding the sum, as in the example.

Quantum adiabatic calculation is a theory that allows time evolution while keeping the ground state by intermittently changing the state vector.

Let $H_{start}$ be the Hamiltonian of the initial state and $H_{final}$ be the Hamiltonian of the final problem to be solved, then from the time $t$ and the overall schedule $T$, we have

$H_{temp} = (1-\frac{t}{T})H_{start} + \frac{t}{T}H_{final}$

Then $T\rightarrow\infty$, the state vector changed in time evolution can follow the instantaneous Hamiltonian, take eigenstates and have eigenvalue.

$H_{temp}\mid \psi \rangle = E_{0temp}\mid \psi \rangle$

The time evolution is aquired by,

$\mid \psi_{t+1} \rangle = U \mid \psi_t \rangle = e^{-iHt} \mid \psi_t \rangle$

The challenge is where the ground state and the first excited state are closest, but we can keep the ground state by paying attention to the energy difference between $E_1(t)-E_0(t)$.

## QAOA circuit

QAOA is the time evolution calculation of the above quantum adiabatic calculation applied to a variational algorithm as ansatz.

|0> --H-- --RZZ--RZ-- --RX-- --RZZ--RZ-- --RX--
|                  |
|0> --H-- --RZZ--RZ-- --RX-- --RZZ--RZ-- --RX--


The overall structure can be divided into two main parts

1.Selecting a mixer determines the initial state
2. create a formulation in QUBO or Z

The second formulation is automatically time evolved.

The leftmost formulation creates the initial eigenstate|+>. The corresponding Hamiltonian X comes out in Rx in the form of a time evolution. Usually the mixer chooses X by default, and $H^ {\otimes N}$ is often used to create the corresponding|+> initial state.

Also, CX-Rz-CX (orRZZ) corresponds to the weight of the Hamiltonian in the problem setup, and the next Rz corresponds to the bias of the Hamiltonian.

blueqat's QaoaAnsatz will automatically construct this time evolution ansatz for you if you decide on the Hamiltonian and the number of step divisions. Since the library does the appropriate calculations for us, all we have to do is formulate the Hamiltonian and select the mixer. Let's solve a simple formulation.

## Ising Formulation

A physical model called the Ising model is used to solve combinatorial optimization problems. In the Ising model, the problem is usually formulated using up and down spins. The formulation uses Z as the operator, where Z has the expected value of +1 and -1.

$H = -Z_0 -Z_0*Z_1$

## QUBO

Next, we will check QUBO, which is derived from the Hamiltonian Z formulation above and formulated in terms of 0s and 1s. QUBO is a rewriting of the Z formulation, but blueqat has a tool that automatically converts it.

The formulation is

$H = 2q_1-4q_0q_1$
.css-wy3l36{position:absolute;top:0px;right:0px;}.css-moltat{display:-webkit-inline-box;display:-webkit-inline-flex;display:-ms-inline-flexbox;display:inline-flex;-webkit-appearance:none;-moz-appearance:none;-ms-appearance:none;appearance:none;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-ms-flex-pack:center;-webkit-justify-content:center;justify-content:center;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;position:relative;white-space:nowrap;vertical-align:middle;outline:2px solid transparent;outline-offset:2px;line-height:1.2;border-radius:var(--chakra-radii-md);font-weight:var(--chakra-fontWeights-semibold);transition-property:var(--chakra-transition-property-common);transition-duration:var(--chakra-transition-duration-normal);height:var(--chakra-sizes-8);min-width:var(--chakra-sizes-8);font-size:var(--chakra-fontSizes-sm);-webkit-padding-start:var(--chakra-space-3);padding-inline-start:var(--chakra-space-3);-webkit-padding-end:var(--chakra-space-3);padding-inline-end:var(--chakra-space-3);background:var(--chakra-colors-teal-500);color:var(--chakra-colors-white);}.css-moltat:focus-visible,.css-moltat[data-focus-visible]{box-shadow:var(--chakra-shadows-outline);}.css-moltat:disabled,.css-moltat[disabled],.css-moltat[aria-disabled=true],.css-moltat[data-disabled]{opacity:0.4;cursor:not-allowed;box-shadow:var(--chakra-shadows-none);}.css-moltat:hover,.css-moltat[data-hover]{background:var(--chakra-colors-teal-600);}.css-moltat:hover:disabled,.css-moltat[data-hover]:disabled,.css-moltat:hover[disabled],.css-moltat[data-hover][disabled],.css-moltat:hover[aria-disabled=true],.css-moltat[data-hover][aria-disabled=true],.css-moltat:hover[data-disabled],.css-moltat[data-hover][data-disabled]{background:var(--chakra-colors-teal-500);}.css-moltat:active,.css-moltat[data-active]{background:var(--chakra-colors-teal-700);}.css-1ibzxu9{display:inline-block;font-family:var(--chakra-fonts-mono);font-size:var(--chakra-fontSizes-sm);-webkit-padding-start:0.2em;padding-inline-start:0.2em;-webkit-padding-end:0.2em;padding-inline-end:0.2em;border-radius:var(--chakra-radii-sm);--badge-bg:colors.grey.100;--badge-color:colors.grey.800;background:var(--badge-bg);color:#fff;}.chakra-ui-dark .css-1ibzxu9:not([data-theme]),[data-theme=dark] .css-1ibzxu9:not([data-theme]),.css-1ibzxu9[data-theme=dark]{--badge-bg:rgba(0, 0, 0, 0.16);--badge-color:colors.grey.200;}from blueqat import Circuit
from blueqat.utils import qaoa
from blueqat.pauli import qubo_bit as q
from blueqat.pauli import X,Y,Z,I

hamiltonian = 2*q(1)-4*q(0)*q(1)
step = 1

result = qaoa(hamiltonian, step)
result.circuit.run(shots=100)
.css-191h9yu{display:inline-block;font-family:var(--chakra-fonts-mono);font-size:var(--chakra-fontSizes-sm);-webkit-padding-start:0.2em;padding-inline-start:0.2em;-webkit-padding-end:0.2em;padding-inline-end:0.2em;border-radius:var(--chakra-radii-sm);--badge-bg:var(--chakra-colors-gray-500);--badge-color:var(--chakra-colors-white);background:var(--badge-bg);color:var(--badge-color);width:var(--chakra-sizes-full);white-space:pre-wrap;}.chakra-ui-dark .css-191h9yu:not([data-theme]),[data-theme=dark] .css-191h9yu:not([data-theme]),.css-191h9yu[data-theme=dark]{--badge-bg:rgba(113, 128, 150, 0.6);--badge-color:var(--chakra-colors-whiteAlpha-800);}Counter({'11': 47, '00': 36, '10': 17})