def get_operators(size, Nb): n, m = size if Nb % 2 == 1: S = "{}/2".format(Nb) else: S = "{}".format(Nb // 2) bath_basis = spin_basis_general(1, S=S) N = n**2 + m**2 Ns_block_est = max((2**N) / (N), 1000) if n != 0: T1, t1, T2, t2, Pr, pr, Tx, Ty = tilted_square_transformations(n, m) blocks = dict(tx=(Tx, 0), ty=(Ty, 0), pb=(Pr, 0)) spin_basis = spin_basis_general(N, S="1/2", pauli=True, Ns_block_est=Ns_block_est, **blocks) else: L = m tr = square_lattice_trans(L, L) Tx = tr.T_x Ty = tr.T_y blocks = dict(tx=(Tx, 0), ty=(Ty, 0), px=(tr.P_x, 0), py=(tr.P_y, 0), pd=(tr.P_d, 0)) spin_basis = spin_basis_general(N, S="1/2", pauli=True, Ns_block_est=Ns_block_est, **blocks) basis = tensor_basis(spin_basis, bath_basis) J_list = [[-1.0, i, Tx[i]] for i in range(N)] J_list.extend([-1.0, i, Ty[i]] for i in range(N)) M_list = [[1.0 / N**2, i, i] for i in range(N)] M_list += [[2.0 / N**2, i, j] for i in range(N) for j in range(N) if i > j] kwargs = dict(basis=basis, dtype=np.float64, check_symm=False, check_pcon=False, check_herm=False) print size H_S = hamiltonian([["zz|", J_list]], [], **kwargs) M2 = hamiltonian([["zz|", M_list]], [], **kwargs) return H_S, M2
def test(S,Lx,Ly): N = Lx*Ly nmax = int(eval("2*"+S)) sps = nmax+1 tr = square_lattice_trans(Lx,Ly) basis_dict = {} Nups=range(nmax*N+1) for Nup in Nups: basis_blocks=[] pcon_basis = spin_basis_general(N,Nup=Nup,S=S) Ns_block = 0 for blocks in tr.allowed_blocks_spin_inversion_iter(Nup,sps): basis = spin_basis_general(N,Nup=Nup,S=S,**blocks) Ns_block += basis.Ns basis_blocks.append(basis) try: assert(Ns_block == pcon_basis.Ns) except AssertionError: print(Nup,Ns_block,pcon_basis.Ns) raise AssertionError("reduced blocks don't sum to particle sector.") basis_dict[Nup] = (pcon_basis,basis_blocks) J = [[1.0,i,tr.T_x[i]] for i in range(N)] J.extend([[1.0,i,tr.T_y[i]] for i in range(N)]) static = [["zz",J],["+-",J],["-+",J]] E_symm = {} for Nb,(pcon_basis,basis_blocks) in basis_dict.items(): H_pcon = hamiltonian(static,[],basis=pcon_basis,dtype=np.float64) if H_pcon.Ns>0: E_pcon = np.linalg.eigvalsh(H_pcon.todense()) else: E_pcon = np.array([]) E_block = [] for basis in basis_blocks: H = hamiltonian(static,[],basis=basis,dtype=np.complex128) if H.Ns>0: E_block.append(np.linalg.eigvalsh(H.todense())) E_block = np.hstack(E_block) E_block.sort() np.testing.assert_allclose(E_pcon,E_block,atol=1e-13) print("passed Nb={} sector".format(Nb))
def test(Lx, Ly): N = Lx * Ly tr = square_lattice_trans(Lx, Ly) basis_dict = {} Nfs = range(N + 1) for Nf in Nfs: basis_blocks = [] pcon_basis = spinless_fermion_basis_general(N, Nf=Nf) Ns_block = 0 for blocks in tr.allowed_blocks_iter_parity(): basis = spinless_fermion_basis_general(N, Nf=Nf, **blocks) Ns_block += basis.Ns basis_blocks.append(basis) assert (Ns_block == pcon_basis.Ns) basis_dict[Nf] = (pcon_basis, basis_blocks) J = [[np.sqrt(2.0), i, tr.T_x[i]] for i in range(N)] J.extend([[np.sqrt(2.0), i, tr.T_y[i]] for i in range(N)]) Jp = [[1.0, i, tr.T_x[i]] for i in range(N)] Jp.extend([[1.0, i, tr.T_y[i]] for i in range(N)]) Jm = [[-1.0, i, tr.T_x[i]] for i in range(N)] Jm.extend([[-1.0, i, tr.T_y[i]] for i in range(N)]) static = [["nn", J], ["+-", Jp], ["-+", Jm]] E_symm = {} for Nf, (pcon_basis, basis_blocks) in basis_dict.items(): H_pcon = hamiltonian(static, [], basis=pcon_basis, dtype=np.float64) if H_pcon.Ns > 0: E_pcon = np.linalg.eigvalsh(H_pcon.todense()) else: E_pcon = np.array([]) E_block = [] for basis in basis_blocks: H = hamiltonian(static, [], basis=basis, dtype=np.complex128) if H.Ns > 0: E_block.append(np.linalg.eigvalsh(H.todense())) E_block = np.hstack(E_block) E_block.sort() print(Nf) print(E_pcon) print(E_block) np.testing.assert_allclose(E_pcon, E_block, atol=1e-13) print("passed Nf={} sector".format(Nf))
def test(sps, Lx, Ly): N = Lx * Ly nmax = sps - 1 tr = square_lattice_trans(Lx, Ly) basis_dict = {} Nbs = range(nmax * N + 1) for Nb in Nbs: basis_blocks = [] pcon_basis = boson_basis_general(N, Nb=Nb, sps=sps) Ns_block = 0 for blocks in tr.allowed_blocks_iter(): basis = boson_basis_general(N, Nb=Nb, sps=sps, **blocks) Ns_block += basis.Ns basis_blocks.append(basis) try: assert (Ns_block == pcon_basis.Ns) except AssertionError: print(Ns_block, pcon_basis.Ns) raise AssertionError basis_dict[Nb] = (pcon_basis, basis_blocks) J = [[1.0, i, tr.T_x[i]] for i in range(N)] J.extend([[1.0, i, tr.T_y[i]] for i in range(N)]) static = [["nn", J], ["+-", J], ["-+", J]] E_symm = {} for Nb, (pcon_basis, basis_blocks) in basis_dict.items(): H_pcon = hamiltonian(static, [], basis=pcon_basis, dtype=np.float64) if H_pcon.Ns > 0: E_pcon = np.linalg.eigvalsh(H_pcon.todense()) else: E_pcon = np.array([]) E_block = [] for basis in basis_blocks: H = hamiltonian(static, [], basis=basis, dtype=np.complex128) if H.Ns > 0: E_block.append(np.linalg.eigvalsh(H.todense())) E_block = np.hstack(E_block) E_block.sort() np.testing.assert_allclose(E_pcon, E_block, atol=1e-13) print("passed Nb={} sector".format(Nb))
###### setting up user-defined symmetry transformations for 2d lattice ###### s = np.arange(N_2d) # sites [0,1,2,....] x = s % Lx # x positions for sites y = s // Lx # y positions for sites T_x = (x + 1) % Lx + Lx * y # translation along x-direction T_y = x + Lx * ((y + 1) % Ly) # translation along y-direction Z = -(s + 1) # spin inversion J = np.sqrt(7) J_p = [[+J, i, T_x[i]] for i in range(N_2d)] + [[+J, i, T_y[i]] for i in range(N_2d)] J_n = [[-J, i, T_x[i]] for i in range(N_2d)] + [[-J, i, T_y[i]] for i in range(N_2d)] lattice_trans = square_lattice_trans(Lx, Ly) allowed_sectors = lattice_trans.allowed_blocks_iter() for ii, basis_dict in enumerate(allowed_sectors): ###### setting up bases ###### basis_boson = boson_basis_general(N_2d, make_basis=False, Nb=N_2d // 4, sps=2, **basis_dict) basis_boson_full = boson_basis_general( N_2d, make_basis=False,
def test(Lx,Ly): N = Lx*Ly nmax = int(eval("2*1/2")) sps = nmax+1 tr = square_lattice_trans(Lx,Ly) basis_dict = {} basis_dict_f = {} basis_dict_combined = {} Nups=range(nmax*N+1) for Nup in Nups: basis_blocks=[] basis_blocks_f=[] pcon_basis = spin_basis_general(N,Nup=Nup,pauli=False) pcon_basis_f = spinful_fermion_basis_general(N,Nf=(Nup,N-Nup),double_occupancy=False) Ns_block = 0 for blocks in tr.allowed_blocks_spin_inversion_iter(Nup,sps): basis = spin_basis_general(N,Nup=Nup,pauli=False,**blocks) Ns_block += basis.Ns basis_blocks.append(basis) Ns_block_f = 0 for blocks_f in tr.allowed_blocks_spin_inversion_iter(Nup,sps): # requires simple symmetry definition basis_f = spinful_fermion_basis_general(N,Nf=(Nup,N-Nup),double_occupancy=False,**blocks_f) Ns_block_f += basis_f.Ns basis_blocks_f.append(basis_f) try: assert(Ns_block == pcon_basis.Ns) except AssertionError: print(Nup,Ns_block,pcon_basis.Ns) raise AssertionError("reduced blocks don't sum to particle sector.") try: assert(Ns_block_f == pcon_basis_f.Ns) except AssertionError: print(Nup,Ns_block_f,pcon_basis_f.Ns) raise AssertionError("fermion reduced blocks don't sum to particle sector.") try: assert(Ns_block == pcon_basis_f.Ns) except AssertionError: print(Nup,Ns_block_f,pcon_basis_f.Ns) raise AssertionError("fermion reduced blocks don't match spin blocks.") basis_dict[Nup] = (pcon_basis,basis_blocks) basis_dict_f[Nup] = (pcon_basis_f,basis_blocks_f) basis_dict_combined[Nup] = (pcon_basis,basis_blocks,pcon_basis_f,basis_blocks_f) J = [[1.0,i,tr.T_x[i]] for i in range(N)] + [[1.0,i,tr.T_y[i]] for i in range(N)] J_nn_ij = [[-0.25,i,tr.T_x[i]] for i in range(N)] + [[-0.25,i,tr.T_y[i]] for i in range(N)] J_nn_ji = [[-0.25,tr.T_x[i],i] for i in range(N)] + [[-0.25,tr.T_y[i],i] for i in range(N)] J_nn_ij_p = [[0.25,i,tr.T_x[i]] for i in range(N)] + [[0.25,i,tr.T_y[i]] for i in range(N)] J_nn_ji_p = [[0.25,tr.T_x[i],i] for i in range(N)] + [[0.25,tr.T_y[i],i] for i in range(N)] J_cccc_ij = [[-1.0,i,tr.T_x[i],tr.T_x[i],i] for i in range(N)] + [[-1.0,i,tr.T_y[i],tr.T_y[i],i] for i in range(N)] J_cccc_ji = [[-1.0,tr.T_x[i],i,i,tr.T_x[i]] for i in range(N)] + [[-1.0,tr.T_y[i],i,i,tr.T_y[i]] for i in range(N)] static = [["zz",J],["+-",J],["-+",J]] static_f = [["nn|",J_nn_ij_p],["|nn",J_nn_ji_p],["n|n",J_nn_ij],["n|n",J_nn_ji],["+-|+-",J_cccc_ij],["+-|+-",J_cccc_ji]] E_symm = {} E_symm_f = {} #''' for N,(pcon_basis,basis_blocks,pcon_basis_f,basis_blocks_f) in basis_dict_combined.items(): H_pcon = hamiltonian(static,[],basis=pcon_basis,dtype=np.float64) H_pcon_f = hamiltonian(static_f,[],basis=pcon_basis_f,dtype=np.float64) if H_pcon.Ns>0: E_pcon = np.linalg.eigvalsh(H_pcon.todense()) else: E_pcon = np.array([]) if H_pcon_f.Ns>0: E_pcon_f = np.linalg.eigvalsh(H_pcon_f.todense()) else: E_pcon_f = np.array([]) E_block = [] E_block_f = [] for basis, basis_f in zip(basis_blocks,basis_blocks_f): H = hamiltonian(static,[],basis=basis,dtype=np.complex128) H_f = hamiltonian(static_f,[],basis=basis_f,dtype=np.complex128) if H.Ns>0: E_block.append(np.linalg.eigvalsh(H.todense())) if H_f.Ns>0: E_block_f.append(np.linalg.eigvalsh(H_f.todense())) E_block = np.hstack(E_block) E_block.sort() E_block_f = np.hstack(E_block_f) E_block_f.sort() np.testing.assert_allclose(E_pcon,E_block,atol=1e-13) np.testing.assert_allclose(E_pcon_f,E_block_f,atol=1e-13) np.testing.assert_allclose(E_pcon,E_pcon_f,atol=1e-13) print("passed N={} sector".format(N))
def anneal_bath_1(n, m, Nb, T, gamma=0.2, omega=1.0, path="."): ti = time.time() n, m = min(n, m), max(n, m) filename = os.path.join( path, "spin_bath_exact_n_{}_m_{}_Nb_{}_T_{}_gamma_{}_omega_{}.npz".format( n, m, Nb, T, gamma, omega)) if os.path.isfile(filename): print "file_exists...exiting run." exit() if Nb % 2 == 1: S = "{}/2".format(Nb) else: S = "{}".format(Nb // 2) print "creating basis" bath_basis = spin_basis_general(1, S=S) N = n**2 + m**2 Ns_block_est = max((2**N) / (N), 1000) if n != 0: T1, t1, T2, t2, Pr, pr, Tx, Ty = tilted_square_transformations(n, m) blocks = dict(tx=(Tx, 0), ty=(Ty, 0), pb=(Pr, 0)) spin_basis = spin_basis_general(N, S="1/2", pauli=True, Ns_block_est=Ns_block_est, **blocks) else: L = m tr = square_lattice_trans(L, L) Tx = tr.T_x Ty = tr.T_y blocks = dict(tx=(Tx, 0), ty=(Ty, 0), px=(tr.P_x, 0), py=(tr.P_y, 0), pd=(tr.P_d, 0)) spin_basis = spin_basis_general(N, S="1/2", pauli=True, Ns_block_est=Ns_block_est, **blocks) basis = tensor_basis(spin_basis, bath_basis) print "n,m={},{}, H-space size: {}".format(n, m, basis.Ns) J_list = [[-1.0, i, Tx[i]] for i in range(N)] J_list.extend([-1.0, i, Ty[i]] for i in range(N)) h_list = [[-1.0, i] for i in range(N)] bath_energy = [[omega / Nb, 0]] SB_xy_list = [[gamma / (4.0 * Nb), i, 0] for i in range(N)] SB_zz_list = [[gamma / (2.0 * Nb), i, 0] for i in range(N)] A = lambda t: (t / T)**2 B = lambda t: (1 - t / T)**2 static = [ ["|z", bath_energy], ] dynamic = [ ["zz|", J_list, A, ()], ["x|", h_list, B, ()], ["+|-", SB_xy_list, B, ()], ["-|+", SB_xy_list, B, ()], ["z|z", SB_zz_list, B, ()], ] print "creating hamiltonian" kwargs = dict(basis=basis, dtype=np.float64, check_symm=False, check_pcon=False, check_herm=False) H = hamiltonian(static, dynamic, **kwargs) print "solving initial state" E0, psi_0 = H.eigsh(k=1, which="SA", time=0) psi_0 = psi_0.ravel() print "evolving" out = np.zeros(psi_0.shape, dtype=np.complex128) psi_f = evolve(psi_0, 0, T, H._hamiltonian__omp_SO, f_params=(out, ), solver_name="dop853", atol=1.1e-15, rtol=1.1e-15) print "saving" np.savez_compressed(filename, psi=psi_f) print "dome......{} sec".format(time.time() - ti)