def check_z(L, dtype, Nf=None): J1 = [[2.0 * random() - 1.0, i, i] for i in range(L)] J0 = random() J2p = [[2.0 * J0 - 1.0, i, i + 1] for i in range(L - 1)] J2m = [[-(2.0 * J0 - 1.0), i, i + 1] for i in range(L - 1)] J1p = [[2.0 * J0 - 1.0, i, i + 1] for i in range(L - 1)] J1m = [[-(2.0 * J0 - 1.0), i, i + 1] for i in range(L - 1)] static = [["z|z", J1], ["+-|", J2p], ["-+|", J2m], ["|+-", J1p], ["|-+", J1m]] basis = spinful_fermion_basis_1d(L=L, Nf=Nf) H = hamiltonian(static, [], dtype=dtype, basis=basis, **no_checks) Ns = H.Ns E = H.eigvalsh() basis1 = spinful_fermion_basis_1d(L=L, Nf=Nf, sblock=1) H1 = hamiltonian(static, [], dtype=dtype, basis=basis1, **no_checks) basis2 = spinful_fermion_basis_1d(L=L, Nf=Nf, sblock=-1) H2 = hamiltonian(static, [], dtype=dtype, basis=basis2, **no_checks) E1 = H1.eigvalsh() E2 = H2.eigvalsh() Ez = np.concatenate((E1, E2)) Ez.sort() if norm(Ez - E) > eps(dtype): raise Exception( "test failed z symmetry at L={0:3d} with dtype {1} and Nf={2} {3}". format(L, np.dtype(dtype), Nf, norm(Ez - E)))
def set_basis(self, symmetry=True): """ This method sets the basis for our system, we can use some symmetries of the system to reduce the size of the Hilbert Space """ if symmetry: self.basis = spinful_fermion_basis_1d(self.nx, Nf=(self.nup, self.ndown), sblock=1, kblock=1) else: self.basis = spinful_fermion_basis_1d(self.nx, Nf=(self.nup, self.ndown))
def check_p_z(L, dtype, Nf=None): L_2 = int(L / 2) hr = [2.0 * random() - 1.0 for i in range(L_2)] hi = [hr[i] for i in range(L_2)] hi.reverse() hi.extend(hr) h = [[hi[i], i] for i in range(L)] J = [[1.0, i, i] for i in range(L)] J0 = random() Jp = [[2.0 * J0 - 1.0, i, i + 1] for i in range(L - 1)] Jm = [[-(2.0 * J0 - 1.0), i, i + 1] for i in range(L - 1)] if type(Nf) is tuple: if type(Nf[0]) is int and type(Nf[1]) is int: static = [["z|z", J], ["+-|", Jp], ["-+|", Jm], ["|+-", Jp], ["|-+", Jm], ["z|", h], ["|z", h]] else: static = [["z|z", J], ["+|", h], ["-|", h], ["|+", h], ["|-", h]] basis = spinful_fermion_basis_1d(L=L, Nf=Nf) H = hamiltonian(static, [], dtype=dtype, basis=basis, **no_checks) Ns = H.Ns E = H.eigvalsh() basis1 = spinful_fermion_basis_1d(L=L, Nf=Nf, pblock=1, sblock=1) H1 = hamiltonian(static, [], dtype=dtype, basis=basis1, **no_checks) basis2 = spinful_fermion_basis_1d(L=L, Nf=Nf, pblock=-1, sblock=1) H2 = hamiltonian(static, [], dtype=dtype, basis=basis2, **no_checks) basis3 = spinful_fermion_basis_1d(L=L, Nf=Nf, pblock=1, sblock=-1) H3 = hamiltonian(static, [], dtype=dtype, basis=basis3, **no_checks) basis4 = spinful_fermion_basis_1d(L=L, Nf=Nf, pblock=-1, sblock=-1) H4 = hamiltonian(static, [], dtype=dtype, basis=basis4, **no_checks) E1 = H1.eigvalsh() E2 = H2.eigvalsh() E3 = H3.eigvalsh() E4 = H4.eigvalsh() Epz = np.concatenate((E1, E2, E3, E4)) Epz.sort() if norm(Epz - E) > eps(dtype): raise Exception( "test failed pz symmetry at L={0:3d} with dtype {1} and Nf={2:2d} {3}" .format(L, np.dtype(dtype), Nf, norm(Epz - E)))
def check_t_z(L, dtype, Nf=None): h0 = random() h = [[h0, i] for i in range(L)] J0 = random() J = [[2.0 * J0 - 1.0, i, i] for i in range(L)] J0 = random() Jp = [[2.0 * J0 - 1.0, i, (i + 1) % L] for i in range(L)] Jm = [[-(2.0 * J0 - 1.0), i, (i + 1) % L] for i in range(L)] if type(Nf) is tuple: if type(Nf[0]) is int and type(Nf[1]) is int: static = [["z|z", J], ["+-|", Jp], ["-+|", Jm], ["|+-", Jp], ["|-+", Jm]] else: static = [["z|z", J], ["+|", h], ["-|", h], ["|+", h], ["|-", h]] L_2 = int(L / 2) for kblock in range(-L_2 + 1, L_2 + 1): basisk = spinful_fermion_basis_1d(L=L, Nf=Nf, kblock=kblock) Hk = hamiltonian(static, [], dtype=dtype, basis=basisk, **no_checks) Ns = Hk.Ns Ek = Hk.eigvalsh() basisk1 = spinful_fermion_basis_1d(L=L, Nf=Nf, kblock=kblock, sblock=+1) Hk1 = hamiltonian(static, [], dtype=dtype, basis=basisk1, **no_checks) basisk2 = spinful_fermion_basis_1d(L=L, Nf=Nf, kblock=kblock, sblock=-1) Hk2 = hamiltonian(static, [], dtype=dtype, basis=basisk2, **no_checks) Ek1 = Hk1.eigvalsh() Ek2 = Hk2.eigvalsh() Ekz = np.append(Ek1, Ek2) Ekz.sort() if norm(Ek - Ekz) > eps(dtype): raise Exception( "test failed t z symmetry at L={0:3d} with dtype {1} and Nf={2} {3}" .format(L, np.dtype(dtype), Nf, norm(Ek - Ekz)))
def check_t(L, dtype, Nf=None): hx = random() h = [[hx, i] for i in range(L)] J = random() J = [[J, i, (i + 1) % L] for i in range(L)] J0 = random() J2p = [[2.0 * J0 - 1.0, i, (i + 1) % L] for i in range(L)] J2m = [[-(2.0 * J0 - 1.0), i, (i + 1) % L] for i in range(L)] J0 = random() J1p = [[2.0 * J0 - 1.0, i, (i + 1) % L] for i in range(L)] J1m = [[-(2.0 * J0 - 1.0), i, (i + 1) % L] for i in range(L)] if type(Nf) is tuple: if type(Nf[0]) is int and type(Nf[1]) is int: static = [["z|z", J], ["+-|", J1p], ["-+|", J1m], ["|+-", J2p], ["|-+", J2m], ["z|", h]] else: static = [["z|z", J], ["+|", h], ["-|", h], ["|+", h], ["|-", h]] basis = spinful_fermion_basis_1d(L=L, Nf=Nf) H = hamiltonian(static, [], dtype=dtype, basis=basis, **no_checks) Ns = H.Ns E, _ = H.eigh() #E=H.eigvalsh() # gives ValueError: On entry to CHBRDB parameter number 12 had an illegal value Et = np.array([]) for kblock in range(0, L): basisk = spinful_fermion_basis_1d(L=L, Nf=Nf, kblock=kblock) Hk = hamiltonian(static, [], dtype=dtype, basis=basisk, **no_checks) Et = np.append(Et, Hk.eigvalsh()) Et.sort() if norm(Et - E) > eps(dtype): raise Exception( "test failed t symmetry at L={0:3d} with dtype {1} and Nf={2} {3}". format(L, np.dtype(dtype), Nf, norm(Et - E)))
def check_m(Lmax): for dtype in dtypes: for L in range(2, Lmax + 1): h1 = [[2.0 * random() - 1.0, i] for i in range(L)] h2 = [[2.0 * random() - 1.0, i] for i in range(L)] J1 = [[2.0 * random() - 1.0, i, (i + 1) % L] for i in range(L)] J0 = random() J2p = [[2.0 * J0 - 1.0, i, (i + 1) % L] for i in range(L)] J2m = [[-(2.0 * J0 - 1.0), i, (i + 1) % L] for i in range(L)] J0 = random() J1p = [[2.0 * J0 - 1.0, i, (i + 1) % L] for i in range(L)] J1m = [[-(2.0 * J0 - 1.0), i, (i + 1) % L] for i in range(L)] static = [["z|n", J1], ["+-|", J2p], ["-+|", J2m], ["|+-", J1p], ["|-+", J1m], ["z|", h1], ["|n", h2]] basis = spinful_fermion_basis_1d(L=L) H = hamiltonian(static, [], dtype=dtype, basis=basis, **no_checks) Ns = H.Ns E = H.eigvalsh() Em = [] for Nf, Ndown in product(range(L + 1), range(L + 1)): basis = spinful_fermion_basis_1d(L=L, Nf=(Nf, Ndown)) H = hamiltonian(static, [], dtype=dtype, basis=basis, **no_checks) Etemp = H.eigvalsh() Em.append(Etemp) Em = np.concatenate(Em) Em.sort() if norm(Em - E) > eps(dtype): raise Exception( "test failed m symmetry at L={0:3d} with dtype {1} {2}". format(L, dtype, norm(Em - E)))
def H_int(L, U=4.0): basis = spinful_fermion_basis_1d(L) interact = [[U, i, i] for i in range(L)] # U/2 \sm_j n_{j,up} n_{j,down} pot = [[-U / 2, i] for i in range(L)] # -\mu \sum_j n_{j \sigma}I static = [ ["n|n", interact], # up-down interaction ["n|", pot], # up on-site potention ["|n", pot], # down on-site potent ion ] dynamic = [] no_checks = dict(check_pcon=False, check_symm=False, check_herm=False) H = hamiltonian(static, dynamic, basis=basis, dtype=np.float64, **no_checks) return H
def H_free(L, m=1): basis = spinful_fermion_basis_1d(L) hop_right = [[+1, i, (i + 1) % L] for i in range(L)] # PBC hop_left = [[-1, i, (i + 1) % L] for i in range(L)] # APBC static = [ ["+-|", hop_left], # up hops left ["|+-", hop_left], # down hops left ["-+|", hop_right], # up hops right ["|-+", hop_right], # down hops right ] dynamic = [] no_checks = dict(check_pcon=False, check_symm=False, check_herm=False) H = hamiltonian(static, dynamic, basis=basis, dtype=np.float64, **no_checks) return H
def H_free_apbc(L, μ=0): basis = spinful_fermion_basis_1d(L) hop_right = [[+1, i, i + 1] for i in range(L - 1)] # OBC hop_left = [[-1, i, i + 1] for i in range(L - 1)] # OBC hop_right.append([-1, L - 1, 0]) # APBC hop_left.append([+1, L - 1, 0]) # APBC pot = [[-μ, i] for i in range(L)] # -\mu \sum_j n_{j \sigma}I # print(hop_right) static = [ ["+-|", hop_left], # up hops left ["|+-", hop_left], # down hops left ["-+|", hop_right], # up hops right ["|-+", hop_right], # down hops right ["n|", pot], # up on-site potential ["|n", pot], # down on-site potential ] dynamic = [] no_checks = dict(check_pcon=False, check_symm=False, check_herm=False) H = hamiltonian(static, dynamic, basis=basis, dtype=np.float64, **no_checks) return H
quspin_path = os.path.join(os.getcwd(), "../../") sys.path.insert(0, quspin_path) # from quspin.operators import hamiltonian # Hamiltonians and operators from quspin.basis import spinful_fermion_basis_1d # Hilbert space spinful fermion basis import numpy as np # generic math functions # ##### define model parameters ##### L = 6 # system size J = 1.0 # hopping strength U = np.sqrt(2) # onsite interaction strength # ##### construct basis at half-filling in the 0-total momentum and +1-parity sector basis = spinful_fermion_basis_1d(L=L, Nf=(L // 2, L // 2), a=1, kblock=0, sblock=1) print(basis) # ##### define PBC site-coupling lists for operators # define site-coupling lists hop_right = [[-J, i, (i + 1) % L] for i in range(L)] # hopping to the right PBC hop_left = [[J, i, (i + 1) % L] for i in range(L)] # hopping to the left PBC int_list = [[U, i, i] for i in range(L)] # onsite interaction # static and dynamic lists static = [ ["+-|", hop_left], # up hop left ["-+|", hop_right], # up hop right ["|+-", hop_left], # down hop left
import sys, os qspin_path = os.path.join(os.getcwd(), "../") sys.path.insert(0, qspin_path) from quspin.basis import spinless_fermion_basis_1d, spinful_fermion_basis_1d, tensor_basis import numpy as np import scipy.sparse as sp from functools import reduce L = 4 np.random.seed(2) spinful_basis = spinful_fermion_basis_1d(L, Nf=(2, 2)) spinless_basis = spinless_fermion_basis_1d(L, Nf=2) test_basis = tensor_basis(spinless_basis, spinless_basis) psi = np.random.uniform(-1, 1, size=(spinful_basis.Ns, )) + 1j * np.random.uniform( -1, 1, size=(spinful_basis.Ns, )) psi /= np.linalg.norm(psi) sp_psi = sp.csr_matrix(psi).T psis = np.random.uniform( -1, 1, size=(spinful_basis.Ns, spinful_basis.Ns)) + 1j * np.random.uniform( -1, 1, size=(spinful_basis.Ns, spinful_basis.Ns)) psis /= np.linalg.norm(psis, axis=0)
def check_t_p(L, dtype, Nf=None): hx = random() h = [[hx, i] for i in range(L)] J = random() J = [[J, i, i] for i in range(L)] J0 = random() J2p = [[2.0 * J0 - 1.0, i, (i + 1) % L] for i in range(L)] J2m = [[-(2.0 * J0 - 1.0), i, (i + 1) % L] for i in range(L)] J0 = random() J1p = [[2.0 * J0 - 1.0, i, (i + 1) % L] for i in range(L)] J1m = [[-(2.0 * J0 - 1.0), i, (i + 1) % L] for i in range(L)] if type(Nf) is tuple: if type(Nf[0]) is int and type(Nf[1]) is int: static = [["z|z", J], ["+-|", J1p], ["-+|", J1m], ["|+-", J2p], ["|-+", J2m], ["z|", h]] else: static = [["z|z", J], ["+|", h], ["-|", h], ["|+", h], ["|-", h]] L_2 = int(L / 2) if dtype is np.float32: kdtype = np.complex64 elif dtype is np.float64: kdtype = np.complex128 else: kdtype = dtype for kblock in range(-L_2 + 1, 0): basisk = spinful_fermion_basis_1d(L=L, kblock=kblock) Hk = hamiltonian(static, [], dtype=kdtype, basis=basisk, **no_checks) Ns = Hk.Ns Ek = Hk.eigvalsh() basisk1 = spinful_fermion_basis_1d(L=L, kblock=kblock, pblock=+1) Hk1 = hamiltonian(static, [], dtype=dtype, basis=basisk1, **no_checks) basisk2 = spinful_fermion_basis_1d(L=L, kblock=kblock, pblock=-1) Hk2 = hamiltonian(static, [], dtype=dtype, basis=basisk2, **no_checks) Ek1 = Hk1.eigvalsh() Ek2 = Hk2.eigvalsh() if norm(Ek - Ek1) > eps(dtype): raise Exception( "test failed t p+ symmetry at L={0:3d} kblock={1:3d} with dtype {2} and Nf={3} {4}" .format(L, kblock, np.dtype(dtype), Nf, norm(Ek - Ek1))) if norm(Ek - Ek2) > eps(dtype): raise Exception( "test failed t p- symmetry at L={0:3d} kblock={1:3d} with dtype {2} and Nf={3} {4}" .format(L, kblock, np.dtype(dtype), Nf, norm(Ek - Ek2))) basisk = spinful_fermion_basis_1d(L=L, Nf=Nf, kblock=0) Hk = hamiltonian(static, [], dtype=kdtype, basis=basisk, **no_checks) Ns = Hk.Ns Ek = Hk.eigvalsh() basisk1 = spinful_fermion_basis_1d(L=L, Nf=Nf, kblock=0, pblock=+1) Hk1 = hamiltonian(static, [], dtype=dtype, basis=basisk1, **no_checks) basisk2 = spinful_fermion_basis_1d(L=L, Nf=Nf, kblock=0, pblock=-1) Hk2 = hamiltonian(static, [], dtype=dtype, basis=basisk2, **no_checks) Ek1 = Hk1.eigvalsh() Ek2 = Hk2.eigvalsh() Ekp = np.append(Ek1, Ek2) Ekp.sort() if norm(Ek - Ekp) > eps(dtype): raise Exception( "test failed t p symmetry at L={0:3d} kblock={1:3d} with dtype {2} and Nf={3} {4}" .format(L, 0, np.dtype(dtype), Nf, norm(Ek - Ekp))) if L % 2 == 0: for kblock in range(1, L_2): basisk = spinful_fermion_basis_1d(L=L, Nf=Nf, kblock=kblock) Hk = hamiltonian(static, [], dtype=kdtype, basis=basisk, **no_checks) Ns = Hk.Ns Ek = Hk.eigvalsh() basisk1 = spinful_fermion_basis_1d(L=L, Nf=Nf, kblock=kblock, pblock=+1) Hk1 = hamiltonian(static, [], dtype=dtype, basis=basisk1, **no_checks) basisk2 = spinful_fermion_basis_1d(L=L, Nf=Nf, kblock=kblock, pblock=-1) Hk2 = hamiltonian(static, [], dtype=dtype, basis=basisk2, **no_checks) Ek1 = Hk1.eigvalsh() Ek2 = Hk2.eigvalsh() if norm(Ek - Ek1) > eps(dtype): raise Exception( "test failed t p+ symmetry at L={0:3d} kblock={1:3d} with dtype {2} and Nf={3} {4}" .format(L, kblock, np.dtype(dtype), Nf, norm(Ek - Ek1))) if norm(Ek - Ek2) > eps(dtype): raise Exception( "test failed t p- symmetry at L={0:3d} kblock={1:3d} with dtype {2} and Nf={3} {4}" .format(L, kblock, np.dtype(dtype), Nf, norm(Ek - Ek1))) basisk = spinful_fermion_basis_1d(L=L, Nf=Nf, kblock=L_2) Hk = hamiltonian(static, [], dtype=kdtype, basis=basisk, **no_checks) Ns = Hk.Ns Ek = Hk.eigvalsh() basisk1 = spinful_fermion_basis_1d(L=L, Nf=Nf, kblock=L_2, pblock=+1) Hk1 = hamiltonian(static, [], dtype=dtype, basis=basisk1, **no_checks) basisk2 = spinful_fermion_basis_1d(L=L, Nf=Nf, kblock=L_2, pblock=-1) Hk2 = hamiltonian(static, [], dtype=dtype, basis=basisk2, **no_checks) Ek1 = Hk1.eigvalsh() Ek2 = Hk2.eigvalsh() Ekp = np.append(Ek1, Ek2) Ekp.sort() if norm(Ek - Ekp) > eps(dtype): raise Exception( "test failed t p symmetry at L={0:3d} kblock={1:3d} with dtype {2} and Nf={3} {4}" .format(L, int(L / 2), np.dtype(dtype), Nf, norm(Ek - Ekp))) else: for kblock in range(1, L_2 + 1): basisk = spinful_fermion_basis_1d(L=L, Nf=Nf, kblock=kblock) Hk = hamiltonian(static, [], dtype=kdtype, basis=basisk, **no_checks) Ns = Hk.Ns Ek = Hk.eigvalsh() basisk1 = spinful_fermion_basis_1d(L=L, Nf=Nf, kblock=kblock, pblock=+1) Hk1 = hamiltonian(static, [], dtype=dtype, basis=basisk1, **no_checks) basisk2 = spinful_fermion_basis_1d(L=L, Nf=Nf, kblock=kblock, pblock=-1) Hk2 = hamiltonian(static, [], dtype=dtype, basis=basisk2, **no_checks) Ek1 = Hk1.eigvalsh() Ek2 = Hk2.eigvalsh() if norm(Ek - Ek1) > eps(dtype): raise Exception( "test failed t p+ symmetry at L={0:3d} kblock={1:3d} with dtype {2} and Nf={3} {4}" .format(L, kblock, np.dtype(dtype), Nf, norm(Ek - Ek1))) if norm(Ek - Ek2) > eps(dtype): raise Exception( "test failed t p- symmetry at L={0:3d} kblock={1:3d} with dtype {2} and Nf={3} {4}" .format(L, kblock, np.dtype(dtype), Nf, norm(Ek - Ek2)))
Jm.extend([[-1.0, i, tr.T_y[i]] for i in range(N)]) U_onsite = [[1.0, i, i] for i in range(N)] operator_list_0 = [["+-|", Jp], ["-+|", Jm], ["|+-", Jp], ["|-+", Jm]] operator_list_1 = [["n|n", U_onsite]] operator_dict = dict(H0=operator_list_0, H1=operator_list_1) basis_f = spinless_fermion_basis_1d(L=N, Nf=2) basis_1 = tensor_basis(basis_f, basis_f) basis_f = spinless_fermion_basis_general(N, Nf=2) basis_2 = tensor_basis(basis_f, basis_f) basis_3 = spinful_fermion_basis_1d(L=N, Nf=(2, 2)) basis_4 = spinful_fermion_basis_general(N, Nf=(2, 2)) basis_dict = dict(tensored_spinless_fermion_basis_1d=basis_1, spinful_fermion_basis_1d=basis_3, tensored_spinless_fermion_basis_general=basis_2, spinful_fermion_basis_general=basis_4) for basis_name, basis in basis_dict.items(): H_U = quantum_operator(operator_dict, basis=basis, dtype=np.float64, check_pcon=False, check_symm=False, check_herm=False)
subsysA_mod = [subsysA[0] % L, subsysA[1] % L] if np.min(subsysA) <= L - 1 and np.max(subsysA) > L - 1: sub_sys_A = [[ subsysA_mod[0], ], [subsysA_mod[1]]] elif np.max(subsysA) <= L - 1: sub_sys_A = [subsysA_mod, []] elif np.min(sub_sys_A) > L - 1: sub_sys_A = [[], subsysA_mod] J_nn_p_full = [[+1.0] + subsysA_mod] J_nn_n_full = [[-1.0] + subsysA_mod] if np.min(subsysA) <= L - 1 and np.max(subsysA) > L - 1: basis_red = spinful_fermion_basis_1d(1, ) J_nn_p_red = [[+1.0, 0, 0]] J_nn_n_red = [[-1.0, 0, 0]] static_full = [['+|+', J_nn_p_full], ['-|-', J_nn_n_full]] static_red = [['+|+', J_nn_p_red], ['-|-', J_nn_n_red]] elif np.max(subsysA) <= L - 1: basis_red = spinless_fermion_basis_1d(2, ) J_nn_p_red = [[+1.0, 0, 1]] J_nn_n_red = [[-1.0, 0, 1]] static_full = [['++|', J_nn_p_full], ['--|', J_nn_n_full]]
for L in [6, 7]: # symmetry-free basis_1 = spin_basis_1d(L=L, Nup=range(0, L, 2)) basis_1g = spin_basis_general(N=L, Nup=range(0, L, 2)) basis_2 = boson_basis_1d(L=L, Nb=range(0, L, 2)) basis_2g = boson_basis_general(N=L, Nb=range(0, L, 2)) basis_3 = spinless_fermion_basis_1d(L=L, Nf=range(0, L, 2)) basis_3g = spinless_fermion_basis_general(N=L, Nf=range(0, L, 2)) basis_4 = spinful_fermion_basis_1d(L=L, Nf=product(range(0, L, 2), range(0, L, 2))) basis_4g = spinful_fermion_basis_general(N=L, Nf=product( range(0, L, 2), range(0, L, 2))) # symmetry-ful t = (np.arange(L) + 1) % L basis_1 = spin_basis_1d(L=L, Nup=range(0, L, 2), kblock=0) basis_1g = spin_basis_general(N=L, Nup=range(0, L, 2), kblock=(t, 0)) basis_2 = boson_basis_1d(L=L, Nb=range(0, L, 2), kblock=0) basis_2g = boson_basis_general(N=L, Nb=range(0, L, 2), kblock=(t, 0))
retstep=True) """load original data""" # loadfile = '../Basic/Data/expectations:{}sites-{}up-{}down-{}t0-{}U-{}cycles-{}steps-{}pbc.npz'.format(L, N_up, N_down, # t0, U, cycles, # n_steps, pbc) # expectations = dict(np.load(loadfile)) # print(expectations.keys()) # J_field=expectations["current"] # phi_original=expectations["phi"] # neighbour=-expectations["neighbour"]/lat.t """Interpolates the current to be tracked.""" # J_target = interp1d(times, J_scale*J_field, fill_value='extrapolate', bounds_error=False, kind='cubic') """create basis""" # build spinful fermions basis. It's possible to specify certain symmetry sectors here, but I'm not going to touch that # until I understand it better. basis = spinful_fermion_basis_1d(L_track, Nf=(N_up, N_down)) # basis = spinful_fermion_basis_1d(L_track, Nf=(N_up, N_down),sblock=1) basis = spinful_fermion_basis_1d(L, Nf=(N_up, N_down), a=1, kblock=1) # """building model""" # define site-coupling lists int_list = [[lat_track.U, i, i] for i in range(L_track)] # onsite interaction # create static lists # Note that the pipe determines the spinfulness of the operator. | on the left corresponds to down spin, | on the right # is for up spin. For the onsite interaction here, we have: static_Hamiltonian_list = [ ["n|n", int_list], # onsite interaction ]
nx=L, ny=0, U=U, t=t0, pbc=pbc, gamma=gamma, mu=mu) """Define e^i*phi for later dynamics. Important point here is that for later implementations of tracking, we will pass phi as a global variable that will be modified as appropriate during evolution""" """set up parameters for saving expectations later""" outfile = './Data/Exact/expectations:{}sites-{}up-{}down-{}t0-{}U-{}t_max-{}steps-{}gamma-{}mu-{}pbc.npz'.format( L, N_up, N_down, t0, U, t_max, n_steps, gamma, mu, pbc) """create basis""" # build spinful fermions basis. Note that the basis _cannot_ have number conservation as the leads inject and absorb # fermions. This is frankly a massive pain, and the only gain we get basis = spinful_fermion_basis_1d(L) #no symmetries # basis = spinful_fermion_basis_1d(L, sblock=1) # spin inversion symmetry # basis = spinful_fermion_basis_1d(L,Nf=(N_up, N_down)) #number symmetry # basis = spinful_fermion_basis_1d(L, Nf=(N_up, N_down),sblock=1) #parity and spin inversion symmetry # basis = spinful_fermion_basis_1d(L, Nf=(N_up, N_down),a=1,kblock=1) #translation symmetry print('Hilbert space size: {0:d}.\n'.format(basis.Ns)) """building model""" # define site-coupling lists int_list = [[lat.U, i, i] for i in range(L)] # onsite interaction # create static lists # Note that the pipe determines the spinfulness of the operator. | on the left corresponds to down spin, | on the right # is for up spin. For the onsite interaction here, we have: # add dynamic lists hop_right = [[lat.t, i, i + 1]
n_boot = 100 # number of bootstrap samples to calculate error # physical parameters L = 8 # system size N = L//2 # number of particles N_up = N//2 + N % 2 # number of fermions with spin up N_down = N//2 # number of fermions with spin down w_list = [1.0,4.0,10.0] # disorder strength J = 1.0 # hopping strength U = 5.0 # interaction strength # range in time to evolve system start,stop,num=0.0,35.0,101 t = np.linspace(start,stop,num=num,endpoint=True) # ###### create the basis # build spinful fermions basis basis = spinful_fermion_basis_1d(L,Nf=(N_up,N_down)) # ##### create model # define site-coupling lists hop_right = [[-J,i,i+1] for i in range(L-1)] # hopping to the right OBC hop_left = [[J,i,i+1] for i in range(L-1)] # hopping to the left OBC int_list = [[U,i,i] for i in range(L)] # onsite interaction # site-coupling list to create the sublattice imbalance observable sublat_list = [[(-1.0)**i/N,i] for i in range(0,L)] # create static lists operator_list_0 = [ ["+-|", hop_left], # up hop left ["-+|", hop_right], # up hop right ["|+-", hop_left], # down hop left ["|-+", hop_right], # down hop right ["n|n", int_list], # onsite interaction
def check_t_pz(L, dtype, Nf=None): h0 = random() h = [[h0, i] for i in range(L)] J = [[1.0, i, i] for i in range(L)] J0 = random() Jp = [[2.0 * J0 - 1.0, i, (i + 1) % L] for i in range(L)] Jm = [[-(2.0 * J0 - 1.0), i, (i + 1) % L] for i in range(L)] static = [["z|z", J], ["+-|", Jp], ["-+|", Jm], ["|+-", Jp], ["|-+", Jm], ["z|", h], ["|z", h]] if dtype is np.float32: kdtype = np.complex64 elif dtype is np.float64: kdtype = np.complex128 else: kdtype = dtype a = 2 L_2 = int(L / (a * 2)) for kblock in range(-L_2 + 1, 0): basisk = spinful_fermion_basis_1d(L=L, Nf=Nf, kblock=kblock, a=a) Hk = hamiltonian(static, [], dtype=kdtype, basis=basisk, **no_checks) Ns = Hk.Ns Ek = Hk.eigvalsh() basisk1 = spinful_fermion_basis_1d(L=L, Nf=Nf, kblock=kblock, a=a, psblock=+1) Hk1 = hamiltonian(static, [], dtype=dtype, basis=basisk1, **no_checks) basisk2 = spinful_fermion_basis_1d(L=L, Nf=Nf, kblock=kblock, a=a, psblock=-1) Hk2 = hamiltonian(static, [], dtype=dtype, basis=basisk2, **no_checks) Ek1 = Hk1.eigvalsh() Ek2 = Hk2.eigvalsh() if norm(Ek - Ek1) > eps(dtype): raise Exception( "test failed t pz+ symmetry at L={0:3d} kblock={1:3d} with dtype {2} and Nf={3} {4}" .format(L, kblock, np.dtype(dtype), Nf, norm(Ek - Ek1))) if norm(Ek - Ek2) > eps(dtype): raise Exception( "test failed t pz- symmetry at L={0:3d} kblock={1:3d} with dtype {2} and Nf={3} {4}" .format(L, kblock, np.dtype(dtype), Nf, norm(Ek - Ek2))) basisk = spinful_fermion_basis_1d(L=L, Nf=Nf, kblock=0, a=a) Hk = hamiltonian(static, [], dtype=kdtype, basis=basisk, **no_checks) Ns = Hk.Ns Ek = Hk.eigvalsh() basisk1 = spinful_fermion_basis_1d(L=L, Nf=Nf, kblock=0, a=a, psblock=+1) Hk1 = hamiltonian(static, [], dtype=dtype, basis=basisk1, **no_checks) basisk2 = spinful_fermion_basis_1d(L=L, Nf=Nf, kblock=0, a=a, psblock=-1) Hk2 = hamiltonian(static, [], dtype=dtype, basis=basisk2, **no_checks) Ek1 = Hk1.eigvalsh() Ek2 = Hk2.eigvalsh() Ekp = np.append(Ek1, Ek2) Ekp.sort() if norm(Ek - Ekp) > eps(dtype): raise Exception( "test failed t pz symmetry at L={0:3d} kblock={1:3d} with dtype {2} and Nf={3} {4}" .format(L, 0, np.dtype(dtype), Nf, norm(Ek - Ekp))) if ((L / a) % 2 == 0): for kblock in range(1, L_2): basisk = spinful_fermion_basis_1d(L=L, Nf=Nf, kblock=kblock, a=a) Hk = hamiltonian(static, [], dtype=kdtype, basis=basisk, **no_checks) Ns = Hk.Ns Ek = Hk.eigvalsh() basisk1 = spinful_fermion_basis_1d(L=L, Nf=Nf, kblock=kblock, a=a, psblock=+1) Hk1 = hamiltonian(static, [], dtype=dtype, basis=basisk1, **no_checks) basisk2 = spinful_fermion_basis_1d(L=L, Nf=Nf, kblock=kblock, a=a, psblock=-1) Hk2 = hamiltonian(static, [], dtype=dtype, basis=basisk2, **no_checks) Ek1 = Hk1.eigvalsh() Ek2 = Hk2.eigvalsh() if norm(Ek - Ek1) > eps(dtype): raise Exception( "test failed t pz+ symmetry at L={0:3d} kblock={1:3d} with dtype {2} and Nup={3} {4}" .format(L, kblock, np.dtype(dtype), Nup, norm(Ek - Ek1))) if norm(Ek - Ek2) > eps(dtype): raise Exception( "test failed t pz- symmetry at L={0:3d} kblock={1:3d} with dtype {2} and Nup={3} {4}" .format(L, kblock, np.dtype(dtype), Nup, norm(Ek - Ek2))) basisk = spinful_fermion_basis_1d(L=L, Nf=Nf, kblock=L_2, a=a) Hk = hamiltonian(static, [], dtype=kdtype, basis=basisk, **no_checks) Ns = Hk.Ns Ek = Hk.eigvalsh() basisk1 = spinful_fermion_basis_1d(L=L, Nf=Nf, kblock=L_2, a=a, psblock=+1) Hk1 = hamiltonian(static, [], dtype=dtype, basis=basisk1, **no_checks) basisk2 = spinful_fermion_basis_1d(L=L, Nf=Nf, kblock=L_2, a=a, psblock=-1) Hk2 = hamiltonian(static, [], dtype=dtype, basis=basisk2, **no_checks) Ek1 = Hk1.eigvalsh() Ek2 = Hk2.eigvalsh() Ekp = np.append(Ek1, Ek2) Ekp.sort() if norm(Ek - Ekp) > eps(dtype): raise Exception( "test failed t pz symmetry at L={0:3d} kblock={1:3d} with dtype {2} and Nup={3} {4}" .format(L, int(L / 2), np.dtype(dtype), Nup, norm(Ek - Ekp))) else: for kblock in range(1, L_2 + 1): basisk = spinful_fermion_basis_1d(L=L, Nf=Nf, kblock=kblock, a=a) Hk = hamiltonian(static, [], dtype=kdtype, basis=basisk, **no_checks) Ns = Hk.Ns Ek = Hk.eigvalsh() basisk1 = spinful_fermion_basis_1d(L=L, Nf=Nf, kblock=kblock, a=a, psblock=+1) Hk1 = hamiltonian(static, [], dtype=dtype, basis=basisk1, **no_checks) basisk2 = spinful_fermion_basis_1d(L=L, Nf=Nf, kblock=kblock, a=a, psblock=-1) Hk2 = hamiltonian(static, [], dtype=dtype, basis=basisk2, **no_checks) Ek1 = Hk1.eigvalsh() Ek2 = Hk2.eigvalsh() if norm(Ek - Ek1) > eps(dtype): raise Exception( "test failed t pz+ symmetry at L={0:3d} kblock={1:3d} with dtype {2} and Nf={3} {4}" .format(L, kblock, np.dtype(dtype), Nf, norm(Ek - Ek1))) if norm(Ek - Ek2) > eps(dtype): raise Exception( "test failed t pz- symmetry at L={0:3d} kblock={1:3d} with dtype {2} and Nf={3} {4}" .format(L, kblock, np.dtype(dtype), Nf, norm(Ek - Ek2)))
"""instantiate parameters with proper unit scaling""" lat = hhg(field=field, nup=N_up, ndown=N_down, nx=L, ny=0, U=U, t=t0, F0=F0, a=a, pbc=pbc) """System Evolution Time""" cycles = 10 # time in cycles of field frequency n_steps = 2000 start = 0 stop = cycles / lat.freq times, delta = np.linspace(start, stop, num=n_steps, endpoint=True, retstep=True) """set up parameters for saving expectations later""" parameters = f'-{L}sites-{t0}t0-{U}U-{a}a-{field}field-{F0}amplitude-{cycles}cycles-{n_steps}steps-{pbc}pbc' """create basis""" basis = spinful_fermion_basis_1d(L, Nf=(N_up, N_down), sblock=1, kblock=1) """Create static part of hamiltonian - the interaction b/w electrons""" int_list = [[1.0, i, i] for i in range(L)] static_Hamiltonian_list = [ ["n|n", int_list] # onsite interaction ] # n_j,up n_j,down onsite = hamiltonian(static_Hamiltonian_list, [], basis=basis) """Create dynamic part of hamiltonian - composed of a left and a right hopping parts""" hop = [[1.0, i, i+1] for i in range(L-1)] if lat.pbc: hop.append([1.0, L-1, 0]) no_checks = dict(check_pcon=False, check_symm=False, check_herm=False) # c^dag_j,sigma c_j+1,sigma
def check_t_p_z(L, dtype, Nf=None): h0 = random() h = [[h0, i] for i in range(L)] J = [[1.0, i, i] for i in range(L)] J0 = random() Jp = [[2.0 * J0 - 1.0, i, (i + 1) % L] for i in range(L)] Jm = [[-(2.0 * J0 - 1.0), i, (i + 1) % L] for i in range(L)] if type(Nf) is tuple: if type(Nf[0]) is int and type(Nf[1]) is int: static = [["z|z", J], ["+-|", Jp], ["-+|", Jm], ["|+-", Jp], ["|-+", Jm], ["z|", h], ["|z", h]] else: static = [["z|z", J], ["+|", h], ["-|", h], ["|+", h], ["|-", h]] L_2 = int(L / 2) for kblock in range(-L_2 + 1, L_2 + 1): # print(kblock) basisk1 = spinful_fermion_basis_1d(L=L, Nf=Nf, kblock=kblock, pblock=+1) Hkp1 = hamiltonian(static, [], dtype=dtype, basis=basisk1, **no_checks) basisk2 = spinful_fermion_basis_1d(L=L, Nf=Nf, kblock=kblock, pblock=-1) Hkp2 = hamiltonian(static, [], dtype=dtype, basis=basisk2, **no_checks) Ns = Hkp1.Ns Ekp1 = Hkp1.eigvalsh() Ekp2 = Hkp2.eigvalsh() basisk11 = spinful_fermion_basis_1d(L=L, Nf=Nf, kblock=kblock, pblock=+1, sblock=+1) Hkpz11 = hamiltonian(static, [], dtype=dtype, basis=basisk11, **no_checks) basisk12 = spinful_fermion_basis_1d(L=L, Nf=Nf, kblock=kblock, pblock=+1, sblock=-1) Hkpz12 = hamiltonian(static, [], dtype=dtype, basis=basisk12, **no_checks) Ekpz11 = Hkpz11.eigvalsh() Ekpz12 = Hkpz12.eigvalsh() Ekpz1 = np.concatenate((Ekpz11, Ekpz12)) Ekpz1.sort() basisk21 = spinful_fermion_basis_1d(L=L, Nf=Nf, kblock=kblock, pblock=-1, sblock=+1) Hkpz21 = hamiltonian(static, [], dtype=dtype, basis=basisk21, **no_checks) basisk22 = spinful_fermion_basis_1d(L=L, Nf=Nf, kblock=kblock, pblock=-1, sblock=-1) Hkpz22 = hamiltonian(static, [], dtype=dtype, basis=basisk22, **no_checks) Ekpz21 = Hkpz21.eigvalsh() Ekpz22 = Hkpz22.eigvalsh() Ekpz2 = np.concatenate((Ekpz21, Ekpz22)) Ekpz2.sort() # print(basisk1) # print(basisk11) # print(basisk12) #exit() if norm(Ekp1 - Ekpz1) > eps(dtype): raise Exception( "test failed t z p+ symmetry at L={0:3d} kblock={1:3d} with dtype {2} and Nf={3} {4}" .format(L, kblock, np.dtype(dtype), Nf, norm(Ekp1 - Ekpz1))) if norm(Ekp2 - Ekpz2) > eps(dtype): raise Exception( "test failed t z p- symmetry at L={0:3d} kblock={1:3d} with dtype {2} and Nf={3} {4}" .format(L, kblock, np.dtype(dtype), Nf, norm(Ekp2 - Ekpz2))) if (kblock not in [0, L_2]): if norm(Ekp2 - Ekpz1) > eps(dtype): raise Exception( "test failed t z p+ symmetry at L={0:3d} kblock={1:3d} with dtype {2} and Nf={3} {4}" .format(L, kblock, np.dtype(dtype), Nf, norm(Ekp2 - Ekpz1))) if norm(Ekp1 - Ekpz2) > eps(dtype): raise Exception( "test failed t z p- symmetry at L={0:3d} kblock={1:3d} with dtype {2} and Nf={3} {4}" .format(L, kblock, np.dtype(dtype), Nf, norm(Ekp1 - Ekpz2)))
def __init__(self, perimeter_params, cycles): self.basis = spinful_fermion_basis_1d(perimeter_params.nx, Nf=(perimeter_params.nup, perimeter_params.ndown)) self.int_list = [[perimeter_params.U, i, i] for i in range(perimeter_params.nx)] self.sHl = [ ["n|n", self.int_list], ] # onsite interaction self.hop_right = [[perimeter_params.t, i, i + 1] for i in range(perimeter_params.nx - 1) ] # hopping to the right OBC self.hop_left = [[-perimeter_params.t, i, i + 1] for i in range(perimeter_params.nx - 1) ] # hopping to the left OBC if perimeter_params.pbc: self.hop_right.append( [perimeter_params.t, perimeter_params.nx - 1, 0]) self.hop_left.append( [-perimeter_params.t, perimeter_params.nx - 1, 0]) no_checks = dict(check_pcon=False, check_symm=False, check_herm=False) hop_left_op = hamiltonian( [["+-|", self.hop_left], ["|+-", self.hop_left]], [], basis=self.basis, **no_checks) # left hoperators hop_right_op = hop_left_op.getH() # right hoperators ham_onsite = hamiltonian( self.sHl, [], basis=self.basis) # here we just use the onsite Hamiltonian self.operator_dict = dict(H_onsite=ham_onsite) self.operator_dict["hop_left_op"] = -hop_left_op / perimeter_params.t self.operator_dict["hop_right_op"] = -hop_right_op / perimeter_params.t self.operator_dict["ham_init"] = ham_onsite + (hop_left_op + hop_right_op) self.cycles = cycles dynamic_args = [perimeter_params, cycles] self.dHl = [ ["+-|", self.hop_left, expiphi, dynamic_args], # up hop left ["-+|", self.hop_right, expiphiconj, dynamic_args], # up hop right ["|+-", self.hop_left, expiphi, dynamic_args], # down hop left ["|-+", self.hop_right, expiphiconj, dynamic_args], # down hop right ] ham = hamiltonian(self.sHl, self.dHl, basis=self.basis) self.operator_dict["H"] = ham self.operator_dict["lhopup"] = hamiltonian( [], [["+-|", self.hop_left, expiphi, dynamic_args]], basis=self.basis, **no_checks) / perimeter_params.t self.operator_dict["lhopdown"] = hamiltonian( [], [["|+-", self.hop_left, expiphi, dynamic_args]], basis=self.basis, **no_checks) / perimeter_params.t self.operator_dict[ "current"] = 1j * perimeter_params.a * perimeter_params.t * ( (self.operator_dict["lhopup"] + self.operator_dict["lhopdown"]) - (self.operator_dict["lhopup"] + self.operator_dict["lhopdown"]).getH()) self.perimeter_params = perimeter_params