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 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
# -- 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]) ed.set_g2_tau(g_tau, c(up, 0), c_dag(up, 0)) ed.set_g2_iwn(g_iwn, c(up, 0), c_dag(up, 0)) # ------------------------------------------------------------------ # -- Two particle Green's functions
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
print g(tau.real) 2. Linear interpolation for higher order tau greens function g4_tau(t1, t2, t3) """ import itertools import numpy as np from pytriqs.gf import Gf, GfImTime, MeshImTime, MeshProduct ntau = 10 beta = 1.2345 g_tau = GfImTime(name='g_tau', beta=beta, statistic='Fermion', n_points=ntau, indices=[1]) tau = np.array([tau.value for tau in g_tau.mesh]) g_ref = np.exp(-beta * tau) g_tau.data[:, 0, 0] = np.exp(-beta * tau) for tau in g_tau.mesh: g_tau[tau] = np.exp(-beta * tau) for idx, tau in enumerate(g_tau.mesh): # comparison does not work at beta since the evaluation g_tau() wraps.. if idx == len(g_tau.mesh)-1: break #diff_interp = g_tau(tau)[0,0] - g_ref[idx] # FIXME: tau is complex
2. Linear interpolation for higher order tau greens function g4_tau(t1, t2, t3) """ import itertools import numpy as np from pytriqs.gf import Gf, GfImTime, MeshImTime, MeshProduct ntau = 10 beta = 1.2345 g_tau = GfImTime(name='g_tau', beta=beta, statistic='Fermion', n_points=ntau, indices=[1]) tau = np.array([tau.value for tau in g_tau.mesh]) g_ref = np.exp(-beta * tau) g_tau.data[:, 0, 0] = np.exp(-beta * tau) for tau in g_tau.mesh: g_tau[tau] = np.exp(-beta * tau) for idx, tau in enumerate(g_tau.mesh): # comparison does not work at beta since the evaluation g_tau() wraps.. if idx == len(g_tau.mesh) - 1: break
# ---------------------------------------------------------------------- if __name__ == '__main__': if mpi.is_master_node(): with HDFArchive('data_model.h5','r') as A: m = A["p"] with HDFArchive('data_pyed.h5','r') as A: p = A["p"] else: m, p = None, None m, p = mpi.bcast(m), mpi.bcast(p) p.chi_field = np.zeros((4, 4, 4, 4), dtype=np.complex) p.g_tau_field = {} g_tau = GfImTime(name=r'$g$', beta=m.beta, statistic='Fermion', n_points=50, target_shape=(4, 4)) # -- The field is symmetric in (i1, i2) # -- only calculate upper triangle index_list = [] for i1 in xrange(4): for i2 in xrange(i1, 4): 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)
# -- Weiss field of the bath h_tot = quadratic_matrix_from_operator(p.H_bath + p.H_loc, p.op_full) g0_iw = GfImFreq(beta=p.beta, statistic='Fermion', n_points=p.nw, target_shape=(8, 8)) g0_iw << inverse(iOmega_n - h_tot) p.g0_iw = g0_iw[:4, :4] # -- Cut out impurity Gf p.g0t_iw = g2_single_particle_transform(p.g0_iw, p.T.H) p.g0_tau = GfImTime(beta=p.beta, statistic='Fermion', n_points=p.ntau, target_shape=(4, 4)) p.g0_tau << InverseFourier(p.g0_iw) p.g0t_tau = g2_single_particle_transform(p.g0_tau, p.T.H) p.g0_tau_ref = g2_single_particle_transform(p.g0t_tau, p.T) np.testing.assert_array_almost_equal(p.g0_tau_ref.data, p.g0_tau.data) # -- Interaction Hamiltonian: Kanamori interaction U_ab, UPrime_ab = U_matrix_kanamori(n_orb=p.num_orbitals, U_int=p.U, J_hund=p.J) H_int = h_int_kanamori(p.spin_names,
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)
# -- 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, target_shape=(1, 1)) g_iwn = GfImFreq(name='$g$', beta=beta, statistic='Fermion', n_points=10, target_shape=(1, 1)) ed.set_g2_tau(g_tau, c(up, 0), c_dag(up, 0)) ed.set_g2_iwn(g_iwn, c(up, 0), c_dag(up, 0)) # ------------------------------------------------------------------ # -- Two particle Green's functions
from pytriqs.plot.mpl_interface import * from pytriqs.operators.util.op_struct import get_mkind from matplotlib.backends.backend_pdf import PdfPages # Read the reference table file tau = [] data = [] for line in open("5_plus_5.ref.dat", 'r'): cols = line.split() tau.append(float(cols[0])) data.append([-float(c) for c in cols[1:]]) beta = tau[-1] n_tau = len(tau) g_ref = GfImTime(indices=range(len(data[0])), beta=beta, n_points=n_tau) for nt, d in enumerate(data): for nc, val in enumerate(d): g_ref.data[nt, nc, nc] = val for filename in ["5_plus_5.int.h5", "5_plus_5.h5"]: # Read the results #arch = HDFArchive("5_plus_5.h5",'r') #arch = HDFArchive("5_plus_5.int.h5",'r') arch = HDFArchive(filename, 'r') use_interaction = arch['use_interaction'] spin_names = arch['spin_names'] orb_names = arch['orb_names'] delta_params = arch['delta_params']
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
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) tau = np.array([float(tau) for tau in p.chi_tau.mesh]) for i1, i2, i3, i4, in itertools.product(range(4), repeat=4): print i1, i2, i3, i4 o1, o2, o3, o4 = m.op_imp[i1], m.op_imp[i2], m.op_imp[i3], m.op_imp[i4] O1 = dagger(o1) * o2 O2 = dagger(o3) * o4