Skip to content

Commit 5c175d5

Browse files
committed
BSE unit test
1 parent 4aba418 commit 5c175d5

File tree

2 files changed

+102
-1
lines changed

2 files changed

+102
-1
lines changed

Project.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ TensorCrossInterpolation = "b261b2ec-6378-4871-b32e-9173bb050604"
2121
[compat]
2222
EllipsisNotation = "1"
2323
FastMPOContractions = "0.2.2"
24+
HubbardAtoms = "0.1.0"
2425
ITensors = "0.6"
2526
OrderedCollections = "1"
2627
QuanticsGrids = "0.3.1"
@@ -29,9 +30,11 @@ TensorCrossInterpolation = "0.9.7"
2930
julia = "1.6"
3031

3132
[extras]
33+
HubbardAtoms = "4f3da25b-ea28-4d4f-a81f-380d3f5e56a6"
3234
QuanticsGrids = "634c7f73-3e90-4749-a1bd-001b8efc642d"
3335
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
36+
SparseIR = "4fe2279e-80f0-4adb-8463-ee114ff56b7d"
3437
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
3538

3639
[targets]
37-
test = ["Test", "Random", "QuanticsGrids"]
40+
test = ["Test", "Random", "QuanticsGrids", "SparseIR", "HubbardAtoms"]

test/adaptivematmul_tests.jl

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import QuanticsGrids as QG
55
using TensorCrossInterpolation
66
import TensorCrossInterpolation as TCI
77
import TCIAlgorithms as TCIA
8+
using HubbardAtoms
9+
using SparseIR
810

911
import TCIAlgorithms:
1012
create_node,
@@ -338,4 +340,100 @@ import TCIAlgorithms:
338340
@test maximum(abs.(product_matrix .- C)) < 1e-5
339341
@test maximum(abs.(product_matrix_without_patches .- C)) < 1e-5
340342
end
343+
344+
@testset "Bethe-Salpeter equation" begin
345+
U = 1.6
346+
beta = 2.3
347+
model = HubbardAtom(U, beta)
348+
ch_d = DensityChannel()
349+
ch_m = MagneticChannel()
350+
ch_t = TripletChannel()
351+
ch_s = SingletChannel()
352+
m = BosonicFreq(10)
353+
354+
R = 7
355+
maxbonddim = 50
356+
N = 2^R
357+
halfN = 2^(R - 1)
358+
grid = QG.InherentDiscreteGrid{2}(
359+
R, (-halfN, -halfN); step=(1, 1), unfoldingscheme=:fused
360+
)
361+
localdims = fill(4, R)
362+
sitedims = [[2, 2] for _ in 1:R]
363+
pordering = TCIA.PatchOrdering(collect(1:R))
364+
365+
for ch in CHANNELS
366+
367+
######################### quantics functions ############################
368+
# absorb 1/β^2 into chi0 function!!!!!
369+
function fq_chi0(x, y)
370+
return 1 / beta^2 *
371+
chi0(ch, model, (FermionicFreq(2x + 1), FermionicFreq(2y + 1), m))
372+
end
373+
fI_chi0 = QG.quanticsfunction(ComplexF64, grid, fq_chi0)
374+
375+
function fq_full(x, y)
376+
return full_vertex(
377+
ch, model, (FermionicFreq(2x + 1), FermionicFreq(2y + 1), m)
378+
)
379+
end
380+
fI_full = QG.quanticsfunction(ComplexF64, grid, fq_full)
381+
382+
function fq_gamma(x, y)
383+
return gamma(ch, model, (FermionicFreq(2x + 1), FermionicFreq(2y + 1), m))
384+
end
385+
fI_gamma = QG.quanticsfunction(ComplexF64, grid, fq_gamma)
386+
#########################################################################
387+
388+
initialpivots = [QG.origcoord_to_quantics(grid, (0, 0))] # approx center of grid
389+
390+
chi0_patches = reshape(
391+
TCIA.adaptiveinterpolate(
392+
TCIA.makeprojectable(Float64, fI_chi0, localdims),
393+
pordering;
394+
verbosity=0,
395+
maxbonddim,
396+
initialpivots,
397+
),
398+
sitedims,
399+
)
400+
full_patches = reshape(
401+
TCIA.adaptiveinterpolate(
402+
TCIA.makeprojectable(Float64, fI_full, localdims),
403+
pordering;
404+
verbosity=0,
405+
maxbonddim,
406+
initialpivots,
407+
),
408+
sitedims,
409+
)
410+
gamma_patches = reshape(
411+
TCIA.adaptiveinterpolate(
412+
TCIA.makeprojectable(Float64, fI_gamma, localdims),
413+
pordering;
414+
verbosity=0,
415+
maxbonddim,
416+
initialpivots,
417+
),
418+
sitedims,
419+
)
420+
421+
# multiplication Φ = Γ X₀ F
422+
chi0_full = TCIA.adaptivematmul(
423+
chi0_patches, full_patches, pordering; maxbonddim
424+
)
425+
phi_bse = TCIA.adaptivematmul(gamma_patches, chi0_full, pordering; maxbonddim)
426+
427+
# normal multiplication for comparison
428+
box = [(x, y) for x in (-halfN):(halfN - 1), y in (-halfN):(halfN - 1)]
429+
chi0_exact = map(splat(fq_chi0), box)
430+
full_exact = map(splat(fq_full), box)
431+
gamma_exact = map(splat(fq_gamma), box)
432+
phi_normalmul = gamma_exact * chi0_exact * full_exact
433+
434+
phi_adaptivemul = [phi_bse(QG.origcoord_to_quantics(grid, p)) for p in box]
435+
436+
@test isapprox(phi_normalmul, phi_adaptivemul; rtol=1e-5)
437+
end
438+
end
341439
end

0 commit comments

Comments
 (0)