common.title
Cloud support

TYTAN CLOUD
QUANTUM GAMING

Nobisuke

Dekisugi

RAG


autoQAOA
RAG for dev
DEEPSCORE
Translation

Overview
Service overview
Terms of service

Privacy policy

Contact
Research

Sign in
Sign up
common.title

QAOA using the state vector specification feature of blueqat 0.4.1

Yuichiro Minato

2021/03/14 14:42

#quantum computer #qaoa #quantum login gate #state vector

Hello, When solving combinatorial optimization problems on a quantum computer, it is very difficult to create quantum entanglement. In this article, I will try to do an optimization calculation using the state vector specification function of blueqat0.4.1, which is a simulator-only function but allows you to specify the state vector.

Quantum adiabatic time evolution

Combinatorial optimization problems can be solved by using a method called QAOA. The application of quantum adiabatic time evolution to combinatorial optimization involves solving an eigenvalue problem, which is achieved by swapping the eigenstates of two Hamiltonians.

Hψ=E0ψH\lvert \psi \rangle = E_0 \lvert \psi \rangle

The replacement of these Hamiltonians can be done using the time evolution operator. blueqat originally comes with a module to perform QAOA.

Example

Solve for the Hamiltonian as shown below.

H=2q14q0q1H = 2q_1-4q_0q_1

To solve this in QAOA is simple.

!pip install -U blueqat
Requirement already up-to-date: blueqat in /opt/conda/lib/python3.8/site-packages (0.4.1)

Requirement already satisfied, skipping upgrade: numpy~=1.12 in /opt/conda/lib/python3.8/site-packages (from blueqat) (1.19.1)

Requirement already satisfied, skipping upgrade: scipy>=1.1.0 in /opt/conda/lib/python3.8/site-packages (from blueqat) (1.4.1)
from blueqat import vqe from blueqat.pauli import qubo_bit as q h = 2*q(1)-4*q(0)*q(1) step = 2 result = vqe.Vqe(vqe.QaoaAnsatz(h, step)).run() print(result.most_common(12))
(((1, 1), 0.9260556562914583), ((0, 0), 0.0632808374136653), ((0, 1), 0.010178834222034226), ((1, 0), 0.0004846720728419975))

This solved it.

The mixer

Let's change the search method to mixer, and prepare a mixer and its corresponding initial state.

from blueqat import Circuit from blueqat.pauli import X, Y, Z, I #mixer and inital state mixer = 0.5*X[0]*X[1] + 0.5*Y[0]*Y[1] init = Circuit().h[0].cx[0,1].x[0] h = 2*q(1)-4*q(0)*q(1) step=2 result = vqe.Vqe(vqe.QaoaAnsatz(h, step, init, mixer)).run() print(result.most_common(12))
(((1, 0), 0.546043166990948), ((0, 1), 0.45395683300904965), ((0, 0), 1.1226065089900911e-31), ((1, 1), 2.946672814912471e-32))

The initial state shown above was an entangled state of 01 and 10. It becomes more difficult when the number of qubits increases to three. When the number of qubits increases to four, it becomes even more difficult. In order to easily handle this, it is necessary to prepare the initial state in a simple way, but it is quite difficult to write this as a combination of gates. The above entanglement circuit is a

Circuit().h[0].cx[0,1].x[0]
Circuit(2).h[0].cx[0, 1].x[0]

the QAOA circuit was

result.circuit
Circuit(2).h[0].cx[0, 1].x[0].cx[0, 1].rz(15.747393451090012)[1].cx[0, 1].rz(-15.747393451090012)[0].h[0].h[1].cx[0, 1].rz(-3.4070734561763043)[1].cx[0, 1].h[0].h[1].rx(-1.5707963267948966)[0].rx(-1.5707963267948966)[1].cx[0, 1].rz(-3.4070734561763043)[1].cx[0, 1].rx(1.5707963267948966)[0].rx(1.5707963267948966)[1].cx[0, 1].rz(15.558611377279837)[1].cx[0, 1].rz(-15.558611377279837)[0].h[0].h[1].cx[0, 1].rz(-3.5098999259873422)[1].cx[0, 1].h[0].h[1].rx(-1.5707963267948966)[0].rx(-1.5707963267948966)[1].cx[0, 1].rz(-3.5098999259873422)[1].cx[0, 1].rx(1.5707963267948966)[0].rx(1.5707963267948966)[1]

I will rewrite this with the new features.

import numpy as np # prepare the initial state vector vec = np.array([0, 1, 1, 0]) / np.sqrt(2) # True: It's normalized. np.allclose(np.vdot(vec, vec), 1)
True

I made sure it was normalized and prepared a tangle of 01 and 10 in the state vector. First, let's run this as is

Circuit(2).m[:].run(shots=100, initial=np.array([0, 1, 1, 0])/np.sqrt(2))
Counter({'10': 56, '01': 44})

The entanglement circuit was executed properly. Looking at the state vector, we can see that

Circuit(2).run(initial=np.array([0, 1, 1, 0])/np.sqrt(2))
array([0.        +0.j, 0.70710678+0.j, 0.70710678+0.j, 0.        +0.j])

Then, run the ansatz of the QAOA circuit mentioned earlier. If we connect the circuit with the initial state vector as input to the circuit with the initial entanglement circuit removed (there is a short rewrite to Rzz and Rxx in the middle), we get

c = Circuit(2).rzz(28.48504526568177)[0,1].rz(-28.48504526568177)[0].rxx(-13.395826737916892)[0,1].rx(-1.5707963267948966)[0].rx(-1.5707963267948966)[1].rzz(-13.395826737916892)[0,1].rx(1.5707963267948966)[0].rx(1.5707963267948966)[1].rzz(29.964021341813513)[0,1].rz(-29.964021341813513)[0].rxx(-9.00039424636803)[0,1].rx(-1.5707963267948966)[0].rx(-1.5707963267948966)[1].rzz(-9.00039424636803)[0,1].rx(1.5707963267948966)[0].rx(1.5707963267948966)[1].m[:] c.run(shots=1000, initial=vec)
Counter({'10': 933, '01': 67})

This is how it turned out. This is because we are solving an optimization problem in time evolution from 01 and 10, which should come out 50-50, so the answer 10 has priority and samples more. In this way, we were able to do QAOA with a state vector start. This will allow us to efficiently test simulations on larger problems. I encourage you to give it a try.

© 2024, blueqat Inc. All rights reserved