def make_calc(beta=2.0, h_field=0.0): # ------------------------------------------------------------------ # -- Hubbard atom with two bath sites, Hamiltonian p = ParameterCollection( beta = beta, h_field = h_field, U = 5.0, ntau = 40, niw = 15, ) p.mu = 0.5*p.U # ------------------------------------------------------------------ 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) p.H = -p.mu * nA + p.U * docc + p.h_field * mA # ------------------------------------------------------------------ fundamental_operators = [c(up,0), c(do,0)] ed = TriqsExactDiagonalization(p.H, fundamental_operators, p.beta) g_tau = GfImTime(beta=beta, statistic='Fermion', n_points=40, 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], c(up,0), c_dag(up,0)) ed.set_g2_tau(p.G_tau[do], c(do,0), c_dag(do,0)) ed.set_g2_iwn(p.G_iw[up], c(up,0), c_dag(up,0)) ed.set_g2_iwn(p.G_iw[do], c(do,0), c_dag(do,0)) p.magnetization = ed.get_expectation_value(0.5 * mA) p.magnetization2 = ed.get_expectation_value(0.25 * mA * mA) # ------------------------------------------------------------------ # -- Store to hdf5 filename = 'data_pyed_h_field_%4.4f.h5' % h_field with HDFArchive(filename,'w') as res: res['p'] = p
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()
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=50, indices=[1]) g_iwn = GfImFreq(name='$g$', beta=beta, statistic='Fermion', n_points=10, indices=[1])
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 Results['dn'] = G_tau_do
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
index_list.append((i1, i2)) #F = 0.0001 / m.beta F = 0.1 / m.beta F_vec = np.array([-F, F]) work_list = np.array(index_list) work_list = mpi.slice_array(work_list) for i1, i2 in work_list: o1, o2 = m.op_imp[i1], m.op_imp[i2] O1 = dagger(o1) * o2 O1 = O1 + dagger(O1) ed_p = TriqsExactDiagonalization(m.H + F * O1, m.op_full, m.beta) ed_m = TriqsExactDiagonalization(m.H - F * O1, m.op_full, m.beta) p.g_tau_field[(i1, i2)] = g_tau.copy() ed_p.set_g2_tau_matrix(p.g_tau_field[(i1, i2)], m.op_imp) for i3, i4 in itertools.product(range(4), repeat=2): o3, o4 = m.op_imp[i3], m.op_imp[i4] O2 = dagger(o3) * o4 O2_vec = np.zeros(2, dtype=np.complex) O2_vec[0] = ed_m.get_expectation_value(O2) O2_vec[1] = ed_p.get_expectation_value(O2) p.chi_field[i1, i2, i3, i4] = -(O2_vec[1] - O2_vec[0])/(2*F)
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)
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) # ------------------------------------------------------------------ # -- 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=500, indices=['A', 'B']) for (i1, s1), (i2, s2) in itertools.product([('A', up), ('B', do)], repeat=2): print i1, s1, i2, s2 ed.set_g2_tau(g_tau[i1, i2], c(s1, 0), c_dag(s2, 0))
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
from pyed.ParameterCollection import ParameterCollection from pyed.TriqsExactDiagonalization import TriqsExactDiagonalization # ---------------------------------------------------------------------- if __name__ == '__main__': if mpi.is_master_node(): with HDFArchive('data_model.h5', 'r') as A: m = A["p"] else: m = None m = mpi.bcast(m) p = ParameterCollection() ed = TriqsExactDiagonalization(m.H, m.op_full, m.beta) p.O1_exp = np.zeros((4, 4), dtype=np.complex) p.O2_exp = np.zeros((4, 4), dtype=np.complex) p.chi_dissconn = np.zeros((4, 4, 4, 4), dtype=np.complex) p.chi_static = np.zeros((4, 4, 4, 4), dtype=np.complex) p.chi_tau = GfImTime(name=r'$g$', beta=m.beta, statistic='Boson', n_points=50, target_shape=(4, 4, 4, 4)) p.chi = np.zeros_like(p.chi_static)
T_imp = block_diag(T_imp, T_imp) T_bath = block_diag(T_bath, T_bath) print 'V =\n', V print 'T_imp =\n', T_imp print 'T_bath =\n', T_bath T = np.block([[T_imp, V], [V.T, T_bath]]) print 'T =\n', T H_int = h_int_kanamori(spin_names, imp_idxs, np.array([[0, U - 3 * J], [U - 3 * J, 0]]), np.array([[U, U - 2 * J], [U - 2 * J, U]]), J, True) H = H_int + get_quadratic_operator(T, fop) ed = TriqsExactDiagonalization(H, fop, beta) n_tau = 101 G_tau_up = Gf(mesh=MeshImTime(beta, 'Fermion', n_tau), target_shape=[2, 2]) G_tau_do = Gf(mesh=MeshImTime(beta, 'Fermion', n_tau), target_shape=[2, 2]) for i1, i2 in itertools.product(range(norb), repeat=2): ed.set_g2_tau(G_tau_up[i1, i2], c('up', i1), c_dag('up', i2)) ed.set_g2_tau(G_tau_do[i1, i2], c('do', i1), c_dag('do', i2)) with HDFArchive('kanamori_offdiag.pyed.h5', 'w') as Results: Results['up'] = G_tau_up Results['dn'] = G_tau_do