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_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')
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 plot_g2(G2, cplx=None, idx_labels=None, w=Idx(0), opt={}, title=None): data = G2[w, :, :].data if cplx == 're': data = data.real elif cplx == 'im': data = data.imag n = data.shape[-1] N = n**2 subp = [N, N, 1] colorbar_flag = True import itertools for idxs in itertools.product(xrange(n), repeat=4): i1, i2, i3, i4 = idxs d = data[:, :, i1, i2, i3, i4] ax = plt.subplot(*subp) subp[-1] += 1 if idx_labels is not None: labels = [idx_labels[idx] for idx in idxs] sub_title = r'$c^\dagger_{%s} c_{%s} c^\dagger_{%s} c_{%s}$' % tuple( labels) else: sub_title = str(idxs) plt.title(sub_title, fontsize=8) #plt.pcolormesh(d, **opt) if np.max(np.abs(d)) > 1e-10: plt.imshow(d, **opt) if colorbar_flag: if title is not None: plt.title(title) plt.colorbar() colorbar_flag = False ax.set_xticks([]) ax.set_yticks([]) plt.axis('equal') plt.tight_layout()
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')
from pytriqs.plot.mpl_interface import oplot, oplotr, oploti, plt plt.figure(figsize=(6 * 2, 8)) #subp = [3, 6, 1] subp = [4, 1, 1] #idx = 20 idx = 0 vmax = np.max(np.abs(ana.gamma_m.data.real)) opt = dict(vmin=-vmax, vmax=vmax, cmap='PuOr') #opt = dict(vmin=-10., vmax=10., cmap='PuOr') #opt = dict(cmap='PuOr') ax = plt.subplot(*subp) subp[-1] += 1 oplot(ana.G_iw) if True: g2 = ana.gamma_m label = 'gamma ana' s = np.squeeze(g2.data[0, :, :]) ax = plt.subplot(*subp) subp[-1] += 1 plt.title('Re ' + label + ' [i,:,:]') plt.pcolormesh(s.real, **opt) plt.colorbar()
parm = ParameterCollection( U=p.U, beta=p.beta, nw=1, nwf=p.n_iw / 2, nwf_gf=p.n_iw, ) a = analytic_hubbard_atom(**parm.dict()) a.G_iw.name = r'$G_{analytic}$' plt.figure(figsize=(3.25 * 2, 3 * 2)) subp = [2, 2, 1] plt.subplot(*subp) subp[-1] += 1 oploti(p.G_iw) oploti(a.G_iw) plt.subplot(*subp) subp[-1] += 1 diff = a.G_iw.copy() diff << p.G_iw['up'] - a.G_iw diff.name = r'$G_{ctint} - G_{analytic}$' oplot(diff) plt.subplot(*subp) subp[-1] += 1 vmax = np.max(np.abs(p.chi_m.data.real))
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() 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)
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}) plt.clf() plt.suptitle("$U=%.1f$, $\epsilon_d=%.1f$, $V=%.1f$, $\epsilon_k=%.1f$" % (U,ed,V,e)) histo = e_group['performance_analysis'] # Move insert plt.subplot(3,1,1) proposed = histo['insert_length_proposed_up'] + histo['insert_length_proposed_dn'] accepted = histo['insert_length_accepted_up'] + histo['insert_length_accepted_dn'] plot_histos("Insertion",{"Proposed" : proposed, "Accepted" : accepted}) # Move remove plt.subplot(3,1,2) proposed = histo['remove_length_proposed_up'] + histo['remove_length_proposed_dn'] accepted = histo['remove_length_accepted_up'] + histo['remove_length_accepted_dn'] plot_histos("Removal",{"Proposed" : proposed, "Accepted" : accepted}) # Move shift plt.subplot(3,1,3) proposed = histo['shift_length_proposed'] accepted = histo['shift_length_accepted'] plot_histos("Shift",{"Proposed" : proposed, "Accepted" : accepted}) pp.savefig(plt.gcf())
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")