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()
def plot_p(p): xlim = [-50, 50] subp = [3, 1, 1] plt.subplot(*subp) subp[-1] += 1 oploti(p.g0_w[0, 0], label=r'$G_0(i\omega_n)$') oploti(p.g_w[0, 0], label=r'$G(i\omega_n)$') oploti(p.sigma_w[0, 0], label=r'$\Sigma(i\omega_n)$') plt.legend(loc='best') plt.xlim(xlim) plt.subplot(*subp) subp[-1] += 1 oplotr(p.G_tau_raw['up'], alpha=0.75) oplotr(p.G_tau['up']) plt.gca().legend().set_visible(False) plt.subplot(*subp) subp[-1] += 1 G_l = p.G_l.copy() for b, g in G_l: G_l[b].data[:] = np.abs(g.data) oplotr(G_l['up'], 'o-') plt.semilogy([], []) plt.gca().legend().set_visible(False) plt.tight_layout() plt.savefig('figure_field_sc_gf.svg')
def plot_dynamic(p): plt.figure(figsize=(3.25 * 2, 8)) subp = [3, 2, 1] G2_iw_ph = p.G2_iw_ph d = np.squeeze(p.G2_iw_ph[('up', 'up')].data) lim = np.max([np.abs(d.real), np.abs(d.imag)]) opt = dict(vmin=-lim, vmax=lim, cmap='PuOr') ax = plt.subplot(*subp) subp[-1] += 1 plt.pcolormesh(d.real, **opt) ax = plt.subplot(*subp) subp[-1] += 1 plt.pcolormesh(d.imag, **opt) d = np.squeeze(p.G2_iw_ph[('up', 'do')].data) ax = plt.subplot(*subp) subp[-1] += 1 plt.pcolormesh(d.real, **opt) ax = plt.subplot(*subp) subp[-1] += 1 plt.pcolormesh(d.imag, **opt) d = np.squeeze(p.chi_m.data) lim = np.max([np.abs(d.real), np.abs(d.imag)]) ax = plt.subplot(*subp) subp[-1] += 1 plt.pcolormesh(d.real, **opt) ax = plt.subplot(*subp) subp[-1] += 1 plt.pcolormesh(d.imag, **opt) plt.tight_layout() plt.savefig('figure_dynamic.pdf')
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')
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')
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 plt.ylim([-1, 1]) plt.tight_layout() plt.savefig(figure_filename) plt.show(); exit()
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') plt.plot(0, 0.3479, 'r+') plt.subplot(*subp); subp[-1] += 1 plt.plot(X, Y, '--k', lw=1.0, zorder=-100) plt.plot(0, 0.3479, 'r+', label=r'Field') plt.plot(0, y0, 'rx', label=r'BSE') plt.grid(True); plt.legend(loc='best', fontsize=8) plt.xlabel(r'$1/N_\nu$'); plt.ylabel(r'$\chi(\mathbf{0})$') plt.title( r'$\lim_{n_\nu \rightarrow \infty} \, \chi(\mathbf{0}) \approx $' + \ '${:3.4f}$'.format(y0)) plt.tight_layout() plt.savefig('figure_bse.svg') plt.show()
from pytriqs.plot.mpl_interface import oplot, oplotr, plt with HDFArchive('data_g2.h5', 'r') as a: p = a['p'] plt.figure(figsize=(3.25 * 2.2, 2)) subp = [1, 3, 1] opt = dict(cmap=plt.get_cmap('terrain_r'), vmin=0.0, vmax=0.01) plt.subplot(*subp) subp[-1] += 1 plt.title(r'$\chi^{(0)}_m$') plt.imshow(np.squeeze(p.chi0_m.data).real, **opt) plt.colorbar() plt.subplot(*subp) subp[-1] += 1 plt.title(r'$\chi_m$') plt.imshow(np.squeeze(p.chi_m.data).real, **opt) plt.colorbar() plt.subplot(*subp) subp[-1] += 1 plt.title(r'$\Gamma_m - U$') plt.imshow((np.squeeze(p.gamma_m.data) - p.U).real, cmap=plt.get_cmap('RdBu_r'), vmin=-5, vmax=5) plt.colorbar() plt.tight_layout() plt.savefig('figure_g2.svg') plt.show()
styles = {256: '^b', 128: '>r', 64: '<g', 32: '.m', 16: '.c', 8: '.y'} for filename in filenames: print '--> Loading:', filename with HDFArchive(filename, 'r') as s: p = s['p'] if hasattr(p, 'chi'): style = styles[p.nwf] plt.plot(1. / p.beta, p.chi, style, alpha=0.5) for nw in np.sort(styles.keys()): style = styles[nw] plt.plot([], [], style, alpha=0.5, label=r'Analytic Tr$[\chi_m]/\beta^2$, $n_w=%i$' % nw) # ------------------------------------------------------------------ plt.legend(loc='best', fontsize=6, frameon=False) #plt.xlabel(r'$\beta$') plt.xlabel(r'$T$') plt.ylabel(r'$\chi_m$') plt.loglog([], []) plt.tight_layout() plt.savefig('figure_hubbard_atom_static_magnetic_susceptibility.pdf') plt.show()
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()
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) subp[-1] += 1 for spin in ("up", "dn"): plt.plot(np.abs(arch['G_l'][spin].data.flatten()), label="cthyb," + { 'up': "$\uparrow\uparrow$", 'dn': "$\downarrow\downarrow$" }[spin]) plt.plot(np.abs(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.legend(loc='best', prop={'size': 10}) plt.semilogy([], []) plt.tight_layout() plt.savefig('G_l.pdf')
qy = np.array([q[1] for q in q_list])/np.pi data = np.squeeze(chi0w0.data[iw_zero_idx]) data = -1.0 * data vmax = np.max(data.real) plt.title('Square-lattice ' + r'$\chi_0(q, \omega=0)$, $\beta=%2.2f$' % beta) plt.pcolor(qx.reshape((n_k, n_k)), qy.reshape((n_k, n_k)), data.reshape((n_k, n_k)).real, cmap='magma', vmin=0, vmax=vmax) plt.colorbar() plt.axis('equal') plt.xlabel('$q_x/\pi$') plt.ylabel('$q_y/\pi$') plt.tight_layout() plt.savefig('figure_chi0q_w0_square_latt.pdf') # -- Plot Gamma and M point dynamic susceptibilities opt = dict(vmin=-0.01, vmax=0.01, cmap='PuOr') plt.figure(figsize=(12, 8)) subp = [3, 4, 1] 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
#!/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')
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') oplotr(p.G_tau['up'], label='Legendre') plt.legend(loc='best', fontsize=8) plt.ylabel(r'$G(\tau)$') plt.subplot(*subp) subp[-1] += 1 oploti(p.sigma_w[0, 0], '.-', label=None) plt.ylabel(r'$\Sigma(i\omega_n)$') plt.xlim([-100, 100]) plt.tight_layout() plt.savefig('figure_sc.svg') plt.show()
def dcore_check(filename, fileplot=None): """ Main routine for checking convergence Parameters ---------- filename : string Input-file name fileplot : string Output file name. File format is determined by the extension (pdf, eps, jpg, etc). """ if mpi.is_master_node(): print("\n @ Reading {0} ...".format(filename)) # # Construct a parser with default values # pars = create_parser() # # Parse keywords and store # pars.read(filename) p = pars.as_dict() # solver = DMFTCoreSolver(p["model"]["seedname"], p) # # Just for convenience sol = solver.S output_file = p["model"]["seedname"] + '.out.h5' output_group = 'dmft_out' beta = p["system"]["beta"] omega_check = p['tool']['omega_check'] gs = GridSpec(2, 1) if fileplot is not None: # if graph is to be printed in a file import matplotlib matplotlib.use('Agg') # do not plot on x11 from pytriqs.plot.mpl_interface import oplot, plt plt.figure(figsize=(8, 10)) # # Chemical potential # ar = HDFArchive(output_file, 'r') iteration_number = ar[output_group]['iterations'] perform_tail_fit = p["system"]["perform_tail_fit"] and \ not ar[output_group]['parameters']["system"]["perform_tail_fit"] nsh = solver.SK.n_inequiv_shells print(" Total number of Iteration: {0}".format(iteration_number)) print("\n Iter Chemical-potential") for itr in range(1, iteration_number + 1): print(" {0} {1}".format( itr, ar[output_group]['chemical_potential'][str(itr)])) # # Read Sigma and average it # sigma_ave = [] sigma_fit = [] nsigma = 0 itr_sigma = [0] * 7 for itr in range(1, iteration_number + 1): if itr > iteration_number - 7: itr_sigma[nsigma] = itr sigma_ave.append( GfImFreq(indices=[0], beta=beta, n_points=p["system"]["n_iw"])) sigma_fit.append( GfImFreq(indices=[0], beta=beta, n_points=p["system"]["n_iw"])) sigma_ave[nsigma].data[:, 0, 0] = 0.0 sigma_fit[nsigma].data[:, 0, 0] = 0.0 norb_tot = 0 for ish in range(nsh): spn = solver.SK.spin_block_names[solver.SK.corr_shells[ solver.SK.inequiv_to_corr[ish]]['SO']] norb = solver.SK.corr_shells[ solver.SK.inequiv_to_corr[ish]]['dim'] sol[ish].Sigma_iw << ar[output_group]['Sigma_iw'][str(itr)][ str(ish)] sigma_iw_fit = sol[ish].Sigma_iw.copy() if perform_tail_fit: tail_fit(sigma_iw_fit, fit_max_moment=p["system"]["fit_max_moment"], fit_min_w=p["system"]["fit_min_w"], fit_max_w=p["system"]["fit_max_w"]) for isp in spn: for iorb in range(norb): norb_tot += 1 for jorb in range(norb): sigma_ave[nsigma].data[:, 0, 0] += sol[ ish].Sigma_iw[isp].data[:, iorb, jorb] sigma_fit[nsigma].data[:, 0, 0] += sigma_iw_fit[ isp].data[:, iorb, jorb] sigma_ave[nsigma].data[:, 0, 0] /= norb_tot sigma_fit[nsigma].data[:, 0, 0] /= norb_tot nsigma += 1 # # Real part # plt.subplot(gs[0]) for itr in range(nsigma): oplot(sigma_ave[itr], '-o', mode='R', x_window=(0.0, omega_check), name='Sigma-%s' % itr_sigma[itr]) if perform_tail_fit: oplot(sigma_fit[itr], '-o', mode='R', x_window=(0.0, omega_check), name='S_fit-%s' % itr_sigma[itr]) plt.legend(loc=0) # # Imaginary part # plt.subplot(gs[1]) for itr in range(nsigma): oplot(sigma_ave[itr], '-o', mode='I', x_window=(0.0, omega_check), name='Sigma-%s' % itr_sigma[itr]) if perform_tail_fit: oplot(sigma_fit[itr], '-o', mode='I', x_window=(0.0, omega_check), name='S_fit-%s' % itr_sigma[itr]) plt.legend(loc=0) plt.show() if fileplot is not None: plt.savefig(fileplot) # # Output Sigma into a text file # print("\n Output Local Self Energy : ", p["model"]["seedname"] + "_sigma.dat") with open(p["model"]["seedname"] + "_sigma.dat", 'w') as fo: print("# Local self energy at imaginary frequency", file=fo) # # Column information # print("# [Column] Data", file=fo) print("# [1] Frequency", file=fo) icol = 1 for ish in range(nsh): spn = solver.SK.spin_block_names[solver.SK.corr_shells[ solver.SK.inequiv_to_corr[ish]]['SO']] norb = solver.SK.corr_shells[solver.SK.inequiv_to_corr[ish]]['dim'] for isp in spn: for iorb in range(norb): for jorb in range(norb): icol += 1 print("# [%d] Re(Sigma_{shell=%d, spin=%s, %d, %d})" % (icol, ish, isp, iorb, jorb), file=fo) icol += 1 print("# [%d] Im(Sigma_{shell=%d, spin=%s, %d, %d})" % (icol, ish, isp, iorb, jorb), file=fo) # # Write data # omega = [x for x in sol[0].Sigma_iw.mesh] for iom in range(len(omega)): print("%f " % omega[iom].imag, end="", file=fo) for ish in range(nsh): spn = solver.SK.spin_block_names[solver.SK.corr_shells[ solver.SK.inequiv_to_corr[ish]]['SO']] norb = solver.SK.corr_shells[ solver.SK.inequiv_to_corr[ish]]['dim'] for isp in spn: for iorb in range(norb): for jorb in range(norb): print("%f %f " % (sol[ish].Sigma_iw[isp].data[iom, iorb, jorb].real, sol[ish].Sigma_iw[isp].data[iom, iorb, jorb].imag), end="", file=fo) print("", file=fo) # # Output Legendre polynomial # if p["system"]["n_l"] > 0: # # Output Sigma into a text file # print("\n Output Local Self Energy : ", p["model"]["seedname"] + "_legendre.dat") with open(p["model"]["seedname"] + "_legendre.dat", 'w') as fo: print("# Local self energy at imaginary frequency", file=fo) # # Column information # print("# [Column] Data", file=fo) print("# [1] Order of Legendre polynomials", file=fo) icol = 1 for ish in range(nsh): sol[ish].G_l << ar[output_group]['G_l'][str(ish)] spn = solver.SK.spin_block_names[solver.SK.corr_shells[ solver.SK.inequiv_to_corr[ish]]['SO']] norb = solver.SK.corr_shells[ solver.SK.inequiv_to_corr[ish]]['dim'] for isp in spn: for iorb in range(norb): for jorb in range(norb): icol += 1 print( "# [%d] Re(G_l_{shell=%d, spin=%s, %d, %d})" % (icol, ish, isp, iorb, jorb), file=fo) icol += 1 print( "# [%d] Im(G_l_{shell=%d, spin=%s, %d, %d})" % (icol, ish, isp, iorb, jorb), file=fo) # # Write data # for il in range(p["system"]["n_l"]): print("%d " % il, end="", file=fo) for ish in range(nsh): spn = solver.SK.spin_block_names[solver.SK.corr_shells[ solver.SK.inequiv_to_corr[ish]]['SO']] norb = solver.SK.corr_shells[ solver.SK.inequiv_to_corr[ish]]['dim'] for isp in spn: for iorb in range(norb): for jorb in range(norb): print("%f %f " % (sol[ish].G_l[isp].data[il, iorb, jorb].real, sol[ish].G_l[isp].data[il, iorb, jorb].imag), end="", file=fo) print("", file=fo) # # Finish # del ar print("\n Done\n")
for filename in filenames: print '--> Loading:', filename with HDFArchive(filename, 'r') as s: p = s['p'] if hasattr(p, 'chi'): nw = p.solve.measure_G2_n_fermionic nc = int(np.log10(p.n_cycles)) style = styles[(nw, nc)] plt.plot(1. / p.beta, p.chi, style, alpha=0.5) for (nw, nc), style in styles.items(): plt.plot([], [], style, alpha=0.5, label='cthyb dynamic $n_w=%i$, $\log n_c=%i$' % (nw, nc)) # ------------------------------------------------------------------ plt.legend(loc='best', fontsize=6, frameon=False) plt.xlabel(r'$T$') plt.ylabel(r'$\chi_m$') plt.tight_layout() plt.savefig('figure_summary.pdf') plt.show()
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) plt.subplot(*subp) subp[-1] += 1 oplotr(cthyb.G_tau, '.', label='cthyb G_tau', alpha=0.2) oplotr(pyed.G_tau, label='pyed G_tau') plt.plot(0, -1 + cthyb.n_exp * 0.5, 'ob', alpha=0.25, clip_on=False) plt.plot(cthyb.G_tau.mesh.beta, -cthyb.n_exp * 0.5, 'ob', alpha=0.25, clip_on=False) #oplotr(cthyb.Gl_tau, '-', label='cthyb Gl_tau', alpha=0.75) plt.legend(loc='best') plt.tight_layout() plt.savefig('figure_n_n_by_insertion_cthyb.pdf') plt.show()
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()