예제 #1
0
def output(searcher) :
    summary = sqaod.make_summary(searcher)
    print('E {}'.format(summary.E))
    print('Number of solutions : {}'.format(len(summary.xlist)))
    nToShow = min(len(summary.xlist), 4)
    for idx in range(nToShow) :
        print(summary.xlist[idx])
예제 #2
0
def solver(arr):
	W = arr
	output = []
	sol = sq.cpu
	if sq.is_cuda_available() :
	    import sqaod.cuda
	    sol = sqaod.cuda

	ann = sol.dense_graph_annealer()
	ann.seed(1)
	ann.set_qubo(W, sq.minimize)
	ann.set_preferences(n_trotters = W.shape[0])

	h, J, c = ann.get_hamiltonian()
	
	output.append(h); output.append(J); output.append(c)
	
	ann.prepare()
	ann.randomize_spin()

	Ginit = 5.
	Gfin = 0.01
	beta = 1. / 0.02
	tau = 0.99

	G = Ginit
	while Gfin <= G :
	    ann.anneal_one_step(G, beta)
	    G *= tau
	    
	E = ann.get_E()
	q = ann.get_q()
	x = ann.get_x()

	summary = sq.make_summary(ann)

	out_summary = []
	nToShow = min(len(summary.xlist), 4)
	for idx in range(nToShow) :
		out_summary.append(summary.xlist[idx])

	
	output.append(out_summary)
	return output, out_summary
예제 #3
0
def output(searcher):
    summary = sqaod.make_summary(searcher)
    print('E {}'.format(summary.E))
    print('Number of solutions : {}'.format(len(summary.xlist)))
    for x in summary.xlist:
        print(x)
예제 #4
0
# 6. showing preferences (optional)
# preferences of solvers are obtained by calling get_preference().
# preferences is always repeseted as python dictionay object.
print(search.get_preferences())

# 7. do brute-force search
# during search, x vectors that has minimum E values at the point of scan are saved.
search.search()

# 8. some methods to get results
# - Get list of E for every solution.
E = search.get_E()
# - Get searchealed x. get_x() returns x matrix as (n_trotters, N)
x = search.get_x()


# 9. creating summary object
summary = sq.make_summary(search)

# 10. get the best engergy(for min E for minimizing problem, and max E for maxmizing problem)
print('E {}'.format(summary.E))

# 11. show the number of solutions that has the same energy of the best E.
print('Number of solutions : {}'.format(len(summary.xlist)))

# 12. show solutions. Max number of x is limited to 4.
nToShow = min(len(summary.xlist), 4)
for idx in range(nToShow) :
    print(summary.xlist[idx])
예제 #5
0
# annealing loop
G = Ginit
while Gfin <= G:
    # 11. call anneal_one_step to try flipping spins for (n_bits x n_trotters) times.
    ann.anneal_one_step(G, beta)
    G *= tau
    # 12. you may call get_E() to get a current E value.
    # ann.get_E()

# 13. some methods to get results
# - Get list of E for every trogger.
E = ann.get_E()
# - Get annealed q. get_q() returns q matrix as (n_trotters, N)
qlist = ann.get_q()
# - Get annealed x. get_x() returns x matrix as (n_trotters, N)
xlist = ann.get_x()

# 14. creating summary object
summary = sq.make_summary(ann)

# 15. get the best engergy(for min E for minimizing problem, and max E for maxmizing problem)
print('E {}'.format(summary.E))

# 16. show the number of solutions that has the same energy of the best E.
print('Number of solutions : {}'.format(len(summary.xlist)))

# 17. show solutions. Max number of x is limited to 4.
nToShow = min(len(summary.xlist), 4)
for idx in range(nToShow):
    print(summary.xlist[idx])