common.title

Generate Image


Overview
Service overview
Terms of service

Privacy policy

Contact

Sign in
Sign up
common.title

Solving Number Partitioning Problem on QAOA

Yuichiro Minato

2022/01/30 15:53

#qaoa

Number Partitioning Problem

Number Partitioning Problem is a problem to make two groups that sum of the each groups are the same.

Reference

Ising formulations of many NP problems
Andrew Lucas
https://arxiv.org/abs/1302.5843

Ising hamiltonian

iith of N natural number we put as nin_i. And if this number belongs to any groups we show this using ZiZ_i. If nin_i belongs to group A, it is Zi=1Z_i=1. And if it belongs to group B it is Zi=0Z_i=0.

And then we create a hamiltonian of HH that take the minimum value when the sum of each groups are the same.

H=(niZi)2H = (\sum n_i*Z_i)^2

It will be H=0H=0 when the sum of two groups are the same and takes H>0H>0 if these are different.

Example

Let's try solve a simple example. Now we have a list of natural number

[3,6,5,6,5,2,6,8,5,8]

and we make two groups. The hamiltonian is very simple

H=3Z(0)+6Z(1)+5Z(2)+6Z(3)+5Z(4)+2Z(5)+6Z(6)+8Z(7)+5Z(8)+8Z(9)H = 3*Z(0)+6*Z(1)+5*Z(2)+6*Z(3)+5*Z(4)+2*Z(5)+6*Z(6)+8*Z(7)+5*Z(8)+8*Z(9)
#sum 38 num = [3,6,5,6,5,2,6,5] from blueqat import vqe from blueqat.pauli import Z hamiltonian = (num[0]*Z(0)+num[1]*Z(1)+num[2]*Z(2)+num[3]*Z(3)+num[4]*Z(4)+num[5]*Z(5)+num[6]*Z(6)+num[7]*Z(7))**2 step = 2 result = vqe.Vqe(vqe.QaoaAnsatz(hamiltonian.simplify(), step)).run() b = sum([x*y for (x,y) in zip(num, list(result.most_common(1)[0][0]))]) #answer 19 print(b) result.most_common(12)
19
(((0, 1, 1, 1, 0, 1, 0, 0), 0.008320427578059642),

 ((0, 1, 0, 0, 1, 1, 1, 0), 0.008320427578059642),

 ((1, 0, 1, 1, 0, 0, 0, 1), 0.008320427578059642),

 ((1, 0, 0, 0, 1, 0, 1, 1), 0.008320427578059642),

 ((1, 0, 1, 1, 1, 0, 0, 0), 0.008320427578059638),

 ((1, 0, 1, 0, 1, 0, 1, 0), 0.008320427578059638),

 ((0, 1, 0, 1, 0, 1, 0, 1), 0.008320427578059638),

 ((0, 1, 0, 0, 0, 1, 1, 1), 0.008320427578059638),

 ((1, 1, 1, 0, 1, 0, 0, 0), 0.008320427578059637),

 ((0, 0, 0, 1, 0, 1, 1, 1), 0.008320427578059637),

 ((0, 1, 0, 1, 1, 1, 0, 0), 0.008320427578059635),

 ((1, 0, 1, 0, 0, 0, 1, 1), 0.008320427578059635))

Finally we got two groups the sum is each 19.

© 2024, blueqat Inc. All rights reserved