def test_cf_G_tau_and_G_iw_nonint(verbose=False): beta = 3.22 eps = 1.234 niw = 64 ntau = 2 * niw + 1 H = eps * c_dag(0,0) * c(0,0) fundamental_operators = [c(0,0)] ed = TriqsExactDiagonalization(H, fundamental_operators, beta) # ------------------------------------------------------------------ # -- Single-particle Green's functions G_tau = GfImTime(beta=beta, statistic='Fermion', n_points=ntau, target_shape=(1,1)) G_iw = GfImFreq(beta=beta, statistic='Fermion', n_points=niw, target_shape=(1,1)) G_iw << inverse( iOmega_n - eps ) G_tau << InverseFourier(G_iw) G_tau_ed = GfImTime(beta=beta, statistic='Fermion', n_points=ntau, target_shape=(1,1)) G_iw_ed = GfImFreq(beta=beta, statistic='Fermion', n_points=niw, target_shape=(1,1)) ed.set_g2_tau(G_tau_ed[0, 0], c(0,0), c_dag(0,0)) ed.set_g2_iwn(G_iw_ed[0, 0], c(0,0), c_dag(0,0)) # ------------------------------------------------------------------ # -- Compare gfs from pytriqs.utility.comparison_tests import assert_gfs_are_close assert_gfs_are_close(G_tau, G_tau_ed) assert_gfs_are_close(G_iw, G_iw_ed) # ------------------------------------------------------------------ # -- Plotting if verbose: from pytriqs.plot.mpl_interface import oplot, plt subp = [3, 1, 1] plt.subplot(*subp); subp[-1] += 1 oplot(G_tau.real) oplot(G_tau_ed.real) plt.subplot(*subp); subp[-1] += 1 diff = G_tau - G_tau_ed oplot(diff.real) oplot(diff.imag) plt.subplot(*subp); subp[-1] += 1 oplot(G_iw) oplot(G_iw_ed) plt.show()
def c_transf(s, i): if (s, i) not in op_idx_set: return c(s, i) k = op_idx_map.index((s, i)) ret = Operator() for l in xrange(U.shape[0]): op_idx = op_idx_map[l] ret += U[k, l] * c(*op_idx) return ret
def test_fundamental(): assert( op_is_fundamental(c(0, 0)) is True ) assert( op_is_fundamental(c_dag(0, 0)) is True ) assert( op_is_fundamental(c_dag(0, 0)*c(0, 0)) is False ) assert( op_is_fundamental(Operator(1.0)) is False ) assert( op_serialize_fundamental(c(0,0)) == (False, (0,0)) ) assert( op_serialize_fundamental(c_dag(0,0)) == (True, (0,0)) ) assert( op_serialize_fundamental(c(2,4)) == (False, (2,4)) ) assert( op_serialize_fundamental(c_dag(4,3)) == (True, (4,3)) )
def test_quartic(verbose=False): if verbose: print '--> test_quartic' num_orbitals = 2 num_spins = 2 U, J = 1.0, 0.2 up, do = 0, 1 spin_names = [up, do] orb_names = range(num_orbitals) U_ab, UPrime_ab = U_matrix_kanamori(n_orb=2, U_int=U, J_hund=J) if verbose: print 'U_ab =\n', U_ab print 'UPrime_ab =\n', UPrime_ab T_ab = np.array([ [1., 1.], [1., -1.], ]) / np.sqrt(2.) # -- Check hermitian np.testing.assert_array_almost_equal(np.mat(T_ab) * np.mat(T_ab).H, np.eye(2)) I = np.eye(num_spins) T_ab_spin = np.kron(T_ab, I) H_int = h_int_kanamori( spin_names, orb_names, U_ab, UPrime_ab, J_hund=J, off_diag=True, map_operator_structure=None, H_dump=None) op_imp = [c(up,0), c(do,0), c(up,1), c(do,1)] Ht_int = operator_single_particle_transform(H_int, T_ab_spin, op_imp) if verbose: print 'H_int =', H_int print 'Ht_int =', Ht_int from transform_kanamori import h_int_kanamori_transformed Ht_int_ref = h_int_kanamori_transformed( [T_ab, T_ab], spin_names, orb_names, U_ab, UPrime_ab, J_hund=J, off_diag=True, map_operator_structure=None, H_dump=None) if verbose: print 'Ht_int_ref =', Ht_int_ref assert( (Ht_int_ref - Ht_int).is_zero() )
def fundamental_operators_from_gf_struct(gf_struct): fundamental_operators = [] for block, idxs in gf_struct: for idx in idxs: fundamental_operators.append(c(block, idx)) return fundamental_operators
def fundamental_operators_from_gf_struct(gf_struct): """ Return a list of annihilation operators with the quantum numbers defined in the gf_struct """ fundamental_operators = [] for block_name, indices in gf_struct: for index in indices: fundamental_operators.append(c(block_name, index)) return fundamental_operators
def test_quadratic(): n = 10 h_loc = np.random.random((n, n)) h_loc = 0.5 * (h_loc + h_loc.T) fund_op = [ c(0, idx) for idx in xrange(n) ] H_loc = get_quadratic_operator(h_loc, fund_op) h_loc_ref = quadratic_matrix_from_operator(H_loc, fund_op) np.testing.assert_array_almost_equal(h_loc, h_loc_ref)
def is_operator_composed_of_only_fundamental_operators(op, fundamental_operators): """ Return `True` if the operator `op` only contains operators belonging to the fundamental operator set `fundamental_operators`, else return `False`.""" is_fundamental = True for term in op: op_list, prefactor = term d, t = zip(*op_list) # split in two lists with daggers and tuples resp t = [tuple(x) for x in t] for bidx, idx in t: if c(bidx, idx) not in fundamental_operators: is_fundamental = False return is_fundamental
def test_quartic_tensor_from_operator(verbose=False): N = 3 fundamental_operators = [ c(0, x) for x in range(N) ] shape = (N, N, N, N) U = np.random.random(shape) + 1.j * np.random.random(shape) U_sym = symmetrize_quartic_tensor(U) H = operator_from_quartic_tensor(U, fundamental_operators) U_ref = quartic_tensor_from_operator(H, fundamental_operators, perm_sym=True) np.testing.assert_array_almost_equal(U_ref, U_sym) if verbose: print '-'*72 import itertools for idxs in itertools.product(range(N), repeat=4): print idxs, U_ref[idxs] - U_sym[idxs], U[idxs], U_ref[idxs], U_sym[idxs]
def test_single_particle_transform(verbose=False): if verbose: print '--> test_single_particle_transform' h_loc = np.array([ [1.0, 0.0], [0.0, -1.0], ]) op_imp = [c(0,0), c(0,1)] H_loc = get_quadratic_operator(h_loc, op_imp) H_loc_ref = c_dag(0,0) * c(0,0) - c_dag(0,1) * c(0,1) assert( (H_loc - H_loc_ref).is_zero() ) h_loc_ref = quadratic_matrix_from_operator(H_loc, op_imp) np.testing.assert_array_almost_equal(h_loc, h_loc_ref) if verbose: print 'h_loc =\n', h_loc print 'h_loc_ref =\n', h_loc_ref print 'H_loc =', H_loc T_ab = np.array([ [1., 1.], [1., -1.], ]) / np.sqrt(2.) Ht_loc = operator_single_particle_transform(H_loc, T_ab, op_imp) ht_loc = quadratic_matrix_from_operator(Ht_loc, op_imp) ht_loc_ref = np.array([ [0., 1.], [1., 0.], ]) Ht_loc_ref = c_dag(0, 0) * c(0, 1) + c_dag(0, 1) * c(0, 0) if verbose: print 'ht_loc =\n', ht_loc print 'ht_loc_ref =\n', ht_loc_ref print 'Ht_loc =', Ht_loc print 'Ht_loc_ref =', Ht_loc_ref assert( (Ht_loc - Ht_loc_ref).is_zero() )
def solve_aims(G0_iw_list_): G_iw_list = [] G_tau_list = [] average_sign_list = [] for G0_iw in G0_iw_list_: print 'G0_iw', G0_iw # ==== Local Hamiltonian ==== c_dag_vec = matrix([[c_dag('bl', idx) for idx in idx_lst]]) c_vec = matrix([[c('bl', idx)] for idx in idx_lst]) h_0_mat = t_ij_list[0] h_0 = (c_dag_vec * h_0_mat * c_vec)[0, 0] # ==== Interacting Hamiltonian ==== Umat, Upmat = U_matrix_kanamori(len(orb_names), U_int=U, J_hund=J) #op_map = { (s,o): ('bl',i) for i, (s,o) in enumerate(product(spin_names, orb_names)) } op_map = {(s, o): ('bl', i) for i, (o, s) in enumerate(product(orb_names, spin_names))} h_int = h_int_kanamori(spin_names, orb_names, Umat, Upmat, J, off_diag=True, map_operator_structure=op_map) G_tau, G_iw, average_sign = ctqmc_solver(h_int, G0_iw) G_iw_list.append(G_iw) G_tau_list.append(G_tau) average_sign_list.append(average_sign) return G_tau_list, G_iw_list, average_sign_list
def test_gf_struct(): orb_idxs = [0, 1, 2] spin_idxs = ['up', 'do'] gf_struct = [ [spin_idx, orb_idxs] for spin_idx in spin_idxs ] fundamental_operators = fundamental_operators_from_gf_struct(gf_struct) fundamental_operators_ref = [ c('up', 0), c('up', 1), c('up', 2), c('do', 0), c('do', 1), c('do', 2), ] print fundamental_operators assert( fundamental_operators == fundamental_operators_ref )
def test_sparse_matrix_representation(): up, do = 0, 1 fundamental_operators = [c(up, 0), c(do, 0)] rep = SparseMatrixRepresentation(fundamental_operators) # -- Test an operator O_mat = rep.sparse_matrix(c(up, 0)) O_ref = rep.sparse_operators.c_dag[0].getH() compare_sparse_matrices(O_mat, O_ref) # -- Test O_mat = rep.sparse_matrix(c(do, 0)) O_ref = rep.sparse_operators.c_dag[1].getH() compare_sparse_matrices(O_mat, O_ref) # -- Test expression H_expr = c(up, 0) * c(do, 0) * c_dag(up, 0) * c_dag(do, 0) H_mat = rep.sparse_matrix(H_expr) c_dag0, c_dag1 = rep.sparse_operators.c_dag c_0, c_1 = c_dag0.getH(), c_dag1.getH() H_ref = c_0 * c_1 * c_dag0 * c_dag1 compare_sparse_matrices(H_mat, H_ref)
def d(b, m): ret = Operator() for i in range(len(v[b])): ret += v[b][m][i] * c(b, i) return ret
Ek = np.array([ [1.00, 0.75], [0.75, -1.20], ]) E_loc = np.array([ [0.2, 0.3], [0.3, 0.4], ]) V = np.array([ [1.0, 0.25], [0.25, -1.0], ]) h_loc = c_dag('0', 0) * E_loc[0, 0] * c('0', 0) + \ c_dag('0', 0) * E_loc[0, 1] * c('0', 1) + \ c_dag('0', 1) * E_loc[1, 0] * c('0', 0) + \ c_dag('0', 1) * E_loc[1, 1] * c('0', 1) Delta_iw << inverse( iOmega_n - Ek ) + inverse( iOmega_n + Ek ) Delta_iw.from_L_G_R(V, Delta_iw, V) Delta_tau = Gf(mesh=tmesh, target_shape=target_shape) Delta_tail, Delta_tail_err = Delta_iw.fit_hermitian_tail() Delta_tau << InverseFourier(Delta_iw, Delta_tail) G0_iw = Gf(mesh=wmesh, target_shape=target_shape) G0_iw << inverse( iOmega_n - Delta_iw - E_loc ) S.G0_iw << G0_iw
def make_calc(U=10): # ------------------------------------------------------------------ # -- Hubbard atom with two bath sites, Hamiltonian params = dict( beta=2.0, V1=2.0, V2=5.0, epsilon1=0.00, epsilon2=4.00, mu=2.0, U=U, ntau=40, niw=15, ) # ------------------------------------------------------------------ class Dummy(): def __init__(self): pass d = Dummy() # storage space d.params = params print '--> Solving SIAM with parameters' for key, value in params.items(): print '%10s = %-10s' % (key, str(value)) globals()[key] = value # populate global namespace # ------------------------------------------------------------------ up, do = 0, 1 docc = c_dag(up, 0) * c(up, 0) * c_dag(do, 0) * c(do, 0) nA = c_dag(up, 0) * c(up, 0) + c_dag(do, 0) * c(do, 0) nB = c_dag(up, 1) * c(up, 1) + c_dag(do, 1) * c(do, 1) nC = c_dag(up, 2) * c(up, 2) + c_dag(do, 2) * c(do, 2) d.H = -mu * nA + epsilon1 * nB + epsilon2 * nC + U * docc + \ V1 * (c_dag(up,0)*c(up,1) + c_dag(up,1)*c(up,0) + \ c_dag(do,0)*c(do,1) + c_dag(do,1)*c(do,0) ) + \ V2 * (c_dag(up,0)*c(up,2) + c_dag(up,2)*c(up,0) + \ c_dag(do,0)*c(do,2) + c_dag(do,2)*c(do,0) ) # ------------------------------------------------------------------ # -- Exact diagonalization fundamental_operators = [ c(up, 0), c(do, 0), c(up, 1), c(do, 1), c(up, 2), c(do, 2) ] ed = TriqsExactDiagonalization(d.H, fundamental_operators, beta) # ------------------------------------------------------------------ # -- Single-particle Green's functions Gopt = dict(beta=beta, statistic='Fermion', indices=[1]) d.G_tau = GfImTime(name=r'$G(\tau)$', n_points=ntau, **Gopt) d.G_iw = GfImFreq(name='$G(i\omega_n)$', n_points=niw, **Gopt) ed.set_g2_tau(d.G_tau, c(up, 0), c_dag(up, 0)) ed.set_g2_iwn(d.G_iw, c(up, 0), c_dag(up, 0)) # chi2pp = + < c^+_u(\tau^+) c_u(0^+) c^+_d(\tau) c_d(0) > # = - < c^+_u(\tau^+) c^+_d(\tau) c_u(0^+) c_d(0) > chi2opt = dict(beta=beta, statistic='Fermion', indices=[1], n_points=ntau) d.chi2pp_tau = GfImTime(name=r'$\chi^{(2)}_{PP}(\tau)$', **chi2opt) ed.set_g2_tau(d.chi2pp_tau, c_dag(up, 0) * c_dag(do, 0), c(up, 0) * c(do, 0)) d.chi2pp_tau *= -1.0 * -1.0 # commutation sign and gf sign d.chi2pp_iw = g_iw_from_tau(d.chi2pp_tau, niw) # chi2ph = < c^+_u(\tau^+) c_u(\tau) c^+_d(0^+) c_d(0) > d.chi2ph_tau = GfImTime(name=r'$\chi^{(2)}_{PH}(\tau)$', **chi2opt) #d.chi2ph_tau = Gf(name=r'$\chi^{(2)}_{PH}(\tau)$', **chi2opt) ed.set_g2_tau(d.chi2ph_tau, c_dag(up, 0) * c(up, 0), c_dag(do, 0) * c(do, 0)) d.chi2ph_tau *= -1.0 # gf sign d.chi2ph_iw = g_iw_from_tau(d.chi2ph_tau, niw) # ------------------------------------------------------------------ # -- Two particle Green's functions imtime = MeshImTime(beta, 'Fermion', ntau) prodmesh = MeshProduct(imtime, imtime, imtime) G2opt = dict(mesh=prodmesh, target_shape=[1, 1, 1, 1]) d.G02_tau = Gf(name='$G^{(2)}_0(\tau_1, \tau_2, \tau_3)$', **G2opt) ed.set_g40_tau(d.G02_tau, d.G_tau) d.G02_iw = chi4_iw_from_tau(d.G02_tau, niw) d.G2_tau = Gf(name='$G^{(2)}(\tau_1, \tau_2, \tau_3)$', **G2opt) ed.set_g4_tau(d.G2_tau, c_dag(up, 0), c(up, 0), c_dag(do, 0), c(do, 0)) #ed.set_g4_tau(d.G2_tau, c(up,0), c_dag(up,0), c(do,0), c_dag(do,0)) # <cc^+cc^+> d.G2_iw = chi4_iw_from_tau(d.G2_tau, niw) # -- trying to fix the bug in the fft for w2 d.G02_iw.data[:] = d.G02_iw.data[:, ::-1, ...].conj() d.G2_iw.data[:] = d.G2_iw.data[:, ::-1, ...].conj() # ------------------------------------------------------------------ # -- 3/2-particle Green's functions (equal times) prodmesh = MeshProduct(imtime, imtime) chi3opt = dict(mesh=prodmesh, target_shape=[1, 1, 1, 1]) # chi3pp = <c^+_u(\tau) c_u(0^+) c^+_d(\tau') c_d(0) > # = - <c^+_u(\tau) c^+_d(\tau') c_u(0^+) c_d(0) > d.chi3pp_tau = Gf(name='$\Chi^{(3)}_{PP}(\tau_1, \tau_2, \tau_3)$', **chi3opt) ed.set_g3_tau(d.chi3pp_tau, c_dag(up, 0), c_dag(do, 0), c(up, 0) * c(do, 0)) d.chi3pp_tau *= -1.0 # from commutation d.chi3pp_iw = chi3_iw_from_tau(d.chi3pp_tau, niw) # chi3ph = <c^+_u(\tau) c_u(\tau') c^+_d(0^+) c_d(0) > d.chi3ph_tau = Gf(name='$\Chi^{(3)}_{PH}(\tau_1, \tau_2, \tau_3)$', **chi3opt) ed.set_g3_tau(d.chi3ph_tau, c_dag(up, 0), c(up, 0), c_dag(do, 0) * c(do, 0)) d.chi3ph_iw = chi3_iw_from_tau(d.chi3ph_tau, niw) # ------------------------------------------------------------------ # -- Store to hdf5 filename = 'data_ed.h5' with HDFArchive(filename, 'w') as res: for key, value in d.__dict__.items(): res[key] = value
# Number of particles on the impurity N = sum(n(sn, o) for sn, o in product(spin_names, orb_names)) # Local Hamiltonian H_loc = h_int_kanamori(spin_names, orb_names, np.array([[0, U - 3 * J], [U - 3 * J, 0]]), np.array([[U, U - 2 * J], [U - 2 * J, U]]), J, True) H_loc -= mu * N # Bath Hamiltonian H_bath = sum(epsilon[o] * n("B_" + sn, o) for sn, o in product(spin_names, orb_names)) # Hybridization Hamiltonian H_hyb = sum(V[o1, o2] * c_dag("B_" + sn, o1) * c(sn, o2) + np.conj(V[o2, o1]) * c_dag(sn, o1) * c("B_" + sn, o2) for sn, o1, o2 in product(spin_names, orb_names, orb_names)) # Complete Hamiltonian H = H_loc + H_hyb + H_bath # Diagonalize H ed.diagonalize(H) # Compute G(i\omega) G_iw = ed.G_iw(gf_struct, beta, n_iw) # Compute G(\tau) G_tau = ed.G_tau(gf_struct, beta, n_tau)
orbital_names = ['up_0', 'do_0'], ) print '--> e_k' e_k = t_r.on_mesh_brillouin_zone(n_k) print '--> g0_wk' wmesh = MeshImFreq(beta=beta, S='Fermion', n_max=n_w) g0_wk = lattice_dyson_g0_wk(mu=mu, e_k=e_k, mesh=wmesh) chi00_wk = imtime_bubble_chi0_wk(g0_wk, nw=1) # ------------------------------------------------------------------ # -- RPA fundamental_operators = [c(0, 0), c(0, 1)] chi_wk_vec = [] U_vec = np.arange(1.0, 5.0, 1.0) for u in U_vec: print '--> RPA chi_wk, U =', u H_int = u * n(0, 0) * n(0, 1) U_int_abcd = quartic_tensor_from_operator(H_int, fundamental_operators) print U_int_abcd.reshape((4, 4)).real U_int_abcd = quartic_permutation_symmetrize(U_int_abcd) print U_int_abcd.reshape((4, 4)).real
if False: from scipy.stats import unitary_group, ortho_group np.random.seed(seed=233423) # -- Reproducible "randomness" p.T = unitary_group.rvs(4) # General complex unitary transf #p.T = np.kron(ortho_group.rvs(2), np.eye(2)) # orbital only rotation # use parametrized "weak" realvalued 4x4 transform p.T = unitary_transf_4x4(t_vec=[0.3, 0.3, 0.3, 0.0, 0.0, 0.0]) #p.T = unitary_transf_4x4(t_vec=[0.25*np.pi, 0.0, 0.0, 0.0, 0.0, 0.0]) #p.T = np.eye(4) p.T = np.matrix(p.T) print p.T # -- Different types of operator sets p.op_imp = [c('0', 0), c('0', 1), c('0', 2), c('0', 3)] p.op_full = p.op_imp + [c('1', 0), c('1', 1), c('1', 2), c('1', 3)] p.spin_block_ops = [c('0', 0), c('1', 0), c('0', 1), c('1', 1)] p.spin_block_ops += [dagger(op) for op in p.spin_block_ops] p.org_ops = copy.copy(p.op_imp) p.org_ops += [dagger(op) for op in p.org_ops] p.diag_ops = [c('0_0', 0), c('0_1', 0), c('0_2', 0), c('0_3', 0)] p.diag_ops += [dagger(op) for op in p.diag_ops] p.gf_struct = [['0', [0, 1, 2, 3]]] p.gf_struct_diag = [['0_0', [0]], ['0_1', [0]], ['0_2', [0]], ['0_3', [0]]] p.index_converter = {
n_iw=1025, n_tau=2500, n_l=20) solver = SolverCore(**cp) # Set hybridization function mu = 0.5 half_bandwidth = 1.0 delta_w = GfImFreq(indices=[0], beta=cp['beta']) delta_w << (half_bandwidth / 2.0)**2 * SemiCircular(half_bandwidth) for name, g0 in solver.G0_iw: g0 << inverse(iOmega_n + mu - delta_w) sp = dict( h_int=n('up', 0) * n('do', 0) + c_dag('up', 0) * c('do', 0) + c_dag('do', 0) * c('up', 0), max_time=-1, length_cycle=50, n_warmup_cycles=50, n_cycles=500, move_double=False, ) solver.solve(**sp) filename = 'h5_read_write.h5' with HDFArchive(filename, 'w') as A: A['solver'] = solver
def solve(self, H_int, E_levels, integrals_of_motion=None, density_matrix_cutoff=1e-10, file_quantum_numbers="", file_eigenvalues=""): self.__copy_E_levels(E_levels) H_0 = sum( self.E_levels[sn][oi1, oi2].real * c_dag(sn, on1) * c(sn, on2) for sn, (oi1, on1), ( oi2, on2) in product(self.spin_names, enumerate( self.orb_names), enumerate(self.orb_names))) if self.verbose and mpi.is_master_node(): print "\n*** compute G_iw and Sigma_iw" print "*** E_levels =", E_levels print "*** H_0 =", H_0 # print "*** integrals_of_motion =", integrals_of_motion N_op = sum( c_dag(sn, on) * c(sn, on) for sn, on in product(self.spin_names, self.orb_names)) if integrals_of_motion is None: if self.spin_orbit: # use only N op as integrals_of_motion when spin-orbit coupling is included self.__ed.diagonalize(H_0 + H_int, integrals_of_motion=[N_op]) else: # use N and S_z as integrals of motion by default self.__ed.diagonalize(H_0 + H_int) else: assert isinstance(integrals_of_motion, list) # check commutation relation in advance (just for test) if self.verbose and mpi.is_master_node(): print "*** Integrals of motion:" for i, op in enumerate(integrals_of_motion): print " op%d =" % i, op print "*** commutation relations:" is_commute = lambda h, op: h * op - op * h str_if_commute = lambda h, op: "== 0" if is_commute( h, op).is_zero() else "!= 0" for i, op in enumerate(integrals_of_motion): print " [H_0, op%d]" % i, str_if_commute( H_0, op), " [H_int, op%d]" % i, str_if_commute(H_int, op) self.__ed.diagonalize(H_0 + H_int, integrals_of_motion) # save data if file_quantum_numbers: self.__ed.save_quantum_numbers(file_quantum_numbers) if file_eigenvalues: self.__ed.save_eigenvalues(file_eigenvalues) # set density-matrix cutoff self.__ed.set_density_matrix_cutoff(density_matrix_cutoff) # Compute G(i\omega) self.G_iw << self.__ed.G_iw(self.gf_struct, self.beta, self.n_iw) # Compute G0 and Sigma E_list = [self.E_levels[sn] for sn in self.spin_names] # from dict to list self.G0_iw << iOmega_n self.G0_iw -= E_list self.Sigma_iw << self.G0_iw - inverse(self.G_iw) self.G0_iw.invert() # ********************************************************************* # TODO: tail # set tail of Sigma at all zero in the meantime, because tail of G is # not computed in pomerol solver. This part should be improved. # ********************************************************************* for s, sig in self.Sigma_iw: sig.tail.zero()
if __name__ == '__main__': # ------------------------------------------------------------------ # -- Hubbard atom with two bath sites, Hamiltonian beta = 10.0 V1 = 1.0 V2 = 1.0 epsilon1 = +2.30 epsilon2 = -2.30 t = 0.1 mu = 1.0 U = 2.0 up, do = 0, 1 docc = c_dag(up, 0) * c(up, 0) * c_dag(do, 0) * c(do, 0) nA = c_dag(up, 0) * c(up, 0) + c_dag(do, 0) * c(do, 0) nB = c_dag(up, 1) * c(up, 1) + c_dag(do, 1) * c(do, 1) nC = c_dag(up, 2) * c(up, 2) + c_dag(do, 2) * c(do, 2) hopA = c_dag(up, 0) * c(do, 0) + c_dag(do, 0) * c(up, 0) hopB = c_dag(up, 1) * c(do, 1) + c_dag(do, 1) * c(up, 1) hopC = c_dag(up, 2) * c(do, 2) + c_dag(do, 2) * c(up, 2) H = -mu * nA + epsilon1 * nB + epsilon2 * nC + U * docc + \ V1 * (c_dag(up,0)*c(up,1) + c_dag(up,1)*c(up,0) + \ c_dag(do,0)*c(do,1) + c_dag(do,1)*c(do,0) ) + \ V2 * (c_dag(up,0)*c(up,2) + c_dag(up,2)*c(up,0) + \ c_dag(do,0)*c(do,2) + c_dag(do,2)*c(do,0) ) + \ -t * (hopA + hopB + hopC)
def test_two_particle_greens_function(): # ------------------------------------------------------------------ # -- Hubbard atom with two bath sites, Hamiltonian beta = 2.0 V1 = 2.0 V2 = 5.0 epsilon1 = 0.00 epsilon2 = 4.00 mu = 2.0 U = 0.0 up, do = 0, 1 docc = c_dag(up,0) * c(up,0) * c_dag(do,0) * c(do,0) nA = c_dag(up,0) * c(up,0) + c_dag(do,0) * c(do,0) nB = c_dag(up,1) * c(up,1) + c_dag(do,1) * c(do,1) nC = c_dag(up,2) * c(up,2) + c_dag(do,2) * c(do,2) H = -mu * nA + epsilon1 * nB + epsilon2 * nC + U * docc + \ V1 * (c_dag(up,0)*c(up,1) + c_dag(up,1)*c(up,0) + \ c_dag(do,0)*c(do,1) + c_dag(do,1)*c(do,0) ) + \ V2 * (c_dag(up,0)*c(up,2) + c_dag(up,2)*c(up,0) + \ c_dag(do,0)*c(do,2) + c_dag(do,2)*c(do,0) ) # ------------------------------------------------------------------ # -- Exact diagonalization fundamental_operators = [ c(up,0), c(do,0), c(up,1), c(do,1), c(up,2), c(do,2)] ed = TriqsExactDiagonalization(H, fundamental_operators, beta) # ------------------------------------------------------------------ # -- single particle Green's functions g_tau = GfImTime(name=r'$g$', beta=beta, statistic='Fermion', n_points=100, target_shape=(1,1)) ed.set_g2_tau(g_tau[0, 0], c(up,0), c_dag(up,0)) # ------------------------------------------------------------------ # -- Two particle Green's functions ntau = 10 imtime = MeshImTime(beta, 'Fermion', ntau) prodmesh = MeshProduct(imtime, imtime, imtime) g40_tau = Gf(name='g40_tau', mesh=prodmesh, target_shape=(1,1,1,1)) g4_tau = Gf(name='g4_tau', mesh=prodmesh, target_shape=(1,1,1,1)) ed.set_g40_tau_matrix(g40_tau, g_tau) ed.set_g4_tau(g4_tau[0, 0, 0, 0], c(up,0), c_dag(up,0), c(up,0), c_dag(up,0)) # ------------------------------------------------------------------ # -- compare zero_outer_planes_and_equal_times(g4_tau) zero_outer_planes_and_equal_times(g40_tau) np.testing.assert_array_almost_equal(g4_tau.data, g40_tau.data)
# ---------------------------------------------------------------------- if __name__ == '__main__': # ------------------------------------------------------------------ # -- Hubbard atom with two bath sites, Hamiltonian beta = 2.0 V1 = 2.0 V2 = 5.0 epsilon1 = 0.00 epsilon2 = 4.00 mu = 2.0 U = 0.0 up, do = 0, 1 docc = c_dag(up, 0) * c(up, 0) * c_dag(do, 0) * c(do, 0) nA = c_dag(up, 0) * c(up, 0) + c_dag(do, 0) * c(do, 0) nB = c_dag(up, 1) * c(up, 1) + c_dag(do, 1) * c(do, 1) nC = c_dag(up, 2) * c(up, 2) + c_dag(do, 2) * c(do, 2) H = -mu * nA + epsilon1 * nB + epsilon2 * nC + U * docc + \ V1 * (c_dag(up,0)*c(up,1) + c_dag(up,1)*c(up,0) + \ c_dag(do,0)*c(do,1) + c_dag(do,1)*c(do,0) ) + \ V2 * (c_dag(up,0)*c(up,2) + c_dag(up,2)*c(up,0) + \ c_dag(do,0)*c(do,2) + c_dag(do,2)*c(do,0) ) # ------------------------------------------------------------------ # -- Exact diagonalization fundamental_operators = [ c(up, 0), c(do, 0),
fundamental_operators = fundamental_operators_from_gf_struct(gf_struct) beta = 10.0 U = 2.0 mu = 1.0 h = 0.1 #V = 0.5 V = 1.0 epsilon = 2.3 H = U * n('up', 0) * n('do', 0) + \ - mu * (n('up', 0) + n('do', 0)) + \ h * n('up', 0) - h * n('do', 0) + \ epsilon * (n('up', 1) + n('do', 1)) - epsilon * (n('up', 2) + n('do', 2)) + \ V * ( c_dag('up', 0) * c('up', 1) + c_dag('up', 1) * c('up', 0) ) + \ V * ( c_dag('do', 0) * c('do', 1) + c_dag('do', 1) * c('do', 0) ) + \ V * ( c_dag('up', 0) * c('up', 2) + c_dag('up', 2) * c('up', 0) ) + \ V * ( c_dag('do', 0) * c('do', 2) + c_dag('do', 2) * c('do', 0) ) ed = TriqsExactDiagonalization(H, fundamental_operators, beta) n_tau = 101 G_tau_up = Gf(mesh=MeshImTime(beta, 'Fermion', n_tau), target_shape=[]) G_tau_do = Gf(mesh=MeshImTime(beta, 'Fermion', n_tau), target_shape=[]) ed.set_g2_tau(G_tau_up, c('up', 0), c_dag('up', 0)) ed.set_g2_tau(G_tau_do, c('do', 0), c_dag('do', 0)) with HDFArchive('anderson.pyed.h5', 'w') as Results: Results['up'] = G_tau_up
def make_calc(beta=2.0, h_field=0.0): # ------------------------------------------------------------------ # -- Hubbard atom with two bath sites, Hamiltonian p = ParameterCollection( beta=beta, V1=2.0, V2=5.0, epsilon1=0.10, epsilon2=3.00, h_field=h_field, mu=0.0, U=5.0, ntau=800, niw=15, ) # ------------------------------------------------------------------ print '--> Solving SIAM with parameters' print p # ------------------------------------------------------------------ up, do = 'up', 'dn' docc = c_dag(up, 0) * c(up, 0) * c_dag(do, 0) * c(do, 0) mA = c_dag(up, 0) * c(up, 0) - c_dag(do, 0) * c(do, 0) nA = c_dag(up, 0) * c(up, 0) + c_dag(do, 0) * c(do, 0) nB = c_dag(up, 1) * c(up, 1) + c_dag(do, 1) * c(do, 1) nC = c_dag(up, 2) * c(up, 2) + c_dag(do, 2) * c(do, 2) p.H = -p.mu * nA + p.U * docc + p.h_field * mA + \ p.epsilon1 * nB + p.epsilon2 * nC + \ p.V1 * (c_dag(up,0)*c(up,1) + c_dag(up,1)*c(up,0) + \ c_dag(do,0)*c(do,1) + c_dag(do,1)*c(do,0) ) + \ p.V2 * (c_dag(up,0)*c(up,2) + c_dag(up,2)*c(up,0) + \ c_dag(do,0)*c(do,2) + c_dag(do,2)*c(do,0) ) # ------------------------------------------------------------------ fundamental_operators = [ c(up, 0), c(do, 0), c(up, 1), c(do, 1), c(up, 2), c(do, 2) ] ed = TriqsExactDiagonalization(p.H, fundamental_operators, p.beta) g_tau = GfImTime(beta=beta, statistic='Fermion', n_points=400, indices=[0]) g_iw = GfImFreq(beta=beta, statistic='Fermion', n_points=10, indices=[0]) p.G_tau = BlockGf(name_list=[up, do], block_list=[g_tau] * 2, make_copies=True) p.G_iw = BlockGf(name_list=[up, do], block_list=[g_iw] * 2, make_copies=True) ed.set_g2_tau(p.G_tau[up][0, 0], c(up, 0), c_dag(up, 0)) ed.set_g2_tau(p.G_tau[do][0, 0], c(do, 0), c_dag(do, 0)) ed.set_g2_iwn(p.G_iw[up][0, 0], c(up, 0), c_dag(up, 0)) ed.set_g2_iwn(p.G_iw[do][0, 0], c(do, 0), c_dag(do, 0)) p.magnetization = ed.get_expectation_value(0.5 * mA) p.O_tau = Gf(mesh=MeshImTime(beta, 'Fermion', 400), target_shape=[]) ed.set_g2_tau(p.O_tau, n(up, 0), n(do, 0)) p.O_tau.data[:] *= -1. p.exp_val = ed.get_expectation_value(n(up, 0) * n(do, 0)) # ------------------------------------------------------------------ # -- Store to hdf5 filename = 'data_pyed_h_field_%4.4f.h5' % h_field with HDFArchive(filename, 'w') as res: res['p'] = p
for k, sn in product(range(len(epsilon)), spin_names)}) # Make PomerolED solver object ed = PomerolED(index_converter, verbose=True) # Number of particles on the impurity H_loc = -mu * (n('up', 0) + n('dn', 0)) + U * n('up', 0) * n('dn', 0) # Bath Hamiltonian H_bath = sum(eps * n("B%i_%s" % (k, sn), 0) for sn, (k, eps) in product(spin_names, enumerate(epsilon))) # Hybridization Hamiltonian H_hyb = Operator() for k, v in enumerate(V): H_hyb += sum(v * c_dag("B%i_%s" % (k, sn), 0) * c(sn, 0) + np.conj(v) * c_dag(sn, 0) * c("B%i_%s" % (k, sn), 0) for sn in spin_names) # Complete Hamiltonian H = H_loc + H_hyb + H_bath # Diagonalize H ed.diagonalize(H) ########### # G^{(2)} # ########### common_g2_params = { 'gf_struct': gf_struct,
def solve(self, **params_kw): """ Solve the impurity problem: calculate G(iw) and Sigma(iw) Parameters ---------- params_kw : dict {'param':value} that is passed to the core solver. Two required :ref:`parameters <solve_parameters>` are * `h_int` (:ref:`Operator object <triqslibs:operators>`): the local Hamiltonian of the impurity problem to be solved, * `n_cycles` (int): number of measurements to be made. Other parameters are * `calc_gtau` (bool): calculate G(tau) * `calc_gw` (bool): calculate G(w) and Sigma(w) * `calc_gl` (bool): calculate G(legendre) * `calc_dm` (bool): calculate density matrix """ h_int = params_kw['h_int'] try: calc_gtau = params_kw['calc_gtau'] except KeyError: calc_gtau = False try: calc_gw = params_kw['calc_gw'] except KeyError: calc_gw = False try: calc_gl = params_kw['calc_gl'] except KeyError: calc_gl = False try: calc_dm = params_kw['calc_dm'] except KeyError: calc_dm = False Delta_iw = 0 * self.G0_iw Delta_iw << iOmega_n Delta_iw -= inverse(self.G0_iw) for block, ind in self.gf_struct: a = Delta_iw[block].fit_tail() self.eal[block] = a[0][0] G0_iw_F = 0 * self.G_iw if calc_gw: G0_w_F = 0 * self.G_w G0_iw_F << iOmega_n if calc_gw: G0_w_F << Omega for block, ind in self.gf_struct: G0_iw_F[block] -= self.eal[block] if calc_gw: G0_w_F[block] -= self.eal[block] G0_iw_F = inverse(G0_iw_F) if calc_gw: G0_w_F = inverse(G0_w_F) H_loc = 1.0 * h_int for block, ind in self.gf_struct: for ii, ii_ind in enumerate(ind): for jj, jj_ind in enumerate(ind): H_loc += self.eal[block][ii, jj] * c_dag( block, ii_ind) * c(block, jj_ind) self.ad = AtomDiag(H_loc, self.fops) self.G_iw = atomic_g_iw(self.ad, self.beta, self.gf_struct, self.n_iw) if calc_gw: self.G_w = atomic_g_w(self.ad, self.beta, self.gf_struct, (self.w_min, self.w_max), self.n_w, self.idelta) if calc_gtau: self.G_tau = atomic_g_tau(self.ad, self.beta, self.gf_struct, self.n_tau) if calc_gl: self.G_l = atomic_g_l(self.ad, self.beta, self.gf_struct, self.n_l) if calc_dm: self.dm = atomic_density_matrix(self.ad, self.beta) self.Sigma_iw = inverse(G0_iw_F) - inverse(self.G_iw) if calc_gw: self.Sigma_w = inverse(G0_w_F) - inverse(self.G_w)
def make_calc(): # ------------------------------------------------------------------ # -- Hamiltonian p = ParameterCollection( beta = 0.5, U = 0.5, nw = 1, nwf = 15, V = 1.0, eps = 0.2, ) p.nwf_gf = 4 * p.nwf p.mu = 0.5*p.U # ------------------------------------------------------------------ ca_up, cc_up = c('0', 0), c_dag('0', 0) ca_do, cc_do = c('0', 1), c_dag('0', 1) ca0_up, cc0_up = c('1', 0), c_dag('1', 0) ca0_do, cc0_do = c('1', 1), c_dag('1', 1) docc = cc_up * ca_up * cc_do * ca_do nA = cc_up * ca_up + cc_do * ca_do hybridiz = p.V * (cc0_up * ca_up + cc_up * ca0_up + cc0_do * ca_do + cc_do * ca0_do) bath_lvl = p.eps * (cc0_up * ca0_up + cc0_do * ca0_do) p.H_int = p.U * docc p.H = -p.mu * nA + p.H_int + hybridiz + bath_lvl # ------------------------------------------------------------------ # -- Exact diagonalization # Conversion from TRIQS to Pomerol notation for operator indices # TRIQS: block_name, inner_index # Pomerol: site_label, orbital_index, spin_name index_converter = { ('0', 0) : ('loc', 0, 'up'), ('0', 1) : ('loc', 0, 'down'), ('1', 0) : ('loc', 1, 'up'), ('1', 1) : ('loc', 1, 'down'), } # -- Create Exact Diagonalization instance ed = PomerolED(index_converter, verbose=True) ed.diagonalize(p.H) # -- Diagonalize H p.gf_struct = [['0', [0, 1]]] # -- Single-particle Green's functions p.G_iw = ed.G_iw(p.gf_struct, p.beta, n_iw=p.nwf_gf)['0'] # -- Particle-particle two-particle Matsubara frequency Green's function opt = dict( beta=p.beta, gf_struct=p.gf_struct, blocks=set([("0", "0")]), n_iw=p.nw, n_inu=p.nwf) p.G2_iw_ph = ed.G2_iw_inu_inup(channel='PH', **opt)[('0', '0')] filename = 'data_pomerol.h5' with HDFArchive(filename,'w') as res: res['p'] = p import os os.system('tar czvf data_pomerol.tar.gz data_pomerol.h5') os.remove('data_pomerol.h5')
def make_calc(): # ------------------------------------------------------------------ # -- Hubbard atom with two bath sites, Hamiltonian params = dict( beta=2.0, V1=2.0, V2=5.0, epsilon1=0.00, epsilon2=4.00, mu=2.0, U=5.0, ntau=40, niw=15, ) # ------------------------------------------------------------------ class Dummy(): def __init__(self): pass d = Dummy() # storage space d.params = params print '--> Solving SIAM with parameters' for key, value in params.items(): print '%10s = %-10s' % (key, str(value)) globals()[key] = value # populate global namespace # ------------------------------------------------------------------ up, do = 'up', 'dn' docc = c_dag(up, 0) * c(up, 0) * c_dag(do, 0) * c(do, 0) nA = c_dag(up, 0) * c(up, 0) + c_dag(do, 0) * c(do, 0) nB = c_dag(up, 1) * c(up, 1) + c_dag(do, 1) * c(do, 1) nC = c_dag(up, 2) * c(up, 2) + c_dag(do, 2) * c(do, 2) d.H = -mu * nA + epsilon1 * nB + epsilon2 * nC + U * docc + \ V1 * (c_dag(up,0)*c(up,1) + c_dag(up,1)*c(up,0) + \ c_dag(do,0)*c(do,1) + c_dag(do,1)*c(do,0) ) + \ V2 * (c_dag(up,0)*c(up,2) + c_dag(up,2)*c(up,0) + \ c_dag(do,0)*c(do,2) + c_dag(do,2)*c(do,0) ) # ------------------------------------------------------------------ # -- Exact diagonalization # Conversion from TRIQS to Pomerol notation for operator indices # TRIQS: block_name, inner_index # Pomerol: site_label, orbital_index, spin_name index_converter = { (up, 0): ('loc', 0, 'up'), (do, 0): ('loc', 0, 'down'), (up, 1): ('loc', 1, 'up'), (do, 1): ('loc', 1, 'down'), (up, 2): ('loc', 2, 'up'), (do, 2): ('loc', 2, 'down'), } # -- Create Exact Diagonalization instance ed = PomerolED(index_converter, verbose=True) ed.diagonalize(d.H) # -- Diagonalize H gf_struct = {up: [0], do: [0]} # -- Single-particle Green's functions G_iw = ed.G_iw(gf_struct, beta, n_iw=niw) G_tau = ed.G_tau(gf_struct, beta, n_tau=ntau) G_w = ed.G_w(gf_struct, beta, energy_window=(-2.5, 2.5), n_w=100, im_shift=0.01) d.G_iw = G_iw['up'] d.G_tau = G_tau['up'] d.G_w = G_w['up'] # -- Particle-particle two-particle Matsubara frequency Green's function opt = dict(block_order='AABB', beta=beta, gf_struct=gf_struct, blocks=set([("up", "dn")]), n_iw=niw, n_inu=niw) G2_iw = ed.G2_iw_inu_inup(channel='AllFermionic', **opt) d.G2_iw = G2_iw['up', 'dn'] G2_iw_pp = ed.G2_iw_inu_inup(channel='PP', **opt) d.G2_iw_pp = G2_iw_pp['up', 'dn'] G2_iw_ph = ed.G2_iw_inu_inup(channel='PH', **opt) d.G2_iw_ph = G2_iw_ph['up', 'dn'] # ------------------------------------------------------------------ # -- Store to hdf5 filename = 'data_pomerol.h5' with HDFArchive(filename, 'w') as res: for key, value in d.__dict__.items(): res[key] = value