Skip to content

Commit

Permalink
Format and outdated comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
b-kloss committed Jan 10, 2024
1 parent 3033544 commit 64e1c1b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 19 deletions.
23 changes: 5 additions & 18 deletions src/treetensornetworks/opsum_to_ttn.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ end
Construct a dense TreeTensorNetwork from a symbolic OpSum representation of a
Hamiltonian, compressing shared interaction channels.
"""
function ttn_svd(
os::OpSum, sites::IndsNetwork, root_vertex; kwargs...
)
function ttn_svd(os::OpSum, sites::IndsNetwork, root_vertex; kwargs...)
# Function barrier to improve type stability
coefficient_type = ITensors.determineValType(terms(os))
return ttn_svd(coefficient_type, os, sites, root_vertex; kwargs...)
Expand Down Expand Up @@ -210,35 +208,24 @@ function ttn_svd(

# compress this tempTTN representation into dense form

#link_space = dictionary([
# e => Index((isempty(outmaps[e]) ? 0 : size(Vs[e], 2)) + 2, edge_tag(e)) for e in es
#])
###FIXME: that's an ugly constructor... ###QNIndex(undef) not defined
link_space = Dict{edgetype_sites,Index}()
linkdir = ITensors.using_auto_fermion() ? ITensors.In : ITensors.Out ###FIXME: ??
for e in es ###this one might also be tricky, in case there's no Vq defined on the edge
###also tricky w.r.t. the link direction
### ---> should we just infer whether the edge is incoming or outgoing and choose linkdir accordingly?
### ===> this is basically decided by daggering in the MPO code (we should be able to stick to this pattern)
for e in es
qi = Vector{Pair{QN,Int}}()
push!(qi, QN() => 1)
for (q, Vq) in Vs[e]
cols = size(Vq, 2)
if ITensors.using_auto_fermion() # <fermions>
push!(qi, (-q) => cols) ###the minus sign comes from the opposite linkdir ?
push!(qi, (-q) => cols)
else
push!(qi, q => cols)
end
end
push!(qi, Hflux => 1)
link_space[e] = Index(qi...; tags=edge_tag(e), dir=linkdir) ##FIXME: maybe a single linkdir is not the right thing to do here
link_space[e] = Index(qi...; tags=edge_tag(e), dir=linkdir)
end

H = TTN(sites)
##Copy from ITensors qn_svdMPO
# Find location where block of Index i
# matches QN q, but *not* 1 or dim(i)
# which are special ending/starting states
function qnblock(i::Index, q::QN)
for b in 2:(nblocks(i) - 1)
flux(i, Block(b)) == q && return b
Expand Down Expand Up @@ -327,7 +314,7 @@ function ttn_svd(

for ((b, q_op), m) in blocks
###FIXME: make this work if there's no physical degree of freedom at site
Op = computeSiteProd(sites, Prod(q_op)) ###FIXME: is this implemented?
Op = computeSiteProd(sites, Prod(q_op))
if hasqns(Op) ###FIXME: this may not be safe, we may want to check for the equivalent (zero tensor?) case in the dense case as well
iszero(nnzblocks(Op)) && continue ###FIXME: this one may be breaking for no physical indices on site
end
Expand Down
2 changes: 1 addition & 1 deletion test/test_opsum_to_ttn.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ using Test
@test Tttno Tmpo rtol = 1e-6

# this breaks for longer range interactions
Hsvd_lr = TTN(Hlr, is; root_vertex=root_vertex,algorithm="svd", cutoff=1e-10)
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)
Expand Down

0 comments on commit 64e1c1b

Please sign in to comment.