Skip to content

Commit

Permalink
Clean up test_opsum_to_ttn.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
b-kloss committed Jan 21, 2024
1 parent 4b58afd commit f6a43e4
Showing 1 changed file with 7 additions and 40 deletions.
47 changes: 7 additions & 40 deletions test/test_opsum_to_ttn.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Dictionaries
using ITensors
using ITensorGaussianMPS: hopping_hamiltonian#, eigen_gaussian
using ITensorGaussianMPS: hopping_hamiltonian
using ITensorNetworks
using Random
using Test
Expand Down Expand Up @@ -150,30 +150,16 @@ end
tooth_lengths = fill(2, 3)
c = named_comb_tree(tooth_lengths)
is = siteinds("Fermion", c; conserve_nf=true)
#is = siteinds("Electron", c; conserve_nf=true,conserve_sz=true)

# linearized version
#linear_order = [4, 1, 2, 5, 3, 6]

# test with next-to-nearest-neighbor Ising Hamiltonian

# test with next-nearest neighbor tight-binding model
t = 1.0
tp = 0.4
U = 0.0
h = 0.5
H = ITensorNetworks.tight_binding(c; t=t, tp=tp, h=h)
#H = ITensorNetworks.hubbard(c; t=t, tp=tp, h=h)

# add combination of longer range interactions
Hlr = copy(H)
#Hlr += 5, "Cdag", (1, 2), "C", (3, 2)#, "Z", (3,2)
#Hlr += 5, "Cdag", (3, 2), "C", (1, 2)#, "Z", (3,2)

#Hlr += -4, "N", (1, 1), "N", (2, 2)
#Hlr += 2.0, "Sz", (2, 2), "Sz", (3, 2)
#Hlr += -1.0, "Sz", (1, 2), "Sz", (3, 1)

# root_vertex = (1, 2)
# println(leaf_vertices(is))

@testset "Svd approach" for root_vertex in leaf_vertices(is)
# get TTN Hamiltonian directly
Expand Down Expand Up @@ -208,22 +194,7 @@ end
GS_mb,_,_=eigsolve(dTtm,1, :SR,eltype(dTtm))
spectrum_sp=eigvals(Hmat_sp)
@test minimum(cumsum(spectrum_sp)) GS_mb[1] atol=1e-8
#@@@test Tmm ≈ Ttm atol = 1e-8
#@test all(Matrix(dense(Tmm-Ttm),inds(Tmm)[1],inds(Tmm)[2]) .≈ 0.0 atol = 1e-8)

#@test Tmm ≈ Ttm
#@test Tmpo ≈ Tttno rtol = 1e-6

# this breaks for longer range interactions ###not anymore
#=
Hsvd_lr = TTN(Hlr, is; root_vertex=root_vertex, algorithm="svd", cutoff=1e-10)
Hline_lr = MPO(relabel_sites(Hlr, vmap), sites)
@disable_warn_order begin
Tttno_lr = prod(Hline_lr)
Tmpo_lr = contract(Hsvd_lr)
end
@test norm(Tttno_lr) ≈ norm(Tmpo_lr) rtol = 1e-6
=#
end
if !auto_fermion_enabled
ITensors.disable_auto_fermion()
Expand All @@ -235,15 +206,15 @@ end
tooth_lengths = fill(2, 3)
c = named_comb_tree(tooth_lengths)
c2 = copy(c)
## add an internal vertex into the comb graph c2
import ITensorNetworks: add_vertex!, rem_vertex!, add_edge!, rem_edge!
add_vertex!(c2, (-1, 1))
add_edge!(c2, (-1, 1) => (2, 2))
add_edge!(c2, (-1, 1) => (3, 1))
add_edge!(c2, (-1, 1) => (2, 1))
rem_edge!(c2, (2, 1) => (2, 2))
rem_edge!(c2, (2, 1) => (3, 1))
#@show c2


is = siteinds("S=1/2", c; conserve_qns=true)
is_missing_site = siteinds("S=1/2", c2; conserve_qns=true)
is_missing_site[(-1, 1)] = Vector{Index}[]
Expand All @@ -256,8 +227,8 @@ end
J1 = -1
J2 = 2
h = 0.5
H = ITensorNetworks.heisenberg(c; J1=J1, J2=J2, h=h)
#Hvac = heisenberg(is_missing_site; J1=J1, J2=J2, h=h)
# connectivity of the Hamiltonian is that of the original comb graph
H = ITensorNetworks.heisenberg(c; J1=J1, J2=J2, h=h)

# add combination of longer range interactions
Hlr = copy(H)
Expand All @@ -266,9 +237,6 @@ end
Hlr += 2.0, "Z", (2, 2), "Z", (3, 2)
Hlr += -1.0, "Z", (1, 2), "Z", (3, 1)

# root_vertex = (1, 2)
# println(leaf_vertices(is))

@testset "Svd approach" for root_vertex in leaf_vertices(is)
# get TTN Hamiltonian directly
Hsvd = TTN(H, is_missing_site; root_vertex=root_vertex, cutoff=1e-10)
Expand All @@ -283,7 +251,6 @@ end

@test Tttno Tmpo rtol = 1e-6

# this breaks for longer range interactions ###not anymore
Hsvd_lr = TTN(
Hlr, is_missing_site; root_vertex=root_vertex, algorithm="svd", cutoff=1e-10
)
Expand Down

0 comments on commit f6a43e4

Please sign in to comment.