def test_lattice_order(): s = site.SpinHalfSite('Sz') # yapf: disable square = lattice.Square(2, 2, s, order='default') order_default = np.array([[0, 0, 0], [0, 1, 0], [1, 0, 0], [1, 1, 0]]) npt.assert_equal(square.order, order_default) square = lattice.Square(4, 3, s, order='snake') order_snake = np.array([[0, 0, 0], [0, 1, 0], [0, 2, 0], [1, 2, 0], [1, 1, 0], [1, 0, 0], [2, 0, 0], [2, 1, 0], [2, 2, 0], [3, 2, 0], [3, 1, 0], [3, 0, 0]]) npt.assert_equal(square.order, order_snake) square = lattice.Square(2, 3, s, order=("standard", (True, False), (1, 0))) order_Fsnake = np.array([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0], [0, 2, 0], [1, 2, 0]]) npt.assert_equal(square.order, order_Fsnake) hc = lattice.Honeycomb(2, 3, s, order='default') order_hc_def = np.array([[0, 0, 0], [0, 1, 0], [0, 2, 0], [0, 0, 1], [0, 1, 1], [0, 2, 1], [1, 0, 0], [1, 1, 0], [1, 2, 0], [1, 0, 1], [1, 1, 1], [1, 2, 1]]) npt.assert_equal(hc.order, order_hc_def) hc = lattice.Honeycomb(2, 3, s, order=('standard', (True, False, False), (0.3, 0.1, -1.))) order_hc_mix = np.array([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0], [0, 2, 0], [1, 2, 0], [0, 0, 1], [1, 0, 1], [1, 1, 1], [0, 1, 1], [0, 2, 1], [1, 2, 1]]) npt.assert_equal(hc.order, order_hc_mix) kag = lattice.Kagome(2, 3, s, order=('grouped', [[1], [0, 2]])) order_kag_gr = np.array([[0, 0, 1], [0, 1, 1], [0, 2, 1], [0, 0, 0], [0, 0, 2], [0, 1, 0], [0, 1, 2], [0, 2, 0], [0, 2, 2], [1, 0, 1], [1, 1, 1], [1, 2, 1], [1, 0, 0], [1, 0, 2], [1, 1, 0], [1, 1, 2], [1, 2, 0], [1, 2, 2]]) npt.assert_equal(kag.order, order_kag_gr)
def test_MultiCouplingModel_explicit(): fermion_lat_cyl = lattice.Square(1, 2, fermion_site, bc='periodic', bc_MPS='infinite') M = model.MultiCouplingModel(fermion_lat_cyl) # create a wired fermionic model with 3-body interactions M.add_onsite(0.125, 0, 'N') M.add_coupling(0.25, 0, 'Cd', 0, 'C', (0, 1)) M.add_coupling(0.25, 0, 'Cd', 0, 'C', (0, -1), 'JW') M.add_coupling(1.5, 0, 'Cd', 0, 'C', (1, 0), 'JW') M.add_coupling(1.5, 0, 'Cd', 0, 'C', (-1, 0), 'JW') M.add_multi_coupling(4., 0, 'N', [(0, 'N', (2, 1))], 'Id') # a full unit cell inbetween! # some wired mediated hopping along the diagonal M.add_multi_coupling(1.125, 0, 'N', other_ops=[(0, 'Cd', (0, 1)), (0, 'C', (1, 0))]) H_mpo = M.calc_H_MPO() W0_new = H_mpo.get_W(0) W1_new = H_mpo.get_W(1) W2_new = H_mpo.get_W(2) Id, JW, N = fermion_site.Id, fermion_site.JW, fermion_site.N Cd, C = fermion_site.Cd, fermion_site.C CdJW = Cd.matvec(JW) JWC = JW.matvec(C) NJW = N.matvec(JW) # yapf: disable W0_ex = [[Id, None, None, CdJW, None, JWC, N, None, None, None, N*0.125], [None, None, Id, None, None, None, None, None, None, None, None], [None, None, None, None, None, None, None, None, None, None, N*4.0], [None, None, None, None, None, None, None, None, None, None, C*1.5], [None, None, None, None, JW, None, None, None, None, None, None], [None, None, None, None, None, None, None, None, None, None, Cd*1.5], [None, Id, None, None, None, None, None, None, None, None, None], [None, None, None, None, None, None, None, None, None, None, C*1.125], [None, None, None, None, None, None, None, JW, None, None, None], [None, None, None, None, None, None, None, None, JW, None, None], [None, None, None, None, None, None, None, None, None, Id, None], [None, None, None, None, None, None, None, None, None, None, Id]] W1_ex = [[Id, None, None, None, None, None, None, None, CdJW, JWC, N, N*0.125], [None, Id, None, None, None, None, None, None, None, None, None, None], [None, None, None, None, None, None, None, None, None, None, None, N*4.0], [None, None, None, JW, NJW, None, None, None, None, None, None, C*0.5], [None, None, None, None, None, None, None, None, None, None, None, C*1.125], [None, None, None, None, None, JW, None, None, None, None, None, Cd*0.5], [None, None, None, None, None, None, Id, CdJW, None, None, None, None], [None, None, None, None, None, None, None, None, None, None, None, C*1.5], [None, None, None, None, None, None, None, None, None, None, None, Cd*1.5], [None, None, Id, None, None, None, None, None, None, None, None, None], [None, None, None, None, None, None, None, None, None, None, None, Id]] # yapf: enable W0_ex = npc.grid_outer(W0_ex, W0_new.legs[:2]) W1_ex = npc.grid_outer(W1_ex, W1_new.legs[:2]) assert npc.norm(W0_new - W0_ex) == 0. # coupling constants: no rounding errors assert npc.norm(W1_new - W1_ex) == 0. # coupling constants: no rounding errors
def test_number_nn(): s = site.SpinHalfSite('Sz') chain = lattice.Chain(2, s) assert chain.number_nearest_neighbors() == 2 assert chain.number_next_nearest_neighbors() == 2 ladd = lattice.Ladder(2, s) assert ladd.number_nearest_neighbors(0) == 3 assert ladd.number_nearest_neighbors(1) == 3 assert ladd.number_next_nearest_neighbors(0) == 2 assert ladd.number_next_nearest_neighbors(1) == 2 square = lattice.Square(2, 2, s) assert square.number_nearest_neighbors() == 4 assert square.number_next_nearest_neighbors() == 4 triang = lattice.Triangular(2, 2, s) assert triang.number_nearest_neighbors() == 6 assert triang.number_next_nearest_neighbors() == 6 hc = lattice.Honeycomb(2, 2, s) assert hc.number_nearest_neighbors(0) == 3 assert hc.number_nearest_neighbors(1) == 3 assert hc.number_next_nearest_neighbors(0) == 6 assert hc.number_next_nearest_neighbors(1) == 6 kag = lattice.Kagome(2, 2, s) assert kag.number_nearest_neighbors(0) == 4 assert kag.number_nearest_neighbors(1) == 4 assert kag.number_nearest_neighbors(2) == 4 assert kag.number_next_nearest_neighbors(0) == 4 assert kag.number_next_nearest_neighbors(1) == 4 assert kag.number_next_nearest_neighbors(2) == 4
def test_ext_flux(): Lx, Ly = 3, 4 lat = lattice.Square(Lx, Ly, fermion_site, bc=['periodic', 'periodic'], bc_MPS='infinite') M = model.CouplingModel(lat) strength = 1.23 strength_array = np.ones((Lx, Ly)) * strength for phi in [0, 2 * np.pi]: # flux shouldn't do anything print("phi = ", phi) for dx in [1, 0], [0, 1], [0, 2], [1, -1], [-2, 2]: print("dx = ", dx) strength_flux = M.coupling_strength_add_ext_flux(strength, [1, 0], [0, phi]) npt.assert_array_almost_equal_nulp(strength_flux, strength_array, 10) for phi in [np.pi / 2, 0.123]: print("phi = ", phi) strength_hop_x = M.coupling_strength_add_ext_flux(strength, [1, 0], [0, phi]) npt.assert_array_almost_equal_nulp(strength_hop_x, strength_array, 10) expect_y_1 = np.array(strength_array, dtype=np.complex128) expect_y_1[:, -1:] = strength * np.exp(1.j * phi) for dx in [[0, 1], [0, -1], [1, -1], [1, 1]]: print("dx = ", dx) strength_hop_y_1 = M.coupling_strength_add_ext_flux(strength, dx, [0, phi]) if dx[1] < 0: npt.assert_array_almost_equal_nulp(strength_hop_y_1, expect_y_1, 10) else: npt.assert_array_almost_equal_nulp(strength_hop_y_1, np.conj(expect_y_1), 10) expect_y_2 = np.array(strength_array, dtype=np.complex128) expect_y_2[:, -2:] = strength * np.exp(1.j * phi) for dx in [[0, 2], [0, -2], [1, 2], [3, 2]]: print("dx = ", dx) strength_hop_y_2 = M.coupling_strength_add_ext_flux(strength, dx, [0, phi]) if dx[1] < 0: npt.assert_array_almost_equal_nulp(strength_hop_y_2, expect_y_2, 10) else: npt.assert_array_almost_equal_nulp(strength_hop_y_2, np.conj(expect_y_2), 10)
def test_pairs(): lattices = [ lattice.Chain(2, None), lattice.Ladder(2, None), lattice.Square(2, 2, None), lattice.Triangular(2, 2, None), lattice.Honeycomb(2, 2, None), lattice.Kagome(2, 2, None) ] for lat in lattices: print(lat.__class__.__name__) found_dist_pairs = lat.find_coupling_pairs(5, 3.) dists = sorted(found_dist_pairs.keys()) for i, name in enumerate([ 'nearest_neighbors', 'next_nearest_neighbors', 'next_next_nearest_neighbors', 'fourth_nearest_neighbors', 'fifth_nearest_neighbors' ]): if name not in lat.pairs: assert i > 2 # all of them should define up to next_next_nearest_neighbors continue print(name) defined_pairs = lat.pairs[name] found_pairs = found_dist_pairs[dists[i]] assert len(defined_pairs) == len(found_pairs) defined_pairs = pairs_with_reversed(defined_pairs) found_pairs = pairs_with_reversed(found_pairs) assert defined_pairs == found_pairs
def test_CouplingModel_multi_couplings_explicit(use_plus_hc, JW): fermion_lat_cyl = lattice.Square(1, 2, fermion_site, bc='periodic', bc_MPS='infinite') M = model.CouplingModel(fermion_lat_cyl) # create a wired fermionic model with 3-body interactions M.add_onsite(0.125, 0, 'N') M.add_coupling(0.25, 0, 'Cd', 0, 'C', (0, 1), plus_hc=use_plus_hc) M.add_coupling(1.5, 0, 'Cd', 0, 'C', (1, 0), JW, plus_hc=use_plus_hc) if not use_plus_hc: M.add_coupling(0.25, 0, 'Cd', 0, 'C', (0, -1), JW) M.add_coupling(1.5, 0, 'Cd', 0, 'C', (-1, 0), JW) # multi_coupling with a full unit cell inbetween the operators! M.add_multi_coupling(4., [('N', (0, 0), 0), ('N', (-2, -1), 0)]) # some wired mediated hopping along the diagonal M.add_multi_coupling(1.125, [('N', (0, 0), 0), ('Cd', (0, 1), 0), ('C', (1, 0), 0)]) H_mpo = M.calc_H_MPO() W0_new = H_mpo.get_W(0) W1_new = H_mpo.get_W(1) Id, JW, N = fermion_site.Id, fermion_site.JW, fermion_site.N Cd, C = fermion_site.Cd, fermion_site.C CdJW = Cd.matvec(JW) # = Cd CJW = C.matvec(JW) # = -C NJW = N.matvec(JW) # print(M.H_MPO_graph._build_grids()) # yapf: disable W0_ex = [[Id, CJW, CdJW, None, N, None, None, None, None, None, N*0.125], [None, None, None, None, None, None, None, None, None, None, Cd*-1.5], [None, None, None, None, None, None, None, None, None, None, C*1.5], [None, None, None, JW, None, None, None, None, None, None, None], [None, None, None, None, None, Id, None, None, None, None, None], [None, None, None, None, None, None, None, None, None, None, C*1.125], [None, None, None, None, None, None, Id, None, None, None, None], [None, None, None, None, None, None, None, JW, None, None, None], [None, None, None, None, None, None, None, None, JW, None, None], [None, None, None, None, None, None, None, None, None, Id, None], [None, None, None, None, None, None, None, None, None, None, N*4.0], [None, None, None, None, None, None, None, None, None, None, Id]] W1_ex = [[Id, None, None, None, None, None, None, CJW, CdJW, N, None, N*0.125], [None, JW, None, None, None, None, None, None, None, None, None, Cd*-0.5], [None, None, JW, NJW, None, None, None, None, None, None, None, C*0.5], [None, None, None, None, None, None, None, None, None, None, None, C*1.125], [None, None, None, None, Id, CdJW, None, None, None, None, None, None], [None, None, None, None, None, None, Id, None, None, None, None, None], [None, None, None, None, None, None, None, None, None, None, None, N*4.0], [None, None, None, None, None, None, None, None, None, None, None, Cd*-1.5], [None, None, None, None, None, None, None, None, None, None, None, C*1.5], [None, None, None, None, None, None, None, None, None, None, Id, None], [None, None, None, None, None, None, None, None, None, None, None, Id]] # yapf: enable W0_ex = npc.grid_outer(W0_ex, W0_new.legs[:2]) W1_ex = npc.grid_outer(W1_ex, W1_new.legs[:2]) assert npc.norm(W0_new - W0_ex) == 0. # coupling constants: no rounding errors assert npc.norm(W1_new - W1_ex) == 0. # coupling constants: no rounding errors
def test_MultiCouplingModel_shift(Lx=3, Ly=3, shift=1): bc = ['periodic', shift] spin_half_square = lattice.Square(Lx, Ly, spin_half_site, bc=bc, bc_MPS='infinite') M = model.MultiCouplingModel(spin_half_square) M.add_coupling(1.2, 0, 'Sz', 0, 'Sz', [1, 0]) M.add_multi_coupling(0.8, [('Sz', [0, 0], 0), ('Sz', [0, 1], 0), ('Sz', [1, 0], 0)]) M.test_sanity() H = M.calc_H_MPO() dims = [W.shape[0] for W in H._W] # check translation invariance of the MPO: at least the dimensions should fit # (the states are differently ordered, so the matrices differ!) for i in range(1, Lx): assert dims[:Lx] == dims[i * Lx:(i + 1) * Lx]
def test_lattice_order(): s = site.SpinHalfSite('Sz') # yapf: disable square = lattice.Square(2, 2, s, 'default') order_default = np.array([[0, 0, 0], [0, 1, 0], [1, 0, 0], [1, 1, 0]]) npt.assert_equal(square.order, order_default) square = lattice.Square(4, 3, s, 'snake') order_snake = np.array([[0, 0, 0], [0, 1, 0], [0, 2, 0], [1, 2, 0], [1, 1, 0], [1, 0, 0], [2, 0, 0], [2, 1, 0], [2, 2, 0], [3, 2, 0], [3, 1, 0], [3, 0, 0]]) npt.assert_equal(square.order, order_snake) square = lattice.Square(2, 3, s, ((1, 0), (True, False))) order_Fsnake = np.array([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0], [0, 2, 0], [1, 2, 0]]) npt.assert_equal(square.order, order_Fsnake) hc = lattice.Honeycomb(2, 3, s, s, 'default') order_hc_def = np.array([[0, 0, 0], [0, 1, 0], [0, 2, 0], [0, 0, 1], [0, 1, 1], [0, 2, 1], [1, 0, 0], [1, 1, 0], [1, 2, 0], [1, 0, 1], [1, 1, 1], [1, 2, 1]]) npt.assert_equal(hc.order, order_hc_def) hc = lattice.Honeycomb(2, 3, s, s, ((0.3, 0.1, -1.), (True, False, False))) order_hc_mix = np.array([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0], [0, 2, 0], [1, 2, 0], [0, 0, 1], [1, 0, 1], [1, 1, 1], [0, 1, 1], [0, 2, 1], [1, 2, 1]]) npt.assert_equal(hc.order, order_hc_mix)
def test_CouplingModel_explicit(): fermion_lat_cyl = lattice.Square(1, 2, fermion_site, bc='periodic', bc_MPS='infinite') M = model.CouplingModel(fermion_lat_cyl) M.add_onsite(0.125, 0, 'N') M.add_coupling(0.25, 0, 'Cd', 0, 'C', (0, 1), None) # auto-determine JW-string! M.add_coupling(0.25, 0, 'Cd', 0, 'C', (0, -1), None) M.add_coupling(1.5, 0, 'Cd', 0, 'C', (1, 0), None) M.add_coupling(1.5, 0, 'Cd', 0, 'C', (-1, 0), None) M.add_coupling(4., 0, 'N', 0, 'N', (-2, -1), None) # a full unit cell inbetween! H_mpo = M.calc_H_MPO() W0_new = H_mpo.get_W(0) W1_new = H_mpo.get_W(1) Id, JW, N = fermion_site.Id, fermion_site.JW, fermion_site.N Cd, C = fermion_site.Cd, fermion_site.C CdJW = Cd.matvec(JW) # = Cd CJW = C.matvec(JW) # = -C # yapf: disable W0_ex = [[Id, CJW, CdJW, N, None, None, None, None, None, N*0.125], [None, None, None, None, None, None, None, None, None, Cd*-1.5], [None, None, None, None, None, None, None, None, None, C*1.5], [None, None, None, None, Id, None, None, None, None, None], [None, None, None, None, None, Id, None, None, None, None], [None, None, None, None, None, None, JW, None, None, None], [None, None, None, None, None, None, None, JW, None, None], [None, None, None, None, None, None, None, None, Id, None], [None, None, None, None, None, None, None, None, None, N*4.0], [None, None, None, None, None, None, None, None, None, Id]] W1_ex = [[Id, None, None, None, None, CJW, CdJW, N, None, N*0.125], [None, JW, None, None, None, None, None, None, None, Cd*-0.5], [None, None, JW, None, None, None, None, None, None, C*0.5], [None, None, None, Id, None, None, None, None, None, None], [None, None, None, None, Id, None, None, None, None, None], [None, None, None, None, None, None, None, None, None, N*4.0], [None, None, None, None, None, None, None, None, None, Cd*-1.5], [None, None, None, None, None, None, None, None, None, C*1.5], [None, None, None, None, None, None, None, None, Id, None], [None, None, None, None, None, None, None, None, None, Id]] # yapf: enable W0_ex = npc.grid_outer(W0_ex, W0_new.legs[:2]) W1_ex = npc.grid_outer(W1_ex, W1_new.legs[:2]) assert npc.norm(W0_new - W0_ex) == 0. # coupling constants: no rounding errors assert npc.norm(W1_new - W1_ex) == 0. # coupling constants: no rounding errors
def test_number_nn(): s = site.SpinHalfSite('Sz') chain = lattice.Chain(2, s) assert chain.number_nearest_neighbors() == 2 assert chain.number_next_nearest_neighbors() == 2 square = lattice.Square(2, 2, s) print(square.number_next_nearest_neighbors()) assert square.number_nearest_neighbors() == 4 assert square.number_next_nearest_neighbors() == 4 hc = lattice.Honeycomb(2, 2, s, s) assert hc.number_nearest_neighbors(0) == 3 assert hc.number_nearest_neighbors(1) == 3 assert hc.number_next_nearest_neighbors(0) == 6 assert hc.number_next_nearest_neighbors(1) == 6
def plot_bc_shift_comparison(name="square_bc_shift"): print(name) Lx, Ly = 4, 3 fig, axes = plt.subplots(1, 3, True, True, figsize=(5, 2)) for shift, ax in zip([1, 0, -1], axes): lat = lattice.Square(Lx, Ly, None, bc=['periodic', shift]) lat.plot_sites(ax) lat.plot_coupling(ax) lat.plot_basis(ax, color='g', linewidth=2.) lat.plot_bc_identified(ax) ax.set_title("shift = " + str(shift)) ax.get_xaxis().set_visible(False) ax.get_yaxis().set_visible(False) axes[0].set_aspect('equal') plt.savefig(name + ".png") plt.savefig(name + ".pdf")
def test_number_nn(): s = site.SpinHalfSite('Sz') chain = lattice.Chain(2, s) assert chain.count_neighbors() == 2 assert chain.count_neighbors(key='next_nearest_neighbors') == 2 ladd = lattice.Ladder(2, s) for u in [0, 1]: assert ladd.count_neighbors(u) == 3 assert ladd.count_neighbors(u, key='next_nearest_neighbors') == 2 square = lattice.Square(2, 2, s) assert square.count_neighbors() == 4 assert square.count_neighbors(key='next_nearest_neighbors') == 4 triang = lattice.Triangular(2, 2, s) assert triang.count_neighbors() == 6 assert triang.count_neighbors(key='next_nearest_neighbors') == 6 hc = lattice.Honeycomb(2, 2, s) for u in [0, 1]: assert hc.count_neighbors(u) == 3 assert hc.count_neighbors(u, key='next_nearest_neighbors') == 6 kag = lattice.Kagome(2, 2, s) for u in [0, 1, 2]: assert kag.count_neighbors(u) == 4 assert kag.count_neighbors(u, key='next_nearest_neighbors') == 4
def test_CouplingModel_multi_couplings_explicit(use_plus_hc, JW): fermion_lat_cyl = lattice.Square(1, 2, fermion_site, bc='periodic', bc_MPS='infinite') M = model.CouplingModel(fermion_lat_cyl) # create a weird fermionic model with 3-body interactions M.add_onsite(0.125, 0, 'N') M.add_coupling(0.25, 0, 'Cd', 0, 'C', (0, 1), plus_hc=use_plus_hc) M.add_coupling(1.5, 0, 'Cd', 0, 'C', (1, 0), JW, plus_hc=use_plus_hc) if not use_plus_hc: M.add_coupling(0.25, 0, 'Cd', 0, 'C', (0, -1), JW) M.add_coupling(1.5, 0, 'Cd', 0, 'C', (-1, 0), JW) # multi_coupling with a full unit cell inbetween the operators! M.add_multi_coupling(4., [('N', (0, 0), 0), ('N', (-2, -1), 0)]) # some weird mediated hopping along the diagonal M.add_multi_coupling(1.125, [('N', (0, 0), 0), ('Cd', (0, 1), 0), ('C', (1, 0), 0)]) H_mpo = M.calc_H_MPO() W0_new = H_mpo.get_W(0) W1_new = H_mpo.get_W(1) Id, JW, N = fermion_site.Id, fermion_site.JW, fermion_site.N Cd, C = fermion_site.Cd, fermion_site.C CdJW = Cd.matvec(JW) # = Cd JWC = JW.matvec(C) # = C NJW = N.matvec(JW) # yapf: disable H_MPO_graph = tenpy.networks.mpo.MPOGraph.from_terms((M.all_onsite_terms(), M.all_coupling_terms(), M.exp_decaying_terms), M.lat.mps_sites(), M.lat.bc_MPS) H_MPO_graph._set_ordered_states() from pprint import pprint pprint(H_MPO_graph._ordered_states) pprint(H_MPO_graph._build_grids()) print(M.all_coupling_terms().to_TermList()) # 0.50000 * Cd JW_0 C_1 + # 1.50000 * Cd JW_0 C_2 + # 0.50000 * JW C_0 Cd_1 + # 1.50000 * JW C_0 Cd_2 + # 1.50000 * Cd JW_1 C_3 + # 1.50000 * JW C_1 Cd_3 + # 4.00000 * N_0 N_5 + # 4.00000 * N_1 N_4 + # 1.12500 * N_0 Cd JW_1 C_2 + # 1.12500 * Cd JW_0 N JW_1 C_3 W0_ex = [[Id, CdJW, JWC, N, None, None, None, None, None, N*0.125], [None, None, None, None, None, Id, None, None, None, None], [None, None, None, None, None, None, JW*1.5, None, None, None], [None, None, None, None, None, None, None, JW*1.5, None, None], [None, None, None, None, Id, None, None, None, None, None], [None, None, None, None, None, None, JW*1.125, None, None, None], [None, None, None, None, None, None, None, None, None, C], [None, None, None, None, None, None, None, None, None, Cd], [None, None, None, None, None, None, None, None, None, N], [None, None, None, None, None, None, None, None, Id, None], [None, None, None, None, None, None, None, None, None, Id]] W1_ex = [[Id, None, CdJW, JWC, N, None, None, None, None, None, N*0.125], [None, None, None, None, None, NJW, JW*1.5, None, None, None, C*0.5], [None, None, None, None, None, None, None, JW*1.5, None, None, Cd*0.5], [None, Id, None, None, None, None, CdJW*1.125, None, None, None, None], [None, None, None, None, None, None, None, None, Id*4., None, None], [None, None, None, None, None, None, None, None, None, Id*4., None], [None, None, None, None, None, None, None, None, None, None, C], [None, None, None, None, None, None, None, None, None, None, Cd], [None, None, None, None, None, None, None, None, None, None, N], [None, None, None, None, None, None, None, None, None, None, Id]] # yapf: enable W0_ex = npc.grid_outer(W0_ex, W0_new.legs[:2]) assert npc.norm(W0_new - W0_ex) == 0. # coupling constants: no rounding errors W1_ex = npc.grid_outer(W1_ex, W1_new.legs[:2]) assert npc.norm(W1_new - W1_ex) == 0. # coupling constants: no rounding errors
def test_CouplingModel_explicit(): fermion_lat_cyl = lattice.Square(1, 2, fermion_site, bc='periodic', bc_MPS='infinite') M = model.CouplingModel(fermion_lat_cyl) M.add_onsite(0.125, 0, 'N') M.add_coupling(0.25, 0, 'Cd', 0, 'C', (0, 1), None) # auto-determine JW-string! M.add_coupling(0.25, 0, 'Cd', 0, 'C', (0, -1), None) M.add_coupling(1.5, 0, 'Cd', 0, 'C', (1, 0), None) M.add_coupling(1.5, 0, 'Cd', 0, 'C', (-1, 0), None) M.add_coupling(4., 0, 'N', 0, 'N', (-2, -1), None) # a full unit cell inbetween! H_mpo = M.calc_H_MPO() W0_new = H_mpo.get_W(0) W1_new = H_mpo.get_W(1) Id, JW, N = fermion_site.Id, fermion_site.JW, fermion_site.N Cd, C = fermion_site.Cd, fermion_site.C CdJW = Cd.matvec(JW) # = Cd JWC = JW.matvec(C) # = C # H_MPO_graph = tenpy.networks.mpo.MPOGraph.from_terms((M.all_onsite_terms(), # M.all_coupling_terms(), # M.exp_decaying_terms), # M.lat.mps_sites(), # M.lat.bc_MPS) # H_MPO_graph._set_ordered_states() # from pprint import pprint # pprint(H_MPO_graph._ordered_states) # print(M.all_coupling_terms().to_TermList()) # [{'IdL': 0, # ('left', 0, 'Cd JW', 'JW'): 1, # ('left', 0, 'JW C', 'JW'): 2, # ('left', 0, 'N', 'Id'): 3, # ('left', 1, 'Cd JW', 'JW'): 4, # ('left', 1, 'JW C', 'JW'): 5, # ('left', 1, 'N', 'Id'): 6, # ('left', 0, 'N', 'Id', 2, 'Id', 'Id'): 7, # ('left', 1, 'N', 'Id', 3, 'Id', 'Id'): 8}, # 'IdR': 9, # {'IdL': 0, # ('left', 0, 'Cd JW', 'JW'): 1, # ('left', 0, 'JW C', 'JW'): 2, # ('left', 0, 'N', 'Id'): 3, # ('left', 1, 'Cd JW', 'JW'): 4, # ('left', 1, 'JW C', 'JW'): 5, # ('left', 1, 'N', 'Id'): 6}, # ('left', 0, 'N', 'Id', 2, 'Id', 'Id'): 7, # ('left', 0, 'N', 'Id', 2, 'Id', 'Id', 4, 'Id', 'Id'): 8, # 'IdR': 9, # 0.50000 * Cd JW_0 C_1 + # 1.50000 * Cd JW_0 C_2 + # 0.50000 * JW C_0 Cd_1 + # 1.50000 * JW C_0 Cd_2 + # 4.00000 * N_0 N_5 + # 1.50000 * Cd JW_1 C_3 + # 1.50000 * JW C_1 Cd_3 + # 4.00000 * N_1 N_4 # yapf: disable W0_ex = [[Id, CdJW, JWC, N, None, None, None, None, None, N*0.125], [None, None, None, None, None, None, None, None, None, C*1.5], [None, None, None, None, None, None, None, None, None, Cd*1.5], [None, None, None, None, None, None, None, Id, None, None], [None, None, None, None, JW, None, None, None, None, None], [None, None, None, None, None, JW, None, None, None, None], [None, None, None, None, None, None, Id, None, None, None], [None, None, None, None, None, None, None, None, Id, None], [None, None, None, None, None, None, None, None, None, N*4.0], [None, None, None, None, None, None, None, None, None, Id]] W1_ex = [[Id, None, None, None, CdJW, JWC, N, None, None, N*0.125], [None, JW, None, None, None, None, None, None, None, C*0.5], [None, None, JW, None, None, None, None, None, None, Cd*0.5], [None, None, None, Id, None, None, None, None, None, None], [None, None, None, None, None, None, None, None, None, C*1.5], [None, None, None, None, None, None, None, None, None, Cd*1.5], [None, None, None, None, None, None, None, None, Id, None], [None, None, None, None, None, None, None, Id, None, None], [None, None, None, None, None, None, None, None, None, N*4.0], [None, None, None, None, None, None, None, None, None, Id]] # yapf: enable W0_ex = npc.grid_outer(W0_ex, W0_new.legs[:2]) W1_ex = npc.grid_outer(W1_ex, W1_new.legs[:2]) assert npc.norm(W0_new - W0_ex)**2 == 0. # coupling constants: no rounding errors assert npc.norm(W1_new - W1_ex)**2 == 0. # coupling constants: no rounding errors