def test_full_symm_3byb3(self): U = 20 * (np.random.rand() - 0.5) t = np.random.rand() gm = geom.Geometry.createSquareGeometry(3, 3, 0, 0, bc1_open=False, bc2_open=False) model = ed_fermions.fermions(gm, U, t, ns=np.array([2, 2])) # no symmetry hamiltonian_full = model.createH(projector=model.n_projector) eig_vals_full, eig_vects_full = model.diagH(hamiltonian_full) # rotational symmetry cx, cy = model.geometry.get_center_of_mass() rot_fn = symm.getRotFn(4, cx=cx, cy=cy) rot_cycles, max_cycle_len_rot = symm.findSiteCycles( rot_fn, model.geometry) rot_op = model.n_projector.dot( model.get_xform_op(rot_cycles).dot( model.n_projector.conj().transpose())) # reflection symmetry refl_fn = symm.getReflFn(np.array([[0], [1]]), cx=cx, cy=cy) refl_cycles, max_cycle_len_refl = symm.findSiteCycles( refl_fn, model.geometry) refl_op = model.n_projector.dot( model.get_xform_op(refl_cycles).dot( model.n_projector.conj().transpose())) # translational symmetry tx_fn = symm.getTranslFn(np.array([[1], [0]])) tx_cycles, tx_max = symm.findSiteCycles(tx_fn, model.geometry) tx_op_full = model.get_xform_op(tx_cycles) tx_op = model.n_projector.dot( tx_op_full.dot(model.n_projector.conj().transpose())) ty_fn = symm.getTranslFn((np.array([[0], [1]]))) ty_cycles, ty_max = symm.findSiteCycles(ty_fn, model.geometry) ty_op_full = model.get_xform_op(ty_cycles) ty_op = model.n_projector.dot( ty_op_full.dot(model.n_projector.conj().transpose())) symm_projs = symm.getC4V_and_3byb3(rot_op, refl_op, tx_op, ty_op) eig_vals_sectors = [] for ii, proj in enumerate(symm_projs): h_sector = model.createH(projector=proj.dot(model.n_projector)) eig_vals_sector, eig_vects_sector = model.diagH(h_sector) eig_vals_sectors.append(eig_vals_sector) # why only accurate to 10 decimal places? eigs_all_sectors = np.sort(np.concatenate(eig_vals_sectors)) max_diff = np.abs(eig_vals_full - eigs_all_sectors).max() self.assertAlmostEqual(max_diff, 0, 10)
def test_translational_symm_3x3(self): """ Test translational symmetry by diagonalizing random 3x3 spin system with and without it :return: """ cluster = geom.Geometry.createSquareGeometry(3, 3, 0, 0, bc1_open=False, bc2_open=False) jx = np.random.rand() jy = np.random.rand() jz = np.random.rand() hx = np.random.rand() hy = np.random.rand() hz = np.random.rand() # diagonalize full hamiltonian spin_model = tvi.spinSystem(cluster, jx, jy, jz, hx, hy, hz, use_ryd_detunes=0) hamiltonian_full = spin_model.createH() eig_vals_full, eig_vects_full = spin_model.diagH(hamiltonian_full) xtransl_fn = symm.getTranslFn(np.array([[1], [0]])) xtransl_cycles, max_cycle_len_translx = symm.findSiteCycles( xtransl_fn, spin_model.geometry) xtransl_op = spin_model.get_xform_op(xtransl_cycles) xtransl_op = xtransl_op # y-translations ytransl_fn = symm.getTranslFn(np.array([[0], [1]])) ytransl_cycles, max_cycle_len_transly = symm.findSiteCycles( ytransl_fn, spin_model.geometry) ytransl_op = spin_model.get_xform_op(ytransl_cycles) ytransl_op = ytransl_op symm_projs, kxs, kys = symm.get2DTranslationProjectors( xtransl_op, max_cycle_len_translx, ytransl_op, max_cycle_len_transly) eig_vals_sectors = [] for ii, proj in enumerate(symm_projs): h_sector = spin_model.createH(projector=proj) eig_vals_sector, eig_vects_sector = spin_model.diagH(h_sector) eig_vals_sectors.append(eig_vals_sector) # why only accurate to 10 decimal places? eigs_all_sectors = np.sort(np.concatenate(eig_vals_sectors)) max_diff = np.abs(eig_vals_full - eigs_all_sectors).max() self.assertAlmostEqual(max_diff, 0, 10)
def test_four_by_four_xy_model_symm(self): """ Test exact diagonalization of 4x4 xy model with periodic boundary conditions reference: J. Phys. A: Math. Gen 32 51 (1999). "Finite-size scaling in the spin-1/2 xy model on a square lattice" by C J Hamer et al """ cluster = geom.Geometry.createSquareGeometry(4, 4, 0, 0, bc1_open=False, bc2_open=False) # diagonalize full hamiltonian spin_model = tvi.spinSystem(cluster, jx=-1.0, jy=-1.0, jz=0.0, hx=0.0, hy=0.0, hz=0.0, use_ryd_detunes=0) # x-translations xtransl_fn = symm.getTranslFn(np.array([[1], [0]])) xtransl_cycles, max_cycle_len_translx = symm.findSiteCycles( xtransl_fn, spin_model.geometry) xtransl_op = spin_model.get_xform_op(xtransl_cycles) xtransl_op = xtransl_op # y-translations ytransl_fn = symm.getTranslFn(np.array([[0], [1]])) ytransl_cycles, max_cycle_len_transly = symm.findSiteCycles( ytransl_fn, spin_model.geometry) ytransl_op = spin_model.get_xform_op(ytransl_cycles) ytransl_op = ytransl_op symm_projs, kxs, kys = symm.get2DTranslationProjectors( xtransl_op, max_cycle_len_translx, ytransl_op, max_cycle_len_transly) eig_vals_sectors = [] hfull = spin_model.createH() for ii, proj in enumerate(symm_projs): h_sector = proj * hfull * proj.conj().transpose() eig_vals_sector, eig_vects_sector = spin_model.diagH( h_sector, print_results=True) eig_vals_sectors.append(eig_vals_sector) # why only accurate to 10 decimal places? eigs_all_sectors = np.sort(np.concatenate(eig_vals_sectors)) min_eig_per_site = eigs_all_sectors[0] / spin_model.geometry.nsites self.assertAlmostEqual(min_eig_per_site, -1.124972697436, 12)
def test_translation_symmetry_3by3(self): """ Test translational symmetry for a 3x3 Hubbard system with periodic boundary conditions :return: """ U = 20 * (np.random.rand() - 0.5) t = np.random.rand() gm = geom.Geometry.createSquareGeometry(3, 3, 0, 0, bc1_open=False, bc2_open=False) hubbard = ed_fermions.fermions(gm, U, t, ns=np.array([1, 1])) # no symmetry hamiltonian_full = hubbard.createH(projector=hubbard.n_projector) eig_vals_full, eig_vects_full = hubbard.diagH(hamiltonian_full) # with symmetry xtransl_fn = symm.getTranslFn(np.array([[1], [0]])) xtransl_cycles, max_cycle_len_translx = symm.findSiteCycles( xtransl_fn, hubbard.geometry) xtransl_op = hubbard.n_projector * hubbard.get_xform_op( xtransl_cycles) * hubbard.n_projector.conj().transpose() # y-translations ytransl_fn = symm.getTranslFn(np.array([[0], [1]])) ytransl_cycles, max_cycle_len_transly = symm.findSiteCycles( ytransl_fn, hubbard.geometry) ytransl_op = hubbard.n_projector * hubbard.get_xform_op( ytransl_cycles) * hubbard.n_projector.conj().transpose() symm_projs, kxs, kys = symm.get2DTranslationProjectors( xtransl_op, max_cycle_len_translx, ytransl_op, max_cycle_len_transly) eig_vals_sectors = [] for ii, proj in enumerate(symm_projs): h_sector = hubbard.createH(projector=proj.dot(hubbard.n_projector)) eig_vals_sector, eig_vects_sector = hubbard.diagH(h_sector) eig_vals_sectors.append(eig_vals_sector) # why only accurate to 10 decimal places? eigs_all_sectors = np.sort(np.concatenate(eig_vals_sectors)) max_diff = np.abs(eig_vals_full - eigs_all_sectors).max() self.assertAlmostEqual(max_diff, 0, 10)
def test_get_transformed_sites(self): """ Test function which determines how sites are permuted under the action of a transformation :return: """ geom = ed_geometry.Geometry.createSquareGeometry(8, 1, 0, 0, 0, 1) transl_fn = ed_symmetry.getTranslFn(np.array([[1.0], [0.0]])) sites, trans_sites = ed_symmetry.getTransformedSites(transl_fn, range(0, geom.nsites), geom) sites_expected = np.arange(0, geom.nsites) trans_sites_expected = np.array([1., 2., 3., 4., 5., 6., 7., 0.]) self.assertTrue(np.array_equal(sites, sites_expected)) self.assertTrue(np.array_equal(trans_sites, trans_sites_expected))
def test_get_translation_fn(self): """ Test coordinate translation function :return: """ transl_fn = ed_symmetry.getTranslFn(np.array([[1.0], [0.0]])) x = np.array([3.0]) y = np.array([5.0]) x_transl, y_transl = transl_fn(x, y) x_transl_expected = np.array([4.0]) y_transl_expected = np.array([5.0]) self.assertAlmostEqual(np.linalg.norm(x_transl - x_transl_expected), 0, 14) self.assertAlmostEqual(np.linalg.norm(y_transl - y_transl_expected), 0, 14)
with np.errstate(divide="ignore"): betas = np.divide(1, temps) betas[temps == 0] = np.inf # ints = np.linspace(0, 5, 60) * t ints = np.linspace(0, 5, 5) * t ints = np.concatenate((-np.flip(ints, axis=0), ints[1:])) print("spinless fermions with nearest neighbor interactions") print("nsites = %d, n interactions = %d, ntemps = %d" % (nsites, len(ints), len(temps))) gm = geom.Geometry.createSquareGeometry(nsites, 1, 0, 0, bc1_open=False, bc2_open=True) # translational symmetry xtransl_fn = symm.getTranslFn(np.array([[1], [0]])) xtransl_cycles, max_cycle_len_translx = symm.findSiteCycles(xtransl_fn, gm) # get all symmetry operators at the beginning n_list = np.array([]) k_list = np.array([]) projector_list = [] sf = ed_fermions.fermions(gm, 0, t, us_same_species=0, potentials=0, nspecies=1) # number subspace projectors n_species_op = sf.get_sum_op(sf.n_op, 0, format="boson") n_projs, ns = sf.get_subspace_projs(n_species_op, print_results=False) # translation op xtransl_op_full = sf.get_xform_op(xtransl_cycles)
def test_full_symm_3x3(self): cluster = geom.Geometry.createSquareGeometry(3, 3, 0, 0, bc1_open=False, bc2_open=False) jx = np.random.rand() jy = np.random.rand() jz = np.random.rand() hx = np.random.rand() hy = np.random.rand() hz = np.random.rand() # diagonalize full hamiltonian spin_model = tvi.spinSystem(cluster, jx, jy, jz, hx, hy, hz, use_ryd_detunes=0) hamiltonian_full = spin_model.createH() eig_vals_full, eig_vects_full = spin_model.diagH(hamiltonian_full) xtransl_fn = symm.getTranslFn(np.array([[1], [0]])) xtransl_cycles, max_cycle_len_translx = symm.findSiteCycles( xtransl_fn, spin_model.geometry) tx_op = spin_model.get_xform_op(xtransl_cycles) # y-translations ytransl_fn = symm.getTranslFn(np.array([[0], [1]])) ytransl_cycles, max_cycle_len_transly = symm.findSiteCycles( ytransl_fn, spin_model.geometry) ty_op = spin_model.get_xform_op(ytransl_cycles) # rotation cx, cy = spin_model.geometry.get_center_of_mass() rot_fn = symm.getRotFn(4, cx=cx, cy=cy) rot_cycles, max_cycle_len_rot = symm.findSiteCycles( rot_fn, spin_model.geometry) rot_op = spin_model.get_xform_op(rot_cycles) # reflection # reflection about y-axis refl_fn = symm.getReflFn(np.array([0, 1]), cx=cx, cy=cy) refl_cycles, max_cycle_len_refl = symm.findSiteCycles( refl_fn, spin_model.geometry) refl_op = spin_model.get_xform_op(refl_cycles) symm_projs = symm.getC4V_and_3byb3(rot_op, refl_op, tx_op, ty_op) eig_vals_sectors = [] for ii, proj in enumerate(symm_projs): h_sector = spin_model.createH(projector=proj) eig_vals_sector, eig_vects_sector = spin_model.diagH(h_sector) eig_vals_sectors.append(eig_vals_sector) # why only accurate to 10 decimal places? eigs_all_sectors = np.sort(np.concatenate(eig_vals_sectors)) max_diff = np.abs(eig_vals_full - eigs_all_sectors).max() self.assertAlmostEqual(max_diff, 0, 10)
def test_ising_model_5x5(self): """ Test diagonalization of 5x5 ising model with periodic boundary conditions. reference: J. Phys. A: Math. Gen 33 6683 (2000). "Finite-size scaling in the transverse Ising model on a square lattice" by C J Hamer https://doi.org/10.1088/0305-4470/33/38/303 :return: """ cluster = geom.Geometry.createSquareGeometry(5, 5, 0, 0, bc1_open=False, bc2_open=False) # paper definition of hamiltonian differs by a factor of two from mine jz_critical = -2 * 0.32669593806 h_transverse = 2 * 1.0 spin_model = tvi.spinSystem(cluster, jx=0.0, jy=0.0, jz=jz_critical, hx=h_transverse, hy=0.0, hz=0.0, use_ryd_detunes=0) # symmetry swapping up/down spins spin_swap_op = spin_model.get_swap_up_down_op() # x-translations xtransl_fn = symm.getTranslFn(np.array([[1], [0]])) xtransl_cycles, max_cycle_len_translx = symm.findSiteCycles( xtransl_fn, spin_model.geometry) xtransl_op = spin_model.get_xform_op(xtransl_cycles) xtransl_op = xtransl_op # y-translations ytransl_fn = symm.getTranslFn(np.array([[0], [1]])) ytransl_cycles, max_cycle_len_transly = symm.findSiteCycles( ytransl_fn, spin_model.geometry) ytransl_op = spin_model.get_xform_op(ytransl_cycles) ytransl_op = ytransl_op symm_projs, kxs, kys = symm.get2DTranslationProjectors( xtransl_op, max_cycle_len_translx, ytransl_op, max_cycle_len_transly) eig_vals_sectors = [] full_proj_list = [] hfull = spin_model.createH() for ii, proj in enumerate(symm_projs): spin_swap_proj_op = proj * spin_swap_op * proj.conj().transpose() # char_table = np.array([[1, 1], [1, -1]]) # ccs = [[sp.eye(spin_swap_proj_op.shape[0], format="csr")], [spin_swap_proj_op]] swap_projs, phase = symm.getZnProjectors(spin_swap_proj_op, 2) for jj, sproj in enumerate(swap_projs): full_proj_list.append(sproj * proj) h_sector = sproj * proj * hfull * proj.conj().transpose( ) * sproj.conj().transpose() eig_vals_sector, eig_vects_sector = spin_model.diagH( h_sector, print_results=True) eig_vals_sectors.append(eig_vals_sector) # why only accurate to 10 decimal places? eigs_all_sectors = np.sort(np.concatenate(eig_vals_sectors)) min_eig_per_site = eigs_all_sectors[0] / spin_model.geometry.nsites + 1 self.assertAlmostEqual(min_eig_per_site, -0.064637823298, 11)
0, bc1_open=False, bc2_open=False) parent_geometry.permute_sites(parent_geometry.get_sorting_permutation()) model = tvi.spinSystem(parent_geometry, jx, jy, jz, hx, hy, hz, use_ryd_detunes=False) # x-translation tx_fn = symm.getTranslFn(np.array([[1], [0]])) tx_cycles, ntx = symm.findSiteCycles(tx_fn, model.geometry) tx_op = model.get_xform_op(tx_cycles) # y-translations ty_fn = symm.getTranslFn(np.array([[0], [1]])) ty_cycles, nty = symm.findSiteCycles(ty_fn, model.geometry) ty_op = model.get_xform_op(ty_cycles) # symmetry projectors symm_projs, kxs, kys = symm.get2DTranslationProjectors(tx_op, ntx, ty_op, nty, print_results=True)