# Preparing 2-opt swap on IonQ quantum computer with entanglement and swap operation.

Here we think about the way to implement 2-opt method on quantum computer using quantum circuit

## 2-opt method

Evalutating the cost function swapping two cities. To use this method on quantum computer, we need some techniques. Thinking about the route we round ABCD cities, we need N*Nqubits for N cities. To realize 2-opt method on ising model we have to swap 4qubits once together. The quantum circuit would be,

|0> --X--RXX--RYY--
|    |
|0> -----RXX--RYY--

|0> -----RXX--RYY--
|    |
|0> --X--RXX--RYY--

By making 1 using X gate and then swap each qubits we can make 2-opt swap.

from blueqat import Circuit
import math

Circuit(4).x[0,3].m[:].run(shots=100)

First we made 1001 state. Then let's try to swap.

Circuit(4).x[0,3].rxx(math.pi/2)[0,1].rxx(math.pi/2)[2,3].ryy(math.pi/2)[0,1].ryy(math.pi/2)[2,3].m[:].run(shots=100)

Now we could make a 2-opt swap 1001 to 0110. Let's try on IonQ Device on blueqat cloud

from bqcloud import load_api
from bqcloud import Device

#import API key.

task = api.execute(Circuit(4).x[0,3].rxx(math.pi/2)[0,1].rxx(math.pi/2)[2,3].ryy(math.pi/2)[0,1].ryy(math.pi/2)[2,3], Device.IonQDevice, 100)
print(task.status())
# get the result
if result:
print(result.shots())
else:
print("timeout")

We could realize on IonQ Device.

From now we try to implement a quantum circuit to realize hard constraint using entanglement. When we think about 4qubits, the possible states are,

0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111

But, if we only think about the 2-opt method, what we need is just these two states,

0110
1001

To realize these states once on the quantum circuit, we can use entanglement. By realizing this circuit we can rezlize 2-opt swap operation on just one circuit.

The circuit to realize the entanglement is,

Circuit(4).x[0,3].rxx(math.pi/2)[0,1].cx[1,2].cx[2,3].m[:].run(shots=100)
task2 = api.execute(Circuit(4).x[0,3].rxx(math.pi/2)[0,1].cx[1,2].cx[2,3], Device.IonQDevice, 100)
#realize it
if result2:
print(result2.shots())
else:
print("timeout")

Then let's flip these states at once.

Circuit(4).x[0,3].rxx(math.pi/2)[0,1].cx[1,2].cx[2,3].rxx(math.pi/2)[0,1].rxx(math.pi/2)[2,3].ryy(math.pi/2)[0,1].ryy(math.pi/2)[2,3].m[:].run(shots=100)

Now we applied flip operation and get the same state, means we have flipped two state at once.

task3 = api.execute(Circuit(4).x[0,3].rxx(math.pi/2)[0,1].cx[1,2].cx[2,3].rxx(math.pi/2)[0,1].rxx(math.pi/2)[2,3].ryy(math.pi/2)[0,1].ryy(math.pi/2)[2,3], Device.IonQDevice, 100)
result3 = task3.wait(timeout=3600)
if result3:
print(result3.shots())
else:
print("timeout")

Here we also succeded to make flip on IonQ device. To apply this 2-opt method to combinatorial optimizaiton on quantum computer would be little complicated. I will follow on articles later, one by one. Thank you for reading. ##### Yuichiro Minatoblueqat CEO/CTO 2015年総務省異能vation最終採択 2017年内閣府ImPACTプロジェクトPM補佐 2019年文科省さきがけ量子情報処理領域アドバイザー 