def test_canonical_flip(self): mpiprint( 0, '\n' + '=' * 50 + '\nCanonical Peps Flipping test\n' + '-' * 50) from cyclopeps.tools.peps_tools import PEPS Nx = 5 Ny = 5 d = 2 D = 3 chi = 10 peps = PEPS(Nx=Nx, Ny=Ny, d=d, D=D, chi=chi, normalize=False, canonical=True) norm0 = peps.calc_norm() peps.flip() norm1 = peps.calc_norm() peps.flip() norm2 = peps.calc_norm() mpiprint(0, 'Norms = {},{},{}'.format(norm0, norm1, norm2)) self.assertTrue(abs((norm0 - norm1) / norm0) < 1e-3) self.assertTrue(abs((norm0 - norm2) / norm0) < 1e-10) mpiprint(0, 'Passed\n' + '=' * 50)
def test_canonical_rotate_z2(self): mpiprint( 0, '\n' + '=' * 50 + '\nCanonical Peps Rotation test (Z2 Symmetry)\n' + '-' * 50) from cyclopeps.tools.peps_tools import PEPS Nx = 3 Ny = 3 d = 2 D = 3 chi = 10 Zn = 2 backend = 'numpy' peps = PEPS(Nx=Nx, Ny=Ny, d=d, D=D, chi=chi, Zn=Zn, backend=backend, normalize=False, canonical=True) norm0 = peps.calc_norm() peps.rotate() norm1 = peps.calc_norm() peps.rotate(clockwise=False) norm2 = peps.calc_norm() mpiprint(0, 'Norms = {},{},{}'.format(norm0, norm1, norm2)) self.assertTrue(abs((norm0 - norm1) / norm0) < 1e-3) self.assertTrue(abs((norm0 - norm2) / norm0) < 1e-10) mpiprint(0, 'Passed\n' + '=' * 50)
def test_rotate_ctf(self): mpiprint(0, '\n' + '=' * 50 + '\nPeps Rotation test (ctf)\n' + '-' * 50) from cyclopeps.tools.peps_tools import PEPS Nx = 3 Ny = 3 d = 2 D = 3 chi = 100 peps = PEPS(Nx=Nx, Ny=Ny, d=d, D=D, chi=chi, normalize=False, backend='ctf') norm0 = peps.calc_norm() peps.rotate() norm1 = peps.calc_norm() peps.rotate(clockwise=False) norm2 = peps.calc_norm() mpiprint(0, 'Norms = {},{},{}'.format(norm0, norm1, norm2)) self.assertTrue(abs((norm0 - norm1) / norm0) < 1e-5) self.assertTrue(abs((norm0 - norm2) / norm0) < 1e-10) mpiprint(0, 'Passed\n' + '=' * 50)
def test_canonical_normalization_z2(self): from cyclopeps.tools.peps_tools import PEPS mpiprint( 0, '\n' + '=' * 50 + '\nCanonical Peps Normalization test (Z2 Symmetry) \n' + '-' * 50) Nx = 3 Ny = 5 d = 2 D = 3 chi = 10 Zn = 2 backend = 'numpy' peps = PEPS(Nx=Nx, Ny=Ny, d=d, D=D, chi=chi, Zn=Zn, backend=backend, normalize=False, canonical=True) norm = peps.calc_norm(chi=chi) norm = peps.normalize() mpiprint(0, 'Norm = {}'.format(norm)) self.assertTrue(abs(1.0 - norm) < 1e-3) mpiprint(0, 'Passed\n' + '=' * 50)
def test_normalization_Z3(self): from cyclopeps.tools.peps_tools import PEPS mpiprint( 0, '\n' + '=' * 50 + '\nPeps (5x5) Normalization test with Z3 Symmetry\n' + '-' * 50) Nx = 5 Ny = 5 d = 2 D = 6 chi = 50 Zn = 3 # Zn symmetry (here, Z3) dZn = 2 backend = 'ctf' # Generate random PEPS peps = PEPS(Nx=Nx, Ny=Ny, d=d, D=D, chi=chi, Zn=Zn, dZn=dZn, backend=backend, normalize=False) # Compute the norm (2 ways for comparison) peps_sparse = peps.make_sparse() norm0 = peps.calc_norm(chi=chi) norm1 = peps_sparse.calc_norm(chi=chi) mpiprint(0, 'Symmetric Sparse Norm = {}'.format(norm1)) mpiprint(0, 'Symmetric Dense Norm = {}'.format(norm0)) self.assertTrue(abs((norm0 - norm1) / norm1) < 1e-3) mpiprint(0, 'Passed\n' + '=' * 50)
def test_energy_contraction_ones_z2(self): mpiprint( 0, '\n' + '=' * 50 + '\nPeps Energy (Ham=Identity, peps=ones, 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 = 'numpy' peps = PEPS(Nx=Nx, Ny=Ny, d=d, D=D, chi=1000, Zn=2, 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, 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) print('Check here {}, {}, {}, {}'.format(norm0, norm1, E1, E2)) self.assertTrue(abs((norm0 - E1) / norm0) < 1e-10) self.assertTrue(abs((norm0 - E2) / norm0) < 1e-10) mpiprint(0, 'Passed\n' + '=' * 50)
def test_normalization_ctf(self): from cyclopeps.tools.peps_tools import PEPS mpiprint( 0, '\n' + '=' * 50 + '\nPeps (5x5) Normalization test without Symmetry (ctf)\n' + '-' * 50) Nx = 5 Ny = 5 d = 2 D = 6 chi = 10 Zn = None backend = 'ctf' peps = PEPS(Nx=Nx, Ny=Ny, d=d, D=D, chi=chi, Zn=Zn, backend=backend, normalize=True) norm = peps.calc_norm(chi=chi) mpiprint(0, 'Norm = {}'.format(norm)) self.assertTrue(abs(1.0 - norm) < 1e-3) mpiprint(0, 'Passed\n' + '=' * 50)
def test_energy_contraction_heis_z2(self): mpiprint( 0, '\n' + '=' * 50 + '\nPeps Energy (Ham=Heisenberg, 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.heis import return_op ham = return_op(Nx, Ny, sym='Z2', backend=backend) # Calculate initial norm norm0 = peps.calc_norm() 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 mpiprint(0, 'Norm (explicit) = {}'.format(norm1)) #print(ham[0][0][0]) 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]) E1 = E1 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) / E1) < 1e-10) mpiprint(0, 'Passed\n' + '=' * 50)
def test_energy_itf_contraction_ones(self): mpiprint( 0, '\n' + '=' * 50 + '\nPeps Energy (Ham=ITF, 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, normalize=False, backend=backend) # 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.itf import return_op ham = return_op(Nx, Ny, (1., 2.), backend=backend) # Calculate initial norm norm0 = peps.calc_norm() 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()) mpiprint(0, 'Explicitly computed norm = {}'.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 (routine) = {}'.format(E2)) self.assertTrue(abs((E2 - E1) / E1) < 1e-10) mpiprint(0, 'Passed\n' + '=' * 50)
def test_flip_Z2_ctf(self): mpiprint( 0, '\n' + '=' * 50 + '\nPeps Z2 Flipping test (ctf)\n' + '-' * 50) from cyclopeps.tools.peps_tools import PEPS Nx = 5 Ny = 5 d = 2 D = 6 Zn = 2 chi = 10 backend = 'ctf' # Generate random PEPS peps = PEPS(Nx=Nx, Ny=Ny, d=d, D=D, chi=chi, Zn=Zn, backend=backend, normalize=False) # Compute the norm (2 ways for comparison) norm0 = peps.calc_norm(chi=chi) peps_sparse = peps.make_sparse() norm1 = peps_sparse.calc_norm(chi=chi) mpiprint(0, 'Symmetric Dense Norm = {}'.format(norm0)) mpiprint(0, 'Symmetric Sparse Norm = {}'.format(norm1)) # Rotate the PEPS peps.flip() norm2 = peps.calc_norm(chi=chi) peps_sparse = peps.make_sparse() norm3 = peps_sparse.calc_norm(chi=chi) mpiprint(0, 'Flipped Symmetric Dense Norm = {}'.format(norm2)) mpiprint(0, 'Flipped Symmetric Sparse Norm = {}'.format(norm3)) self.assertTrue(abs((norm0 - norm1) / norm1) < 1e-3) self.assertTrue(abs((norm0 - norm2) / norm2) < 1e-3) self.assertTrue(abs((norm0 - norm3) / norm3) < 1e-3) mpiprint(0, 'Passed\n' + '=' * 50)
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)
def test_normalization_Z2_ctf(self): from cyclopeps.tools.peps_tools import PEPS mpiprint( 0, '\n' + '=' * 50 + '\nPeps (5x5) Normalization test with Z2 Symmetry (ctf)\n' + '-' * 50) Nx = 5 Ny = 5 d = 2 D = 6 chi = 10 Zn = 2 # Zn symmetry (here, Z2) backend = 'ctf' # Generate random PEPS peps = PEPS(Nx=Nx, Ny=Ny, d=d, D=D, chi=chi, Zn=Zn, backend=backend, normalize=False) # Compute the norm (2 ways for comparison) norm0 = peps.calc_norm(chi=chi) peps_sparse = peps.make_sparse() norm1 = peps_sparse.calc_norm(chi=chi) mpiprint(0, 'Symmetric Dense Norm = {}'.format(norm0)) mpiprint(0, 'Symmetric Sparse Norm = {}'.format(norm1)) # Normalize the PEPS norm2 = peps.normalize() peps_sparse = peps.make_sparse() norm3 = peps_sparse.calc_norm(chi=chi) mpiprint(0, 'Symmetric Dense Norm (After normalized) = {}'.format(norm2)) mpiprint(0, 'Symmetric Sparse Norm (After normalized) = {}'.format(norm3)) # Do some assertions to check if passed self.assertTrue(abs((norm0 - norm1) / norm1) < 1e-3) self.assertTrue(abs(1.0 - norm2) < 1e-3) self.assertTrue(abs(1.0 - norm3) < 1e-3) mpiprint(0, 'Passed\n' + '=' * 50)