TRIQS / triqs

a Toolbox for Research on Interacting Quantum Systems
https://triqs.github.io
GNU General Public License v3.0
135 stars 71 forks source link

make_gf_dlr does not work on Gf views #913

Closed YannIntVeld closed 10 months ago

YannIntVeld commented 11 months ago

Description

Calling make_gf_dlr on a slice of a mesh-product Green's function gives incorrect results.

Steps to Reproduce

  1. Construct a mesh-product Green's function g0_Dwk
from triqs.lattice.lattice_tools import BrillouinZone, BravaisLattice
from triqs.gf import *

bl = BravaisLattice(units=[(1, 0, 0)], orbital_positions=[(0,0,0)])
bz = BrillouinZone(bl)
kmesh = MeshBrillouinZone(bz, [2, 2, 1])

beta = 100.0
wmax = 30.0
dlreps = 1e-10
wmeshDLR_f = MeshDLRImFreq(beta, 'Fermion', wmax, dlreps)

g_Dwk = Gf(mesh=MeshProduct(wmeshDLR_f, kmesh), target_shape=[1]*2)
for k in kmesh:
    g_Dwk[:,k] << inverse(iOmega_n + 0.5)
  1. Slice at a certain k-point and interpolate using the DLR

    nw_equidist = 50
    g_c = make_gf_dlr(g_Dwk[:,Idx([0,0,0])])
    g_slice_w = make_gf_imfreq(g_c, nw_equidist)
  2. As a comparison, create a new Green's function with the same data as the slice.

g_Dw = Gf(mesh=wmeshDLR_f, target_shape=g_Dwk.target_shape)
g_Dw.data[:,0,0] = g_Dwk.data[:,0,0,0]
g_c = make_gf_dlr(g_Dw)
g_w = make_gf_imfreq(g_c, nw_equidist)
  1. Now compare g0_slice_w and g0_w
from triqs.plot.mpl_interface import oplot,plt
%matplotlib inline

oplot(g_w, '-', name='$G_{copy}$', linewidth=2)
oplot(g_slice_w, ':', name='$G_{view}$', linewidth=2)

This results on the following plot bugreportplot

Expected behavior: g0_w and g0_slice_w should be equal

Actual behavior: They are not equal

Additional Information

@HugoStrand mentioned that this probably has to do with the fact that cppdlr requires data to be contiguous.

Wentzell commented 11 months ago

@YannIntVeld Could you reduce your example to not use functions from tprf? Also, you are currently not defining mu and e_k. A self-contained example would be helpful

YannIntVeld commented 11 months ago

@Wentzell That indeed makes more sense. I just updated the example.

Wentzell commented 10 months ago

Thank you @YannIntVeld for updating the example. This was very helpful.

This helped find a bug in cppdlr for non-contiguous input data. I have created a PR with a fix in https://github.com/flatironinstitute/cppdlr/pull/4

Wentzell commented 10 months ago

Fixed by https://github.com/flatironinstitute/cppdlr/pull/4

I also added a test in 814063980