**prefs):
    return DenseGraphBFSearcher(W, optimize, dtype, prefs)


if __name__ == '__main__':

    np.random.seed(0)
    dtype = np.float32
    N = 8
    W = np.array([[-32, 4, 4, 4, 4, 4, 4, 4], [4, -32, 4, 4, 4, 4, 4, 4],
                  [4, 4, -32, 4, 4, 4, 4, 4], [4, 4, 4, -32, 4, 4, 4, 4],
                  [4, 4, 4, 4, -32, 4, 4, 4], [4, 4, 4, 4, 4, -32, 4, 4],
                  [4, 4, 4, 4, 4, 4, -32, 4], [4, 4, 4, 4, 4, 4, 4, -32]])

    N = 16
    W = sqaod.generate_random_symmetric_W(N, -0.5, 0.5, dtype)
    bf = dense_graph_bf_searcher(W, sqaod.minimize, dtype)
    bf.set_preferences(tile_size=256)

    import time

    start = time.time()
    bf.search()
    end = time.time()
    print(end - start)

    x = bf.get_x()
    E = bf.get_E()
    print(E)
    print(x)
    print(bf.get_preferences())
Beispiel #2
0
def dense_graph_random(N, dtype):
    return sq.generate_random_symmetric_W(N, dtype=dtype)
Beispiel #3
0
if __name__ == '__main__':
    import sqaod
    import sqaod.py.formulas as py_formulas
    dtype = np.float64

    np.random.seed(0)

    try:
        W = np.ones((4, 4), np.int32)
        dense_graph_calculate_hamiltonian(W, np.int32)
    except Exception as e:
        print(e.message)

    # dense graph
    N = 16
    W = sqaod.generate_random_symmetric_W(N)

    x = sqaod.generate_random_bits(N)
    E0 = py_formulas.dense_graph_calculate_E(W, x)
    E1 = dense_graph_calculate_E(W, x, dtype)
    assert np.allclose(E0, E1)

    xlist = sqaod.create_bitset_sequence(range(0, 1 << N), N)
    E0 = py_formulas.dense_graph_batch_calculate_E(W, xlist)
    E1 = dense_graph_batch_calculate_E(W, xlist, dtype)
    assert np.allclose(E0, E1)

    h0, J0, c0 = py_formulas.dense_graph_calculate_hamiltonian(W)
    h1, J1, c1 = dense_graph_calculate_hamiltonian(W, dtype)
    assert np.allclose(h0, h1)
    assert np.allclose(J0, J1)
Beispiel #4
0
    elapsedTimePerIter = warmup / nIters        
    nIters = int(duration / warmup * nIters) + 1
    print('Done.')
    print('Averarge time : {0} sec, Expected # iterations in {1} sec. : {2}'
          .format(elapsedTimePerIter, duration, nIters))
    sys.stdout.flush()
    
    begin = timer();
    for i in range(nIters) :
        # print('.', end='', file=sys.stderr)
        searcher.search();
    searcher.make_solution()
    end = timer()
    elapsedTime = end - begin
    elapsedTimePerIter = elapsedTime / nIters
    print('Done,')
    print('Averarge time : {0} sec, {1} iterations executed in {2} sec.'
          .format(elapsedTimePerIter, nIters, elapsedTime))
    sys.stdout.flush()
    
    return nIters, elapsedTimePerIter

if __name__ == '__main__' :
    N = 2048
    W = sq.generate_random_symmetric_W(N, dtype=dtype)
    W = dense_graph_random(N, np.float32)
    an = sq.cpu.dense_graph_annealer(W, dtype=np.float32)
    an.set_preferences(n_trotters = N)
    elapsed, nIters = benchmark(an)
    print(elapsed, nIters)
Beispiel #5
0
def dense_graph_random(N, dtype):
    W = sqaod.generate_random_symmetric_W(N, dtype=dtype)
    return _quantize(W, dtype)
Beispiel #6
0
    W = np.array([[-32,4,4,4,4,4,4,4],
                  [4,-32,4,4,4,4,4,4],
                  [4,4,-32,4,4,4,4,4],
                  [4,4,4,-32,4,4,4,4],
                  [4,4,4,4,-32,4,4,4],
                  [4,4,4,4,4,-32,4,4],
                  [4,4,4,4,4,4,-32,4],
                  [4,4,4,4,4,4,4,-32]])
    np.random.seed(0)

    N = 8
    m = 4

    N = 100
    m = 5
    W = sqaod.generate_random_symmetric_W(N, -0.5, 0.5, np.float64)

    ann = dense_graph_annealer(W, dtype=np.float64, n_trotters = m)
    import sqaod.py as py
    #ann = py.dense_graph_annealer(W, n_trotters = m)
    ann.set_qubo(W, sqaod.minimize)
    h, J, c = ann.get_hamiltonian()
    print(h)
    print(J)
    print(c)

    
    Ginit = 5.
    Gfin = 0.001
    
    nRepeat = 2