Example #1
0
 def test_energy_contraction_z2(self):
     mpiprint(
         0, '\n' + '=' * 50 +
         '\nPeps Energy (Ham=Identity, peps=random, Z2 symmetry) calculation\n'
         + '-' * 50)
     # Create a PEPS
     from cyclopeps.tools.peps_tools import PEPS
     Nx = 2
     Ny = 2
     d = 2
     D = 3
     Zn = 2
     backend = 'ctf'
     peps = PEPS(Nx=Nx,
                 Ny=Ny,
                 d=d,
                 D=D,
                 chi=1000,
                 Zn=2,
                 backend=backend,
                 normalize=False)
     # Get the Hamiltonian
     from cyclopeps.ops.identity import return_op
     ham = return_op(Nx, Ny, sym='Z2', backend=backend)
     # Calculate initial norm
     norm0 = peps.calc_norm() * 4.
     mpiprint(0, 'Norm (routine) = {}'.format(norm0))
     # Perform the Exact energy calculation:
     bra = einsum('LDWCM,lMXcu->LDluWXCc', peps[0][0],
                  peps[0][1]).remove_empty_ind(0).remove_empty_ind(
                      0).remove_empty_ind(0).remove_empty_ind(0)
     bra = einsum('WXCc,CdYRm->dRWXYcm', bra,
                  peps[1][0]).remove_empty_ind(0).remove_empty_ind(0)
     bra = einsum('WXYcm,cmZru->ruWXYZ', bra,
                  peps[1][1]).remove_empty_ind(0).remove_empty_ind(0)
     norm1 = einsum('WXYZ,WXYZ->', bra, bra.conj())
     norm1 = norm1 * 4
     mpiprint(0, 'Norm (explicit) = {}'.format(norm1))
     tmp = einsum('WXYZ,wxYZ->WXwx', bra, bra.conj())
     E1 = einsum('WXwx,WXwx->', tmp, ham[0][0][0])
     tmp = einsum('WXYZ,wXyZ->WYwy', bra, bra.conj())
     E1 += einsum('WYwy,WYwy->', tmp, ham[1][0][0])
     tmp = einsum('WXYZ,WXyz->YZyz', bra, bra.conj())
     E1 += einsum('YZyz,YZyz->', tmp, ham[0][1][0])
     tmp = einsum('WXYZ,WxYz->XZxz', bra, bra.conj())
     E1 += einsum('XZxz,XZxz->', tmp, ham[1][1][0])
     mpiprint(0,
              'Explicitly computed energy (not normalized) = {}'.format(E1))
     # Contract Energy again
     E2 = peps.calc_op(ham, normalize=False)
     mpiprint(0, 'Energy via peps Method (not normalized) = {}'.format(E2))
     self.assertTrue(abs((norm0 - norm1) / norm0) < 1e-10)
     self.assertTrue(abs((E2 - E1) / E2) < 1e-10)
     mpiprint(0, 'Passed\n' + '=' * 50)
Example #2
0
 def test_energy_contraction_ones(self):
     mpiprint(
         0, '\n' + '=' * 50 +
         '\nPeps Energy (Ham=Identity, peps=ones, no symmetry) calculation\n'
         + '-' * 50)
     # Create a PEPS
     from cyclopeps.tools.peps_tools import PEPS
     Nx = 2
     Ny = 2
     d = 2
     D = 3
     backend = 'ctf'
     peps = PEPS(Nx=Nx,
                 Ny=Ny,
                 d=d,
                 D=D,
                 chi=1000,
                 Zn=None,
                 backend=backend,
                 normalize=False)
     # Set all tensor values to 1
     for xind in range(Nx):
         for yind in range(Ny):
             peps[xind][yind].fill_all(1.)
     # Get the Hamiltonian
     from cyclopeps.ops.identity import return_op
     ham = return_op(Nx, Ny, backend=backend)
     # Calculate initial norm
     norm0 = peps.calc_norm() * 4.
     mpiprint(0, 'Norm = {}'.format(norm0))
     # Perform the Exact energy calculation:
     bra = einsum('LDWCM,lMXcu->WXCc', peps[0][0], peps[0][1])
     bra = einsum('WXCc,CdYRm->WXYcm', bra, peps[1][0])
     bra = einsum('WXYcm,cmZru->WXYZ', bra, peps[1][1])
     norm1 = einsum('WXYZ,WXYZ->', bra, bra.conj()) * 4.
     tmp = einsum('WXYZ,wxYZ->WXwx', bra, bra.conj())
     E1 = einsum('WXwx,WXwx->', tmp, ham[0][0][0])
     tmp = einsum('WXYZ,wXyZ->WYwy', bra, bra.conj())
     E1 += einsum('WYwy,WYwy->', tmp, ham[1][0][0])
     tmp = einsum('WXYZ,WXyz->YZyz', bra, bra.conj())
     E1 += einsum('YZyz,YZyz->', tmp, ham[0][1][0])
     tmp = einsum('WXYZ,WxYz->XZxz', bra, bra.conj())
     E1 += einsum('XZxz,XZxz->', tmp, ham[1][1][0])
     mpiprint(0,
              'Explicitly computed energy (not normalized) = {}'.format(E1))
     # Contract Energy again
     E2 = peps.calc_op(ham, normalize=False)
     mpiprint(0, 'Energy via peps Method (not normalized) = {}'.format(E2))
     self.assertTrue(abs((norm0 - norm1) / norm0) < 1e-10)
     self.assertTrue(abs((norm0 - E1) / norm0) < 1e-10)
     self.assertTrue(abs((norm0 - E2) / norm0) < 1e-10)
     mpiprint(0, 'Passed\n' + '=' * 50)
Example #3
0
 def test_energy_contraction(self):
     mpiprint(
         0, '\n' + '=' * 50 +
         '\nPeps Energy (Ham=Identity, peps=random, no symmetry) calculation\n'
         + '-' * 50)
     # Create a PEPS
     from cyclopeps.tools.peps_tools import PEPS
     Nx = 2
     Ny = 2
     d = 2
     D = 3
     backend = 'ctf'
     peps = PEPS(Nx=Nx, Ny=Ny, d=d, D=D, chi=1000, backend=backend)
     # Get the Hamiltonian
     from cyclopeps.ops.identity import return_op
     ham = return_op(Nx, Ny, backend=backend)
     # Calculate initial norm
     norm0 = peps.calc_norm() * 4.
     # Perform the Exact energy calculation:
     bra = einsum('LDWCM,lMXcu->WXCc', peps[0][0], peps[0][1])
     bra = einsum('WXCc,CdYRm->WXYcm', bra, peps[1][0])
     bra = einsum('WXYcm,cmZru->WXYZ', bra, peps[1][1])
     norm1 = einsum('WXYZ,WXYZ->', bra, bra.conj()) * 4.
     tmp = einsum('WXYZ,wxYZ->WXwx', bra, bra.conj())
     E1 = einsum('WXwx,WXwx->', tmp, ham[0][0][0])
     tmp = einsum('WXYZ,wXyZ->WYwy', bra, bra.conj())
     E1 += einsum('WYwy,WYwy->', tmp, ham[1][0][0])
     tmp = einsum('WXYZ,WXyz->YZyz', bra, bra.conj())
     E1 += einsum('YZyz,YZyz->', tmp, ham[0][1][0])
     tmp = einsum('WXYZ,WxYz->XZxz', bra, bra.conj())
     E1 += einsum('XZxz,XZxz->', tmp, ham[1][1][0])
     # Contract Energy again
     E2 = peps.calc_op(ham, normalize=False)
     self.assertTrue(abs((norm0 - norm1) / norm0) < 1e-10)
     mpiprint(0, 'Passed Norm1')
     self.assertTrue(abs((norm0 - E1) / norm0) < 1e-10)
     mpiprint(0, 'Passed E1')
     mpiprint(0, 'Norm from calc_norm = {}'.format(norm0))
     mpiprint(0, 'Norm from exact contraction {}'.format(norm1))
     mpiprint(0, 'Norm from Energy calc op = {}'.format(E2))
     mpiprint(0, 'Norm from Energy exact contraction {}'.format(E1))
     #mpiprint(0,norm1,E1,norm0,E2,abs((norm0-E2)/norm0))
     self.assertTrue(abs((norm0 - E2) / norm0) < 1e-10)
     mpiprint(0, 'Passed\n' + '=' * 50)
Example #4
0
 def test_energy_itf_contraction(self):
     mpiprint(
         0, '\n' + '=' * 50 +
         '\nPeps Energy (Ham=ITF, peps=random, no symmetry) calculation\n' +
         '-' * 50)
     # Create a PEPS
     from cyclopeps.tools.peps_tools import PEPS
     Nx = 2
     Ny = 2
     d = 2
     D = 3
     backend = 'ctf'
     peps = PEPS(Nx=Nx, Ny=Ny, d=d, D=D, chi=1000, backend=backend)
     peps2 = PEPS(Nx=Nx, Ny=Ny, d=d, D=D, chi=1000, backend=backend)
     # Get the Hamiltonian
     from cyclopeps.ops.itf import return_op
     ham = return_op(Nx, Ny, (1., 2.), backend=backend)
     # Perform the Exact energy calculation:
     bra = einsum('LDWCM,lMXcu->WXCc', peps[0][0], peps[0][1])
     bra = einsum('WXCc,CdYRm->WXYcm', bra, peps[1][0])
     bra = einsum('WXYcm,cmZru->WXYZ', bra, peps[1][1])
     ket = einsum('LDWCM,lMXcu->WXCc', peps2[0][0], peps2[0][1])
     ket = einsum('WXCc,CdYRm->WXYcm', ket, peps2[1][0])
     ket = einsum('WXYcm,cmZru->WXYZ', ket, peps2[1][1])
     norm1 = einsum('WXYZ,WXYZ->', bra, ket)
     tmp = einsum('WXYZ,wxYZ->WXwx', bra, ket)
     E1 = einsum('WXwx,WXwx->', tmp, ham[0][0][0])
     tmp = einsum('WXYZ,wXyZ->WYwy', bra, ket)
     E2 = einsum('WYwy,WYwy->', tmp, ham[1][0][0])
     tmp = einsum('WXYZ,WXyz->YZyz', bra, ket)
     E3 = einsum('YZyz,YZyz->', tmp, ham[0][1][0])
     tmp = einsum('WXYZ,WxYz->XZxz', bra, ket)
     E4 = einsum('XZxz,XZxz->', tmp, ham[1][1][0])
     E1 = E1 + E2 + E3 + E4
     # Contract Energy again
     E2 = peps.calc_op(ham, normalize=False, chi=1e100, ket=peps2)
     mpiprint(0, 'Energy (exact)   = {}'.format(E1))
     mpiprint(0, 'Energy (routine) = {}'.format(E2))
     self.assertTrue(abs((E2 - E1) / E1) < 1e-10)
     mpiprint(0, 'Passed\n' + '=' * 50)
Example #5
0
                    du = 0.5
                    dd = 0.5
                    sx = sxVec[sxind]
                    sy = syVec[0]
                    params = (jr, jl, ju, jd, cr, cl, cu, cd, dr, dl, du, dd,
                              sx, sy)

                    # Create the Suzuki trotter decomposed operator
                    ops = return_op(N, N, params)
                    opsl = ops_conj_trans(ops)
                    curr_ops = return_curr_op(N, N, params)
                    dens_ops_top = return_dens_op(N, N, top=True)
                    dens_ops_bot = return_dens_op(N, N, top=False)

                    try:
                        E = peps.calc_op(ops, return_sum=True, chi=chi[dind])
                        El = pepsl.calc_op(opsl,
                                           return_sum=True,
                                           chi=chi[dind])
                        Elr = peps.calc_op(ops,
                                           return_sum=True,
                                           ket=pepsl,
                                           chi=chi[dind])
                        currents = peps.calc_op(curr_ops,
                                                return_sum=False,
                                                ket=pepsl,
                                                chi=chi[dind])
                        density_top = peps.calc_op(dens_ops_top,
                                                   return_sum=False,
                                                   ket=pepsl,
                                                   chi=chi[dind])
Example #6
0
    Efl, pepsl = run_tebd(Nx,
                          Ny,
                          d,
                          ops,
                          peps=pepsl,
                          D=D[ind],
                          chi=chi[ind],
                          n_step=n_step[ind],
                          step_size=dt[ind],
                          conv_tol=conv[ind],
                          print_prepend='(left) ')

    # --------------------------------------------------------------------
    # Evaluate Operators
    # Current
    currents = peps.calc_op(curr_ops, return_sum=False, ket=pepsl)
    print('Vertical Currents = {}'.format(currents[0].sum()))
    for i in range(Nx):
        print_str = ''
        for j in range(Ny - 1):
            print_str += '{} '.format(currents[0][i][j])
        print(print_str)
    print('Horizontal Currents = {}'.format(currents[1].sum()))
    for i in range(Ny):
        print_str = ''
        for j in range(Nx - 1):
            print_str += '{} '.format(currents[1][i][j])
        print(print_str)
    # Calculate Density
    density_top = peps.calc_op(dens_ops_top, return_sum=False, ket=pepsl)
    density_bot = peps.calc_op(dens_ops_bot, return_sum=False, ket=pepsl)
Example #7
0
                                  n_step=n_step[ind],
                                  step_size=dt[ind],
                                  conv_tol=conv[ind],
                                  print_prepend='(left) ')
            break
        except Exception as e:
            print('Failed Left TEBD:\n{}'.format(e))
            print('Restarting ({}/{} restarts)'.format(i, 5))
            pepsl.load_tensors(pepsl.fdir + pepsl.fname)

    # --------------------------------------------------------------------
    # Evaluate Operators
    # Current
    try:
        currents = peps.calc_op(curr_ops,
                                return_sum=False,
                                ket=pepsl,
                                chi=chi[ind])
        print('Vertical Currents = {}'.format(currents[0].sum()))
        for i in range(Nx):
            print_str = ''
            for j in range(Ny - 1):
                print_str += '{} '.format(currents[0][i][j])
            print(print_str)
        print('Horizontal Currents = {}'.format(currents[1].sum()))
        for i in range(Ny):
            print_str = ''
            for j in range(Nx - 1):
                print_str += '{} '.format(currents[1][i][j])
            print(print_str)
        # Calculate Density
        density_top = peps.calc_op(dens_ops_top,