예제 #1
0
def run_inf_trotter(N, h, st, dt, init_wf=None):

    trotter_st = st
    trotter_dt = dt
    decay_rate = 1

    mod = models.TransIsing1D(N, h, pbc=True)

    if init_wf == None:
        wf = nqs.brbm_nqs(N, N)
        wf.W[:N, :] = .1 * np.eye(N, dtype=complex)
    else:
        wf = init_wf

    meanS = []
    stdS = []

    print("Applying Trotter Evolution...")
    for k in range(trotter_st):

        print(k)
        if True:  #k%5==0:#True:#k==trotter_st-1:
            print("Measuring SigmaX...")
            M = {'E': 0, 'E2': 0}
            S = sampler.metropolis(wf=wf)
            S.afterSweep = lambda S: measure_sigmax(M, mod, S)
            S.run(nsweeps=5000, output=False)
            print(M['E'], np.sqrt(M['E2'] - M['E']**2))
            meanS.append(M['E'][0, 0])
            stdS.append(np.sqrt(M['E2'] - M['E']**2)[0, 0])

        tao = trotter_dt * (decay_rate**(k / trotter_st))
        mod.applyTrotterStep(wf, tao, inf=True)

    return mod, wf, meanS, stdS
예제 #2
0
def reduceUBM(ubm, nh_factor=1, nsteps=300, nsweeps=200, learning_rate=1e-2):

    # create and initialize rbm wave function
    rbm = nqs.brbm_nqs(ubm.nv, int(ubm.nh*nh_factor))
    rbm.setRandomParams()

    rbm.a = np.real(ubm.a) + 0j
    rbm.b[:ubm.nh] = np.real(ubm.b) + 0j
    rbm.W[:ubm.nh,:ubm.nv] = np.real(ubm.W) + 0j
    rbm.Y[:ubm.nv,:ubm.nv] = np.real(ubm.Y) + 0j

    print(np.real(ubm.Y))

    # optimize with real parameters to adjust the absolute value
    # of each coefficient in the ubm
    S = sampler.metropolis(wf=rbm)
    O = optimize.fidelity_GA(S, ubm)
    O.opt(nsteps,nsweeps,learning_rate)

    # now I have to take care of the phases of the coefficients
#    a, Y = optimize.opt_phases(ubm.logPsi_dict, ubm.nv, 1000, 1e-2)

    # create a new ubm
    new = rbm.asUBM()
#    new.Y = 1j*Y
#    new.a += 1j*a

    return new, O.fidelity[-1]
예제 #3
0
def run_inf_trotter(N, h, st, dt, init_wf=None):

    trotter_st = st
    trotter_dt = dt
    decay_rate = 1

    mod = models.TransIsing1D(N, h, pbc=True)

    if init_wf == None:
        wf = nqs.brbm_nqs(N, N)
        #wf.W = .1*np.random.rand(N,N).astype(complex)
        wf.W[:N, :] = .1 * np.eye(N, dtype=complex)
        #        for k in range(N):
        #            wf.W[N+k,k] = .2
        #        for k in range(N-1):
        #            wf.W[N+k,k+1] = .2
    else:
        wf = init_wf

    meanE = []
    stdE = []

    print("Applying Trotter Evolution...")
    for k in range(trotter_st):

        #        print('a', wf.nh)
        #        wf.rmVisibleInt()
        #        print('b', wf.nh)
        #        wf.rmHiddenNodes(keep=4*N)

        print(k)
        if k % 5 == 0:  #True:#k==trotter_st-1:
            print("Measuring Energy...")
            M = {'E': 0, 'E2': 0, 'C': 0}
            S = sampler.metropolis(wf=wf)
            S.afterSweep = lambda S: measure(M, mod, S)
            S.run(nsweeps=1000, output=False)
            print(M['E'], np.sqrt(M['E2'] - M['E']**2))
            meanE.append(M['E'][0, 0])
            stdE.append(np.sqrt(M['E2'] - M['E']**2)[0, 0])

        tao = trotter_dt * (decay_rate**(k / trotter_st))
        mod.applyTrotterStep(wf, -1j * tao, inf=True)

    return mod, wf, meanE, stdE
예제 #4
0
def run_trotter(N, h, st, dt, init_wf=None):

    trotter_st = st
    trotter_dt = dt
    decay_rate = 1

    mod = models.TransIsing1D(N, h, pbc=True)

    if init_wf == None:
        wf = nqs.bbm_nqs(N, 0)
    else:
        wf = init_wf

    meanE = []
    stdE = []

    print("Applying Trotter Evolution...")
    for k in range(trotter_st):

        tao = trotter_dt * (decay_rate**(k / trotter_st))
        mod.applyTrotterStep(wf, -1j * tao, renorm=True)

        wf.rmHiddenNodes(keep=2 * N)
        #        wf.W = wf.W/np.max(wf.W)

        print(k)
        if True:  #k%50==0:#k==trotter_st-1:
            print("Measuring Energy...")
            M = {'E': 0, 'E2': 0, 'C': 0}
            S = sampler.metropolis(wf=wf.asRBM())
            S.afterSweep = lambda S: measure(M, mod, S)
            S.run(nsweeps=1000, output=False)
            print(M['E'], np.sqrt(M['E2'] - M['E']**2))
            meanE.append(M['E'][0, 0])
            stdE.append(np.sqrt(M['E2'] - M['E']**2)[0, 0])

    return mod, wf, meanE, stdE
예제 #5
0
def run_inf_trotter2(N, h, st, dt, init_wf=None):

    trotter_st = st
    trotter_dt = dt
    decay_rate = 1

    mod = models.TransIsing1D(N, h, pbc=True)

    if init_wf == None:
        wf = nqs.brbm_nqs(N, 0)
    else:
        wf = init_wf

    meanE = []
    stdE = []

    print("Applying Trotter Evolution...")
    for k in range(trotter_st):

        #        wf.rmHiddenNodes(keep=4*N)

        print(k)
        if True:  #k==trotter_st-1:
            print("Measuring SigmaX...")
            M = {'E': 0, 'E2': 0, 'C': 0}
            S = sampler.metropolis(wf=wf)
            S.afterSweep = lambda S: measure_sigmax(M, mod, S)
            S.run(nsweeps=1000, output=False)
            print(M['E'], np.sqrt(M['E2'] - M['E']**2))
            meanE.append(M['E'][0, 0])
            stdE.append(np.sqrt(M['E2'] - M['E']**2)[0, 0])

        tao = trotter_dt * (decay_rate**(k / trotter_st))
        mod.applyTrotterStep(wf, tao, inf=True, hidden_crz=True)

    return mod, wf, meanE, stdE
import numpy as np

import nqs
import models
import sampler
import optimize

ubm = nqs.wrbbm_nqs(nv=10, nh=10)
ubm.setRandomParams()
#ubm.X = np.zeros_like(ubm.X)

rbm = ubm.asRBM()
S = sampler.metropolis(wf=rbm)

O = optimize.fidelity_GA(S, ubm)
예제 #7
0
import numpy as np

import nqs
import models
import sampler
import optimize

#wf = nqs.ti_brbm_nqs(nv=10,nf=1)
wf = nqs.brbm_nqs(nv=10, nh=10)
wf.setRandomParams()

TI = models.TransIsing1D(nspins=10, hfield=.1)

S = sampler.metropolis(wf=wf)

O = optimize.energy_GD(S, TI)