def test_ising_crit_im_tdvp_RK4(self):
        N = 5
        D = 8
        
        s = tdvp.EvoMPS_TDVP_Generic(N, [D] * (N + 1), [2] * (N + 1), get_ham(N, 1.0, 1.0))
        
        E = get_E_crit(N)
        
        tol = 1E-5 #Should result in correct energy to ~1E-12
        
        eta = 1
        while eta > tol:
            s.update()
            H = s.H_expect
            s.take_step_RK4(0.1)
            eta = s.eta.real.sum()
            
        print("E=",E," E_mps=",H," difference=",abs(E-H))
        self.assertTrue(sp.allclose(E, H))

        rtstep = 0.1
        s.ham = get_ham(N, 1.0, 1.1)
        s.update()
        H1 = s.H_expect
        for j in range(10):
            s.take_step_RK4(rtstep*1.j)
            s.update()
        H2 = s.H_expect
        print("E1=",H1," E2=",H2," difference=",abs(H1-H2))
        self.assertTrue(abs(H1-H2) < rtstep**4)
Exemple #2
0
def convert_tdvp_mps(s,hamTermList):
    """Convert object evoMPS.mps_gen.EvoMPS_MPS_Generic to evoMPS.tdvp_gen.EvoMPS_TDVP_Generic
    with Hamiltonian given by hamTermList
    """
    s1 = tdvp.EvoMPS_TDVP_Generic(s.N, s.D,s.q,hamTermList)
    s1.A = copy.deepcopy(s.A)
    s1.update()
    return s1
Exemple #3
0
    def test_ising_crit_im_tdvp_RK4(self):
        N = 5

        s = tdvp.EvoMPS_TDVP_Generic(N, [1024] * (N + 1), [2] * (N + 1),
                                     get_ham(N, 1.0, 1.0))

        E = get_E_crit(N)

        tol = 1E-5  #Should result in correct energy to ~1E-12

        eta = 1
        while eta > tol:
            s.update()
            H = s.H_expect
            s.take_step_RK4(0.1)
            eta = s.eta.real.sum()

        self.assertTrue(sp.allclose(E, H))
 def test_ising_crit_im_tdvp_auto_trunc(self):
     N = 10
     D = 16
     
     s = tdvp.EvoMPS_TDVP_Generic(N, [D] * (N + 1), [2] * (N + 1), get_ham(N, 1.0, 0.5))
     
     tol = 1E-5 #Should result in correct energy to ~1E-12
     
     eta = 1
     itr = 0
     while eta > tol:
         s.update(auto_truncate=True)
         if eta < 1E-3 and itr % 10 == 9:
             s.vari_opt_ss_sweep(ncv=4)
         else:
             s.take_step(0.08)
         eta = s.eta.real.sum()
         itr += 1
         
     self.assertTrue(s.D[N//2] < D)
 def test_ising_crit_im_tdvp_dynexp(self):
     N = 8
     D = 1
     
     s = tdvp.EvoMPS_TDVP_Generic(N, [D] * (N + 1), [2] * (N + 1), get_ham(N, 1.0, 1.0))
     
     E = get_E_crit(N)
     
     tol = 1E-5 #Should result in correct energy to ~1E-12
     
     eta = 1
     itr = 0
     while eta > tol:
         s.update()
         H = s.H_expect
         s.take_step(0.1, dynexp=True, dD_max=1)
         eta = s.eta.real.sum()
         itr += 1
         
     self.assertTrue(sp.allclose(E, H))
    def test_ising_crit_im_tdvp_split_step(self):
        N = 5
        D = 8
        
        s = tdvp.EvoMPS_TDVP_Generic(N, [D] * (N + 1), [2] * (N + 1), get_ham(N, 1.0, 1.0))
        
        E = get_E_crit(N)
        
        tol = 1E-5 #Should result in correct energy to ~1E-12
        
        itr = 1
        eta = 1
        while eta > tol:
            s.update()
            B = s.calc_B() #ensure eta is set!
            eta = s.eta.real.sum()
            H = s.H_expect
            print(itr,": eta = ",eta, " E_mps = ", H)
            if eta < 1E-2:
                s.take_step_split(0.1)
            else:
                s.take_step(0.1, B=B)
            
            itr += 1

        print("E=",E," E_mps=",H," difference=",abs(E-H))
        self.assertTrue(sp.allclose(E, H))

        rtstep = 0.1
        s.ham = get_ham(N, 1.0, 1.1)
        s.update()
        H1 = s.H_expect
        for j in range(10):
            s.take_step_split(rtstep*1.j)
        s.update()
        H2 = s.H_expect
        print("E1=",H1," E2=",H2," difference=",abs(H1-H2))
        self.assertTrue(abs(H1-H2) < rtstep**4)
 def test_ising_crit_im_tdvp_DMRG(self):
     N = 5
     D = 8
     
     s = tdvp.EvoMPS_TDVP_Generic(N, [D] * (N + 1), [2] * (N + 1), get_ham(N, 1.0, 1.0))
     
     E = get_E_crit(N)
     
     tol = 1E-5 #Should result in correct energy to ~1E-12
     
     eta = 1
     itr = 0
     while eta > tol:
         s.update()
         H = s.H_expect
         if itr % 10 == 9:
             s.vari_opt_ss_sweep()
         else:
             s.take_step(0.1)            
         eta = s.eta.real.sum()
         itr += 1
         
     self.assertTrue(sp.allclose(E, H))
 def test_ising_crit_im_tdvp(self):
     N = 5
     D = 8
     
     s = tdvp.EvoMPS_TDVP_Generic(N, [D] * (N + 1), [2] * (N + 1), get_ham(N, 1.0, 1.0))
     
     E = get_E_crit(N)
     
     tol = 1E-5 #Should result in correct energy to ~1E-12
     
     eta = 1
     while eta > tol:
         s.update()
         H = s.H_expect
         s.take_step(0.1)
         eta = s.eta.real.sum()
         
     s.update()
         
     self.assertTrue(sp.allclose(E, H))
     
     self.assertLessEqual(s.expect_1s(x_ss, 1), 10 * tol)
     
     self.assertLessEqual(s.expect_1s(y_ss, 1), 10 * tol)
Exemple #9
0
"""
The bond dimension for each site is given as a vector, length N + 1.
Here we set the bond dimension = bond_dim for all sites.
"""
D = [bond_dim] * (N + 1)

"""
The site Hilbert space dimension is also given as a vector, length N + 1.
Here, we set all sites to dimension = 2.
"""
q = [qn] * (N + 1)

"""
Now we are ready to create an instance of the evoMPS class.
"""
s = tdvp.EvoMPS_TDVP_Generic(N, D, q, get_ham(N, Jx, Jy, Jz))
s.zero_tol = zero_tol
s.sanity_checks = sanity_checks
#s.canonical_form = 'left'
#s.gauge_fixing = 'left'

"""
The following loads a ground state from a file.
The ground state will be saved automatically when it is declared found.
"""
grnd_fname = "heis_af_N%d_D%d_q%d_S%g_Jx%g_Jy%g_Jz%g_s%g_dtau%g_ground.npy" % (N, bond_dim, qn, S, Jx, Jy, Jz, tol_im, step)

if load_saved_ground:
    try:
        a_file = open(grnd_fname, 'rb')
        s.load_state(a_file)
Exemple #10
0
"""
The site Hilbert space dimension is also given as a vector, length N + 1.
Here, we set all sites to dimension = 2.
"""
q = [2] * (N + 1)
"""
Print the exact ground state energy
"""
if h == J:
    E = -2 * abs(sp.sin(sp.pi * (2 * sp.arange(N) + 1) / (2 *
                                                          (2 * N + 1)))).sum()
    print "Exact ground state energy = %.15g" % E
"""
Now we are ready to create an instance of the evoMPS class.
"""
s = tdvp.EvoMPS_TDVP_Generic(N, D, q, get_ham(N, J, h))
s.zero_tol = zero_tol
s.sanity_checks = sanity_checks
"""
The following loads a ground state from a file.
The ground state will be saved automatically when it is declared found.
"""
grnd_fname = "t_ising_N%d_D%d_J%g_h%g_s%g_dtau%g_ground.npy" % (
    N, bond_dim, J, h, tol_im, step)

if load_saved_ground:
    try:
        a_file = open(grnd_fname, 'rb')
        s.load_state(a_file)
        a_file.close
        real_time = True
"""
h = -2.00
J = 1.0

if h == -J:
    E = 0
    for n in xrange(N):
        E += 2 * abs(sp.sin(sp.pi * (2 * n + 1) / (2 * (2 * N + 1))))
    print "Exact energy = %.15g" % E

#ham = [get_ham(J, h)] * (N - 1) + [get_ham_end(J, h)]
ham = [get_ham_3s(J, h)] * (N - 2) + [get_ham_end_3s(J, h)]
"""
Now we are ready to create an instance of the evoMPS class.
"""
s = tdvp.EvoMPS_TDVP_Generic(N, D, q, ham)

s.randomize()

step = 0.02
tol = 1E-10
"""
The following handles loading the ground state from a file.
The ground state will be saved automatically when it is declared found.
If this script is run again with the same settings, an existing
ground state will be loaded, if present.
"""
grnd_fname = "t_ising_N%d_D%d_q%d_J%g_h%g_s%g_dtau%g_ground.npy" % (
    N, qn, bond_dim, J, h, tol, step)

loaded = False
Exemple #12
0
  ham[n][s,t,u,v] = <st|h|uv> (for sites n and n+1)
'''


def get_hamiltonian(num_sites, J, h):
    ham = (-J * sp.kron(Sz, Sz) - h * sp.kron(Sx, sp.eye(2))).reshape(
        2, 2, 2, 2)
    return [ham] * num_sites


#Create vectors for bond dimension and local site hilber space
v_D = [bond_dim] * (N + 1)
v_q = [2] * (N + 1)
start_time = time.time()
#Create instance of evoMPS_generic class
sim = tdvp.EvoMPS_TDVP_Generic(N, v_D, v_q, get_hamiltonian(N, J, h))
sim.zero_tol = zero_tol
sim.sanity_checks = sanity_checks

#if ground state is already calculated then go to real time evolution otherwise first calculate ground state.
try:
    a_file = open("DQPT/Logs/" + grnd_fname, 'rb')
    sim.load_state(a_file)
    a_file.close
    groun_loaded = True
    print('Using saved ground state: ' + grnd_fname)
except IOError as e:
    groun_loaded = False
    print('No existing ground state could be opened.')

#if ground state is not loaded
Exemple #13
0
import functools as ft
import matplotlib.pyplot as plt

N = 8
D = 10
q = 2

zero_tol = 1E-10  #Zero-tolerance for the Schmidt coefficients squared (right canonical form)
J = 0.1

hamTerm = np.kron(me.Sx, me.Sx) + J * np.kron(me.Sz, np.eye(2))  #TFIM
hamTerm = me.random_hermitian(q**2)
hamTermList = me.make_ham_for_MPS(N, hamTerm)
hamFull = me.make_ham(hamTerm, N)
s = tdvp.EvoMPS_TDVP_Generic(N,
                             np.ones(N + 1, dtype=int) * D,
                             np.ones(N + 1, dtype=int) * q, hamTermList)

s.randomize()
s.zero_tol = zero_tol

for i in range(100):
    s.take_step_RK4(0.08)
    s.update()

plt.close('all')
me.plot_energy(s, 'E gs')
s.apply_op_1s(me.Sz, 3)
me.plot_energy(s, 'E gs pert')

dt = 0.01