def __init__(self, graph): self.graph = graph self.h, self.J = self.graph.get_data() solver = local_connection.get_solver('c4-sw_optimize') self.blackbox_solver = BlackBoxSolver(solver) self.blackbox_parameter = 1 self.cluster_parameter = 2
def __init__(self, filename): self.clauses = [] self.process_file(filename) solver = local_connection.get_solver('c4-sw_optimize') self.blackbox_solver = BlackBoxSolver(solver) self.blackbox_parameter = 10 self.gamma = 99999
def solve(self): solver = local_connection.get_solver('c4-sw_optimize') blackbox_parameter = 10 blackbox_solver = BlackBoxSolver(solver) if debug: print 'contacting super black box...' blackbox_answer = blackbox_solver.solve(self, 2 * SIZE, cluster_num = 10, \ min_iter_inner = blackbox_parameter, max_iter_outer= blackbox_parameter, \ unchanged_threshold=blackbox_parameter, max_unchanged_objective_outer=blackbox_parameter, \ max_unchanged_objective_inner = blackbox_parameter, \ unchanged_best_threshold = blackbox_parameter, verbose=0) blackbox_answer_bin = array([(item + 1) / 2 for item in blackbox_answer]) a, b = (binaryToInt(blackbox_answer[0:SIZE]), binaryToInt(blackbox_answer[SIZE:])) if debug: print 'The best bit string we found was:', blackbox_answer_bin print 'the factors are ', a, ' and ', b return (a, b)
from eternity2_functions import * from dwave_sapi import local_connection, BlackBoxSolver ##------------------------------------------------------------## ##--------------MAIN ROUTINE----------------------------------## ##------------------------------------------------------------## solver = local_connection.get_solver("c4-sw_sample") blackbox_parameter = 30 # This parameter sets the strength vs. speed of BlackBox (higher = more powerful/slower). # How do we construct our bitstring to send to BlackBox? # Well, the position along the bitstring could be the position on the board, # and the numbers contained within can specify which piece goes there and its rotation # For n=16, 265 positions can be described by 8 bits # For n=4, 16 positions can be described by 4 bits # Additionally, each piece can have a rotation (2 bit) # For the full 16x16 puzzle there are 10 bits per board position = 2560 total optimization variables # For a 4x4 puzzle there are 6 bits per board position = 96 total optimization variables n = 4 num_vars = 96 # A test bitstring for n=4, no rotation. Piece index (4 bits) then rotation (2 bits) #test_bitstring = [0,0,0,0, 0,0, 0,0,0,1, 0,0, 0,0,1,0, 0,0, 0,0,1,1, 0,0, # 0,1,0,0, 0,0, 0,1,0,1, 0,0, 0,1,1,0, 0,0, 0,1,1,1, 0,0, # 1,0,0,0, 0,0, 1,0,0,1, 0,0, 1,0,1,0, 0,0, 1,0,1,1, 0,0, # 1,1,0,0, 0,0, 1,1,0,1, 0,0, 1,1,1,0, 0,0, 1,1,1,1, 0,0] test_bitstring = [1,0,0,0, 0,0, 1,0,0,0, 0,0, 1,0,0,0, 0,0, 1,0,0,0, 0,0,\ 1,0,0,0, 0,0, 1,0,0,0, 0,0, 1,0,0,0, 0,0, 1,0,0,0, 0,0,\ 1,0,0,0, 0,0, 1,0,0,0, 0,0, 1,0,0,0, 0,0, 1,0,0,0, 0,0,\
import struct return ''.join( bin(ord(c)).replace('0b', '').rjust(8, '0') for c in struct.pack('!f', num)) def convert_answer(self, bb_answer): bin = [(x + 1) / 2 for x in bb_answer] theta0 = self.as_float32(bin[:32]) theta1 = self.as_float32(bin[32:64]) theta2 = self.as_float32(bin[64:96]) theta3 = self.as_float32(bin[96:128]) # theta4 = self.as_float32(bin[128:]) return [theta0, theta1, theta2, theta3] solver = local_connection.get_solver('c4-sw_optimize') blackbox_parameter = 10 obj = QuantumLR("data.txt") blackbox_solver = BlackBoxSolver(solver) print 'contacting super black box...' blackbox_answer = blackbox_solver.solve(obj, obj.stateLen) print blackbox_answer theta = obj.convert_answer(blackbox_answer) print theta print obj.totalCost(theta) r = arange(0, 100, 1)
def __init__(self): solver = local_connection.get_solver('c4-sw_optimize') self.blackbox_solver = BlackBoxSolver(solver) self.evaluator = NANDEvaluator() self.blackbox_parameter = 10
from eternity2_functions import * from dwave_sapi import local_connection, BlackBoxSolver ##------------------------------------------------------------## ##--------------MAIN ROUTINE----------------------------------## ##------------------------------------------------------------## solver = local_connection.get_solver("c4-sw_sample") blackbox_parameter = 30 # This parameter sets the strength vs. speed of BlackBox (higher = more powerful/slower). # How do we construct our bitstring to send to BlackBox? # Well, the position along the bitstring could be the position on the board, # and the numbers contained within can specify which piece goes there and its rotation # For n=16, 265 positions can be described by 8 bits # For n=4, 16 positions can be described by 4 bits # Additionally, each piece can have a rotation (2 bit) # For the full 16x16 puzzle there are 10 bits per board position = 2560 total optimization variables # For a 4x4 puzzle there are 6 bits per board position = 96 total optimization variables n = 4 num_vars = 96 # A test bitstring for n=4, no rotation. Piece index (4 bits) then rotation (2 bits) #test_bitstring = [0,0,0,0, 0,0, 0,0,0,1, 0,0, 0,0,1,0, 0,0, 0,0,1,1, 0,0, # 0,1,0,0, 0,0, 0,1,0,1, 0,0, 0,1,1,0, 0,0, 0,1,1,1, 0,0, # 1,0,0,0, 0,0, 1,0,0,1, 0,0, 1,0,1,0, 0,0, 1,0,1,1, 0,0, # 1,1,0,0, 0,0, 1,1,0,1, 0,0, 1,1,1,0, 0,0, 1,1,1,1, 0,0] test_bitstring = [1,0,0,0, 0,0, 1,0,0,0, 0,0, 1,0,0,0, 0,0, 1,0,0,0, 0,0,\ 1,0,0,0, 0,0, 1,0,0,0, 0,0, 1,0,0,0, 0,0, 1,0,0,0, 0,0,\ 1,0,0,0, 0,0, 1,0,0,0, 0,0, 1,0,0,0, 0,0, 1,0,0,0, 0,0,\
__author__ = 'Daniel' # Import D-Wave's Python API from dwave_sapi import local_connection solver = local_connection.get_solver('c4-sw_sample') #define the problem h = [0]*128 J = dict() h[48] = -0.1 h[49] = -0.1 h[53] = -0.2 J[(48,53)] = 0.2 J[(48,52)] = 0.1 J[(49,52)] = -1 J[(49,53)] = 0.2 #send the problem to hardware answer = solver.solve_ising(h,J,num_reads = 100)['solutions'][0] print '48 = ', answer[48] print '49 = ', answer[49] print '52 = ', answer[52] print '53 = ', answer[53]