Example #1
0
def main(N, cache_dir=None):
    '''Generate and test a problem with N spins'''

    if WIRE:
        h, J, gam = generate_wire(N)
    else:
        h, J, gam = generate_prob(N)

    t = time()
    if N < 18:
        print('Exact solution...')
        e_vals, e_vecs = solve(h, J, gamma=gam)
        print(e_vals[:2])
    print('Runtime: {0:.3f} (s)'.format(time()-t))

    t = time()
    solver = RP_Solver(h, J, gam, verbose=False, cache_dir=cache_dir)
    solver.solve()

    print('\n'*3)
    print('New RP solution:')
    print(solver.node.Es[:2])
    print('Runtime: {0:.3f} (s)'.format(time()-t))

    msolver = RP_Solver(h, J, gam)
    t = time()
    modes = solver.node.modes
    msolver.mode_solve(modes)

    print('\n'*3)
    print('Mode solved:')
    print(msolver.node.Es[:2])
    print('Runtime: {0:.3f} (s)'.format(time()-t))

    f = lambda x: np.round(x,2)

    print(solver.node.Hx.shape)
    print(msolver.node.Hx.shape)

    Dx = solver.node.Hx - msolver.node.Hx

    print('Dx diffs...')
    for i,j in np.transpose(np.nonzero(Dx)):
        print('\t{0}:{1} :: {2:.3f}'.format(i,j,Dx[i,j]))


    # resolve
    for _ in range(TRIALS):
        t = time()
        nx, nz = solver.ground_fields()

        solver = RP_Solver(h, J, gam, nx=nx, nz=nz, verbose=False, cache_dir=cache_dir)
        solver.solve()

        print('\n'*3)
        print('New RP solution:')
        print(solver.node.Es[:2])
        print('Runtime: {0:.3f} (s)'.format(time()-t))
Example #2
0
def main(N, cache_dir=None):
    '''Generate and test a problem with N spins'''

    if WIRE:
        h, J, gam = generate_wire(N)
    else:
        h, J, gam = generate_prob(N)

    t = time()
    if N < 18:
        print('Exact solution...')
        e_vals, e_vecs = solve(h, J, gamma=gam)
        print(e_vals[:2])
    print('Runtime: {0:.3f} (s)'.format(time() - t))

    t = time()
    solver = RP_Solver(h, J, gam, verbose=False, cache_dir=cache_dir)
    solver.solve()

    print('\n' * 3)
    print('New RP solution:')
    print(solver.node.Es[:2])
    print('Runtime: {0:.3f} (s)'.format(time() - t))

    msolver = RP_Solver(h, J, gam)
    t = time()
    modes = solver.node.modes
    msolver.mode_solve(modes)

    print('\n' * 3)
    print('Mode solved:')
    print(msolver.node.Es[:2])
    print('Runtime: {0:.3f} (s)'.format(time() - t))

    f = lambda x: np.round(x, 2)

    print(solver.node.Hx.shape)
    print(msolver.node.Hx.shape)

    Dx = solver.node.Hx - msolver.node.Hx

    print('Dx diffs...')
    for i, j in np.transpose(np.nonzero(Dx)):
        print('\t{0}:{1} :: {2:.3f}'.format(i, j, Dx[i, j]))

    # resolve
    for _ in range(TRIALS):
        t = time()
        nx, nz = solver.ground_fields()

        solver = RP_Solver(h,
                           J,
                           gam,
                           nx=nx,
                           nz=nz,
                           verbose=False,
                           cache_dir=cache_dir)
        solver.solve()

        print('\n' * 3)
        print('New RP solution:')
        print(solver.node.Es[:2])
        print('Runtime: {0:.3f} (s)'.format(time() - t))