def window_conv_depr():

    nwf_vec = np.array([5, 10, 20, 40, 80, 160, 320])
    diff_vec = np.zeros_like(nwf_vec, dtype=np.float)

    for idx, nwf in enumerate(nwf_vec):
        d = analytic_solution(beta=2.0, U=5.0, nw=1, nwf=nwf)
        diff = np.max(np.abs(d.gamma_m.data - d.gamma_m_num.data))
        diff_vec[idx] = diff
        print 'nwf, diff =', idx, nwf, diff

    print diff_vec

    from pytriqs.plot.mpl_interface import oplot, oplotr, oploti, plt

    x = 1. / nwf_vec

    plt.figure(figsize=(3.25, 3))

    plt.plot(x, diff_vec, 'o-', alpha=0.75)
    plt.xlabel(r'$1/n_{w}$')
    plt.ylabel(r'$\max|\Gamma_{ana} - \Gamma_{num}|$')
    plt.ylim([0, diff_vec.max()])
    plt.xlim([0, x.max()])

    plt.tight_layout()
    plt.savefig('figure_bse_hubbard_atom_convergence.pdf')
    plt.show()
Exemple #2
0
    def plot_histos(title,histos):
        a = plt.gca()
        a.set_xlim((0,beta))
        a.set_xlabel('$\\Delta\\tau$')
        a.set_ylabel(title)

        for name, histo in histos.items():
            w = histo.data
            dtau = [histo.mesh_point(n) for n in range(len(histo))]
            plt.plot(dtau,w,label=name,linewidth=0.7)

        a.legend(loc='upper center',prop={'size':10})
Exemple #3
0
def plot_chi_k(p, color=None):

    chi_k = p.chi_kw[:, Idx(0)]

    k_vecs, k_plot, K_plot, K_labels = get_path()
    kx, ky, kz = k_vecs.T

    interp = np.vectorize(lambda kx, ky, kz : np.squeeze(chi_k([kx, ky, kz]).real))
    interp = interp(kx, ky, kz)
    p.chi_G = np.squeeze(chi_k[Idx(0, 0, 0)].real)    

    line = plt.plot(k_plot, interp, '-', label=r'$N_{\nu} = $'+'${:d}$'.format(p.nwf))

    plt.gca().set_xticks(K_plot); plt.gca().set_xticklabels(K_labels)
    plt.grid(True); plt.ylabel(r'$\chi(\mathbf{Q})$')
    plt.legend(loc='best', fontsize=8)
    return line[0].get_color()
Exemple #4
0
def plot_ps(ps):

    subp = [2, 1, 1]

    plt.subplot(*subp)
    subp[-1] += 1
    plt.plot(ps.iter, ps.dG_l, 's-', label=r'$\Delta G_l$')
    plt.plot(ps.iter, ps.dM, 'o-', label=r'$\Delta M$')
    plt.semilogy([], [])
    plt.ylabel('$\Delta G_l$, $\Delta M$')
    plt.legend(loc='best')
    plt.xlabel('Iteration')

    plt.subplot(*subp)
    subp[-1] += 1
    plt.plot(ps.iter, ps.B, 's-', label=r'$B$')
    plt.plot(ps.iter, ps.M, 'o-', label=r'$M$')
    plt.ylabel(r'$M$, $B$')
    plt.legend(loc='best')
    plt.xlabel('Iteration')

    plt.tight_layout()
    plt.savefig('figure_field_sc.svg')
Exemple #5
0
def plot_field(out):

    plt.figure(figsize=(3.25 * 2, 8))
    for p in out.data:

        subp = [2, 1, 1]

        ax = plt.subplot(*subp)
        subp[-1] += 1
        oplotr(p.G_tau['up'], 'b', alpha=0.25)
        oplotr(p.G_tau['dn'], 'g', alpha=0.25)
        ax.legend().set_visible(False)

    plt.subplot(*subp)
    subp[-1] += 1
    plt.title(r'$\chi \approx %2.2f$' % out.chi)
    plt.plot(out.h_vec, out.m_vec, '-og', alpha=0.5)
    plt.plot(out.h_vec, out.m_ref_vec, 'xb', alpha=0.5)
    plt.plot(out.h_vec, -out.chi * out.h_vec, '-r', alpha=0.5)

    plt.tight_layout()
    plt.savefig('figure_static_field.pdf')
Exemple #6
0
    plt.figure(figsize=(3.25, 2 * 3))
    plt.title('Magnetic Susceptibility\n Hubbard atom + 2 bath sites.')

    # ------------------------------------------------------------------
    # -- external field pyed

    filenames = glob.glob('pyed_beta*/data_pyed_extrap*.h5')

    style = 'sk'
    for filename in filenames:
        print '--> Loading:', filename

        with HDFArchive(filename, 'r') as s:
            field = s['field']

        plt.plot(1. / field.beta, field.chi, style, alpha=0.25)

    plt.plot([], [], style, alpha=0.25, label='ed field')

    # ------------------------------------------------------------------
    # -- dynamic pomerol

    filenames = glob.glob('pomerol_*/*.h5')

    styles = {2: '.m', 4: '.c', 8: '.y'}

    for filename in filenames:
        print '--> Loading:', filename
        with HDFArchive(filename, 'r') as s:
            p = s['p']
Exemple #7
0
with HDFArchive(filename, 'w') as a:
    a['order_max'] = order_max
    a['n_min'], a['n_max'] = n_min, n_max
    a['Delta_iw'] = Delta_iw
    a['Delta_iw_ref'] = Delta_iw_ref
    a['Delta_iw_fit'] = Delta_iw_fit

# -- Plot 

from pytriqs.plot.mpl_interface import oplot, oplotr, oploti, plt
plt.figure(figsize=(10, 10))

ylim = [-4, 4]

plt.plot([w_min.imag]*2, ylim, 'sr-', lw=0.5)
plt.plot([w_max.imag]*2, ylim, 'sr-', lw=0.5)
         
for i1, i2 in itertools.product(range(2), repeat=2):
    oplotr(Delta_iw[i1, i2], alpha=0.1)
    oploti(Delta_iw[i1, i2], alpha=0.1)

    oplotr(Delta_iw_ref[i1, i2], lw=4, alpha=0.25)
    oploti(Delta_iw_ref[i1, i2], lw=4, alpha=0.25)

    oplotr(Delta_iw_fit[i1, i2])
    oploti(Delta_iw_fit[i1, i2])

ax = plt.gca()
ax.legend_ = None
Exemple #8
0
    plt.gca().set_xticks(K_plot); plt.gca().set_xticklabels(K_labels)
    plt.grid(True); plt.ylabel(r'$\chi(\mathbf{Q})$')
    plt.legend(loc='best', fontsize=8)
    return line[0].get_color()

plt.figure(figsize=(3.25*2, 3))

ps, color = [], None
for filename in np.sort(glob.glob('data_bse_nwf*.h5')):
    with HDFArchive(filename, 'r') as a: p = a['p']
    subp = [1, 2, 1]
    plt.subplot(*subp); subp[-1] += 1
    color = plot_chi_k(p)
    plt.subplot(*subp); subp[-1] += 1
    plt.plot(1./p.nwf, p.chi_G, 'o', color=color)
    ps.append(p)

# -- Extrapolation to nwf -> oo
ps = ParameterCollections(objects=ps)
x, y = 1./ps.nwf, ps.chi_G
sidx = np.argsort(x)
x, y = x[sidx], y[sidx]
p = np.polyfit(x, y, 1)
y0 = np.polyval(p, 0)
X = np.linspace(0, x.max())
Y = np.polyval(p, X)

subp = [1, 2, 1]
plt.subplot(*subp); subp[-1] += 1
plt.plot(0, y0, 'rx')
Exemple #9
0
              r'half-filled Hubbard atom $U=%2.2f$' % U)

    # ------------------------------------------------------------------
    # -- Analytic result

    T = np.logspace(-3, 2, num=400)
    beta = 1. / T

    # -- Analytic magnetization expecation value
    # -- and static susceptibility

    Z = 2. + 2 * np.exp(-beta * 0.5 * U)
    m2 = 0.25 * (2 / Z)
    chi_m = 2. * beta * m2

    plt.plot(1. / beta, chi_m, '-k', lw=0.5)

    # ------------------------------------------------------------------
    # -- external field pyed

    filenames = glob.glob('pyed_beta*/data_pyed_extrap*.h5')

    style = 'sk'
    for filename in filenames:
        print '--> Loading:', filename

        with HDFArchive(filename, 'r') as s:
            field = s['field']

        plt.plot(1. / field.beta, field.chi, style, alpha=0.25)
        plt.plot(1. / field.beta, field.chi_exp, '.r', alpha=0.25)
Exemple #10
0
    plt.figure(figsize=(3.25 * 2, 8))

    subp = [3, 1, 1]
    plt.subplot(*subp)
    subp[-1] += 1

    #oplotr(O_tau_regr, '-', label=r'cthyb regr $-\langle n_\uparrow(\tau) n_\downarrow \rangle$ (should be bad)', alpha=1.0, lw=1.0, zorder=100)
    oplotr(cthyb.O_tau,
           '-',
           label=r'cthyb $\langle n_\uparrow(\tau) n_\downarrow \rangle$',
           alpha=0.5,
           lw=0.5)
    oplotr(pyed.O_tau,
           label=r'pyed $\langle n_\uparrow(\tau) n_\downarrow \rangle$')

    plt.plot(0, cthyb.exp_val, 'or', alpha=0.25, clip_on=False)
    plt.plot(0, pyed.exp_val, 'xg', alpha=0.25, clip_on=False)

    plt.subplot(*subp)
    subp[-1] += 1
    tau = np.array([float(t) for t in cthyb.O_tau.mesh])

    tau_ref = np.array([float(t) for t in pyed.O_tau.mesh])
    O_ref = pyed.O_tau.data.copy()
    O_interp = np.interp(tau, tau_ref, O_ref)

    O_tau_diff = cthyb.O_tau.copy()
    O_tau_diff.data[:] -= O_interp
    O_tau_diff.name = r'$\Delta$' + 'O_tau'

    oplotr(O_tau_diff, '-', label=r'cthyb - pyed', alpha=0.75)
Exemple #11
0
from pytriqs.gf import *
from pytriqs.plot.mpl_interface import plt

arch = HDFArchive('legendre.h5', 'r')
ed_arch = HDFArchive('legendre.ed.h5', 'r')

plt.figure()
subp = [2, 1, 1]

plt.subplot(*subp)
subp[-1] += 1

for spin in ("up", "dn"):
    plt.plot(arch['G_l'][spin].data.flatten(),
             label="cthyb," + {
                 'up': "$\uparrow\uparrow$",
                 'dn': "$\downarrow\downarrow$"
             }[spin])
    plt.plot(ed_arch[spin].data.flatten(),
             label="ED," + {
                 'up': "$\uparrow\uparrow$",
                 'dn': "$\downarrow\downarrow$"
             }[spin])

axes = plt.gca()
axes.set_xlabel('$l$')
axes.set_ylabel('$G_l$')
axes.set_ylim((-2.0, 1.0))
axes.legend(loc='lower center', prop={'size': 10})

plt.subplot(*subp)
Exemple #12
0
for q in [ [0,0,0], [n_k/2, n_k/2, 0], [n_k/2, 0, 0] ]:

    qidx = bzmesh.index_to_linear(q)

    print '-'*72
    print 'q =', q
    print 'qidx =', qidx
    print 'q_list[qidx] =', q_list[qidx]
    print 'q_list[qidx]/np.pi =', np.array(q_list[qidx])/np.pi
    
    data = np.squeeze(chi0w0.data[:, qidx])
    print data.shape
    
    plt.subplot(*subp); subp[-1] += 1
    plt.title(r'$q = \pi \times$ %s' % str(np.array(q_list[qidx])/np.pi))
    plt.plot(data.real)
    plt.ylabel(r'Re[$\chi_0(i\omega)$]')
    plt.ylim([-vmax, 0.1*vmax])

    plt.subplot(*subp); subp[-1] += 1
    plt.plot(data.imag)
    plt.ylabel(r'Im[$\chi_0(i\omega)$]')

    plt.subplot(*subp); subp[-1] += 1
    plt.pcolormesh(chi0q.data[:,:,qidx,0,0,0,0].real, **opt)
    plt.colorbar()
    plt.axis('equal')
    plt.title(r'Re[$\chi_0(i\omega, i\nu)$]')
    plt.xlabel(r'$\nu$')
    plt.ylabel(r'$\omega$')
Exemple #13
0
#!/bin/env pytriqs

from pytriqs.archive import *
from pytriqs.gf.local import *
from pytriqs.plot.mpl_interface import plt

arch = HDFArchive('legendre.h5','r')
ed_arch = HDFArchive('legendre.ed.h5','r')

for spin in ("up","dn"):
    plt.plot(arch['G_l'][spin].data.flatten(),label="cthyb," + {'up':"$\uparrow\uparrow$",'dn':"$\downarrow\downarrow$"}[spin])
    plt.plot(ed_arch[spin].data.flatten(),label="ED," + {'up':"$\uparrow\uparrow$",'dn':"$\downarrow\downarrow$"}[spin])

axes = plt.gca()
axes.set_xlabel('$l$')
axes.set_ylabel('$G_l$')
axes.set_ylim((-2.0,1.0))
axes.legend(loc='lower center',prop={'size':10})

plt.savefig('G_l.pdf')
Exemple #14
0
#
################################################################################

from common import *
from pytriqs.plot.mpl_interface import oplot, oplotr, oploti, plt

with HDFArchive('data_sc.h5', 'r') as a:
    ps = a['ps']
p = ps.objects[-1]

plt.figure(figsize=(3.25 * 2, 5))
subp = [2, 2, 1]

plt.subplot(*subp)
subp[-1] += 1
plt.plot(ps.iter, ps.dG_l, 's-')
plt.ylabel('$\max | \Delta G_l |$')
plt.xlabel('Iteration')
plt.semilogy([], [])

plt.subplot(*subp)
subp[-1] += 1
for b, g in p.G_l:
    p.G_l[b].data[:] = np.abs(g.data)
oplotr(p.G_l['up'], 'o-', label=None)
plt.ylabel('$| G_l |$')
plt.semilogy([], [])

plt.subplot(*subp)
subp[-1] += 1
oplotr(p.G_tau_raw['up'], alpha=0.75, label='Binned')
Exemple #15
0
ps = []
filenames = np.sort(glob.glob('data_B_*.h5'))
for filename in filenames:
    with HDFArchive(filename, 'r') as a:
        p = a['ps'].objects[-1]
    ps.append(p)
ps = ParameterCollections(ps)

B, M = ps.B, ps.M
B = np.concatenate((-B[1:][::-1], B))
M = np.concatenate((-M[1:][::-1], M))
p = np.polyfit(M, B, 5)
m = np.linspace(-0.5, 0.5, num=1000)
b = np.polyval(p, m)
chi = 1. / np.polyval(np.polyder(p, 1), 0.).real

plt.figure(figsize=(3.25 * 1.5, 2.5 * 1.5))
plt.title(r'$\chi = \frac{dM}{dB}|_{B=0} \approx $' + '$ {:3.4f}$'.format(chi))
plt.plot(B, M, 'o', alpha=0.75, label='DMFT field')
plt.plot(b, m, '-', alpha=0.75, label='Poly fit')
plt.legend(loc='upper left')
plt.grid(True)
plt.xlabel(r'$B$')
plt.ylabel(r'$M$')
plt.xlim([B.min(), B.max()])
plt.ylim([-0.5, 0.5])
plt.tight_layout()
plt.savefig('figure_field.svg')
plt.show()
Exemple #16
0
    for idx, nwf in enumerate(nwf_vec):
        d = analytic_hubbard_atom(beta=2.0,
                                  U=5.0,
                                  nw=1,
                                  nwf=nwf,
                                  nwf_gf=2 * nwf)
        diff_vec[idx] = np.max(np.abs(d.gamma_m.data - d.gamma_m_num.data))
        print 'nwf, diff =', idx, nwf, diff_vec[idx]

    # ------------------------------------------------------------------
    # -- Plot

    from pytriqs.plot.mpl_interface import oplot, oplotr, oploti, plt

    x = 1. / nwf_vec

    plt.figure(figsize=(3.25, 3))

    plt.plot(x, diff_vec, 'o-', alpha=0.75)

    plt.xlabel(r'$1/n_{w}$')
    plt.ylabel(r'$\max|\Gamma_{ana} - \Gamma_{num}|$')

    plt.ylim([0, diff_vec.max()])
    plt.xlim([0, x.max()])

    plt.tight_layout()
    plt.savefig('figure_bse_hubbard_atom_convergence.pdf')

    plt.show()