예제 #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 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
예제 #3
0
def run_real(N, h, st, dt):

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

    A = np.eye(2**N, dtype=complex) - 1j * dt * H  #- (dt**2)*H.dot(H)/2

    psi = np.ones((2**N, 1), dtype=complex) / (2**(N / 2))

    SX = []

    for k in range(st):

        print(k)
        if k % 5 == 0:
            print('measuring sx')
            SX.append(sigmax(psi))

        psi = A.dot(psi)

    return SX
예제 #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
예제 #6
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)
예제 #7
0
import nqs
import models
import sampler

E = []

def measure(M,TI,S):

    e = TI.localEnergy(S.wf,S.st)
#    v = S.wf.varGradient(S.st)

    M['E'] = M['E'] + (e-M['E'])/S.sweeps

    E.append(e[0][0])
#    ga = v['a'] * e
#    gb = v['b'] * e
#    gW = v['W'] * e
#
#    M['ga'] = M['ga'] + (ga-M['ga'])/S.sweeps
#    M['gb'] = M['gb'] + (gb-M['gb'])/S.sweeps
#    M['gW'] = M['gW'] + (gW-M['gW'])/S.sweeps

wf = nqs.brbm_nqs.load_file('./carleo_code/Nqs/Ground/Ising1d_40_1_2.wf')

TI = models.TransIsing1D(nspins=40,hfield=1,pbc=False)

M = {'E':0,'ga':0,'gb':0,'gW':0}
S = sampler.metropolis(wf=wf)
S.afterSweep = lambda S: measure(M,TI,S)
S.run(nsweeps=3000,thermfactor=.1,output=True)