common.title

Overview
Service overview
Terms of service

Privacy policy

Contact

Sign in
Sign up
common.title

maxcut problem on QAOA with IonQ device

Yuichiro Minato

2021/07/06 00:00

#IonQ

1

In this article, we will review QAOA. We will solve a combinatorial optimization problem with quantum gates. First, let's check the calculation with blueqat cloud.
https://blueqat.com/gyu-don/87fcb9ce-f5c2-4f9e-8697-191c8781d70b

from bqcloud import load_api from bqcloud import Device from blueqat import Circuit import math #import api key api = load_api()
#let's make a simple entanglement using rxx gate for trial qc = Circuit().rxx(math.pi/2)[0,1]
#simulator qc.m[:].run(shots=100)
Counter({'00': 46, '11': 54})
#post task to IonQ on the cloud qc = Circuit().rxx(math.pi/2)[0,1] task = api.execute(qc, Device.IonQDevice, 10)
#task queued print(task.status())
Status.QUEUED
#get the result result = task.wait(timeout=3600) if result: print(result.shots()) else: print("timeout")
Counter({'00': 5, '11': 5})

The calculation results came out successfully. Now, let's try QAOA on IonQ.

Let's start with a simple equation and consider the three-vertex maxcut problem.

Let's consider three vertices and set the edge weights all to 1.

For the formulation, we will consider the Ising model. We will create an equation called the Hamiltonian. Assign qubits to the vertices, each of which takes the value 1 or -1.

The formulation is,

Hc=Z0Z1+Z1Z2+Z2Z0H_c = Z_0Z_1 + Z_1Z_2 + Z_2Z_0

The coefficients in front of Z correspond to the weights of the edges, respectively.

Next, we need to prepare one more formulation. That is a mixer to search for a solution. We usually use X as the most simple formulation.

Hinit=X0+X1+X2H_{init} = X_0+X_1+X_2

Another thing that needs to be prepared in the above formulation is the superposition state, which is the eigenstate of HinitH_{init}.

The quantum state is then time-evolved. The equation for time evolution is based on the operation of gradually replacing the Hamiltonian with respect to time t. The time evolution is

ψt+1=Uψt\mid \psi_{t+1} \rangle = U \mid \psi_t \rangle

The Hamiltonian to be applied is the process of swapping the above two Hamiltonians.

Ht=sHinit+(1s)HcH_t = s*H_{init} + (1-s)*H_c

We use time evolution operator eiHte^{-iHt}

Finally the quantum circuit to solve the qaoa in 1step p=1 is

|0> --H--RZZ(beta)-------------RZZ(beta)--RX(gamma)--
         |                     |   
|0> --H--RZZ(beta)--RZZ(beta)--|----------RX(gamma)--
                    |          |   
|0> --H-------------RZZ(beta)--RZZ(beta)--RX(gamma)--

To optimize beta and gamma, we can get solution for qaoa. blueqat sdk has a function to create the qaoa circuit. We call this circuit Ansatz.

from blueqat.pauli import Z from blueqat import vqe hamiltonian = Z[0]*Z[1] + Z[1]*Z[2] + Z[2]*Z[0] result = vqe.Vqe(vqe.QaoaAnsatz(hamiltonian, 1)).run() print(result.most_common(12))
(((1, 0, 0), 0.162033015432909), ((1, 1, 0), 0.162033015432909), ((0, 0, 1), 0.162033015432909), ((0, 1, 1), 0.162033015432909), ((0, 1, 0), 0.16203301543290893), ((1, 0, 1), 0.16203301543290893), ((0, 0, 0), 0.013900953701272978), ((1, 1, 1), 0.013900953701272978))

It has a function to check the quantum circuit

result.circuit
Circuit(3).h[:].cx[0, 1].rz(-25.930489083659825)[1].cx[0, 1].cx[0, 2].rz(-25.930489083659825)[2].cx[0, 2].cx[1, 2].rz(-25.930489083659825)[2].cx[1, 2].rx(0.4578213663591716)[:]

rzz is usually rewrited as combination of cx,rz,cx.

beta = -25.930489083659825 gamma = 0.4578213663591716 Circuit(3).h[:].cx[0, 1].rz(beta)[1].cx[0, 1].cx[0, 2].rz(beta)[2].cx[0, 2].cx[1, 2].rz(beta)[2].cx[1, 2].rx(gamma)[:].run()
array([-0.02214869+0.11580323j,  0.27513225-0.29382863j,

        0.27513225-0.29382863j,  0.27513225-0.29382863j,

        0.27513225-0.29382863j,  0.27513225-0.29382863j,

        0.27513225-0.29382863j, -0.02214869+0.11580323j])

If we check the rzz form, we have the same state vector.

Circuit(3).h[:].rzz(beta)[0,1].rzz(beta)[0,2].rzz(beta)[1,2].rx(gamma)[:].run()
array([-0.02214869+0.11580323j,  0.27513225-0.29382863j,

        0.27513225-0.29382863j,  0.27513225-0.29382863j,

        0.27513225-0.29382863j,  0.27513225-0.29382863j,

        0.27513225-0.29382863j, -0.02214869+0.11580323j])

Basically IonQ has rzz/rxx basic gate set for trapped ion. For qaoa rzz is much more suitable and we can write the quantum cirucit shorter with these gate set. Let's apply for IonQ device.

task = api.execute(Circuit(3).h[:].rzz(beta)[0,1].rzz(beta)[0,2].rzz(beta)[1,2].rx(gamma)[:], Device.IonQDevice, 100)
#get the result result = task.wait(timeout=3600) if result: print(result.shots()) else: print("timeout")
Counter({'110': 19, '101': 19, '100': 18, '001': 16, '011': 13, '010': 12, '111': 2, '000': 1})

Now we have results from IonQ device precisely. It is quite precise than expected.

© 2024, blueqat Inc. All rights reserved