@yuichirominato 2019.02.18更新 91views

## [logic gate] Classical AND gate on QAOA

### Introduction

I just think about to realize classical AND gate on QAOA optimization problem.

### About AND gate

AND gate is a logical gate to have two input and one output. Only when 2 inputs are 1 we have 1 as output.

0 0 >>> 0
0 1 >>> 0
1 0 >>> 0
1 1 >>> 1

### Cost function

Now we have 3 qubits and this is the general cost function.

E=aA+bB+cC+dAB+eBC+fCA+gABC

AB is input qubit and C is output. We just satisfy this logical table. x,y,z,k are natural number bigger than 0.

A B C E（cost function）
0 0 0 0
0 1 0 0
1 0 0 0
1 1 1 0
-------
0 0 1 x
0 1 1 y
1 1 0 z
1 0 1 k

Let’s substitute these one by one

#[A,B,C] = [0,0,0]
E = 0

#[A,B,C] = [0,1,0]
E = b = 0

#[A,B,C] = [1,0,0]
E = a = 0

#[A,B,C] = [1,1,1]
E = c+d+e+f+g = 0

These cost function above have to have value 0 as answer.

#[A,B,C] = [0,0,1]
E = c = x > 0

#[A,B,C] = [0,1,1]
E = c + e = y >0

#[A,B,C] = [1,1,0]
E = d = z >0

#[A,B,C] = [1,0,1]
E = c + f = k >0

These are cost function should be natural number bigger than 0.

c=1,e=1,d=1,f=1,g=-4

We can find these coefficient.

E = C + AB + BC + CA - 4ABC

This is the cost function of classical AND gate.

### Solve on QAOA

Now we have 3-body interaction between qubits, so QAOA is useful for this.

from blueqat import vqe
from blueqat.pauli import qubo_bit as q

hami = q(2)+q(0)*q(1)+q(1)*q(2)+q(2)*q(0)-4*q(0)*q(1)*q(2)

result = vqe.Vqe(vqe.QaoaAnsatz(hami,4)).run()
print(result.most_common(12))

#=>
(((0, 0, 0), 0.519727769221865), ((1, 1, 1), 0.23719281758252192), ((0, 1, 0), 0.11967601213486054), ((1, 0, 0), 0.1196760121348605), ((0, 0, 1), 0.0027571549552323237), ((1, 1, 0), 0.0006430030415655319), ((1, 0, 1), 0.00016361546454752971), ((0, 1, 1), 0.00016361546454752736))

We have 000, 111, 010, 100 for enough amplitude.

### Example

Just try one example as A=1,B=0 and we want to get output C

This time we just add -1*q(0)+q(1) to the cost function that fix A and B to 1 and 0.

hami1 = -1*q(0)+q(1)
hami = q(2)+q(0)*q(1)+q(1)*q(2)+q(2)*q(0)-4*q(0)*q(1)*q(2)

result = vqe.Vqe(vqe.QaoaAnsatz(hami1+hami,4)).run()
print(result.most_common(12))

#=>
(((1, 0, 0), 0.9193795158893359), ((1, 1, 1), 0.03156160130462393), ((0, 0, 0), 0.02058110630291014), ((1, 1, 0), 0.006777171223222024), ((1, 0, 1), 0.006777171223222019), ((0, 1, 0), 0.006257773121487779), ((0, 0, 1), 0.006257773121487756), ((0, 1, 1), 0.0024078878137108292))

It is solved and we get C=0 for the answer.