Skip to content

Commit

Permalink
Cosmetic edits, and remove an unused functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
b-kloss committed Jan 9, 2024
1 parent 764f4da commit 8ae0c5b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
19 changes: 10 additions & 9 deletions src/treetensornetworks/opsum_to_ttn.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Hamiltonian, compressing shared interaction channels.
"""
function ttn_svd(
os::OpSum, sites::IndsNetwork, root_vertex; kwargs...
)::TTN
)
# Function barrier to improve type stability
coefficient_type = ITensors.determineValType(terms(os))
return ttn_svd(coefficient_type, os, sites, root_vertex; kwargs...)
Expand All @@ -55,7 +55,7 @@ function ttn_svd(
mindim::Int=1,
maxdim::Int=typemax(Int),
cutoff=eps(coefficient_type) * 10,
)::TTN
)
# check for qns on the site indices
#FIXME: this check for whether or not any of the siteindices has QNs is somewhat ugly
#FIXME: how are sites handled where some sites have QNs and some don't?
Expand Down Expand Up @@ -278,7 +278,7 @@ function ttn_svd(
block_helper_inds[terminal_dims] .= 1
for dout in filter(d -> d terminal_dims, dims_out)
T_inds[dout] = sublinkdims[dout] # end in channel linkdims[d] for each dimension d
@assert T_inds[dout] == 1
@assert isone(T_inds[dout])
block_helper_inds[dout] = nblocks(linkinds[dout])
end

Expand All @@ -287,7 +287,7 @@ function ttn_svd(
block_helper_inds[d] = qnblock(linkinds[d], T_qns[d])
end

@assert all(block_helper_inds .!= -1) # check that all block indices are set
@assert all((-1), block_helper_inds)# check that all block indices are set
# make Block
theblock = Block(Tuple(block_helper_inds))

Expand All @@ -300,7 +300,7 @@ function ttn_svd(

if isempty(normal_dims)
M = get!(blocks, (theblock, terms(t)), zero_arr())
@assert length(M) == 1
@assert isone(length(M))
M[] += ct
else
M = get!(blocks, (theblock, terms(t)), zero_arr())
Expand Down Expand Up @@ -329,7 +329,7 @@ function ttn_svd(
###FIXME: make this work if there's no physical degree of freedom at site
Op = computeSiteProd(sites, Prod(q_op)) ###FIXME: is this implemented?
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
(nnzblocks(Op) == 0) && continue ###FIXME: this one may be breaking for no physical indices on site
iszero(nnzblocks(Op)) && continue ###FIXME: this one may be breaking for no physical indices on site
end
sq = flux(Op)
if !isnothing(sq)
Expand Down Expand Up @@ -496,7 +496,7 @@ function TTN(
sites::IndsNetwork;
root_vertex=default_root_vertex(sites),
splitblocks=false,
method=:svd,
algorithm="svd",
kwargs...,
)::TTN
length(ITensors.terms(os)) == 0 && error("OpSum has no terms")
Expand All @@ -506,7 +506,7 @@ function TTN(
os = deepcopy(os)
os = sorteachterm(os, sites, root_vertex)
os = ITensors.sortmergeterms(os) # not exported
if method == :svd
if algorithm == "svd"
T = ttn_svd(os, sites, root_vertex; kwargs...)
else
error("Currently only SVD is supported as TTN constructor backend.")
Expand Down Expand Up @@ -619,7 +619,7 @@ end
Base.zero(t::Sum) = zero(typeof(t))



#=
function computeSiteSum(
sites::IndsNetwork{V,<:Index}, ops::Sum{Scaled{C,Prod{Op}}}
)::ITensor where {V,C}
Expand All @@ -637,3 +637,4 @@ function computeSiteSum(
end
return T
end
=#
4 changes: 2 additions & 2 deletions 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, method=: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 Expand Up @@ -115,7 +115,7 @@ using Test
@test Tttno Tmpo rtol = 1e-6

# this breaks for longer range interactions ###not anymore
Hsvd_lr = TTN(Hlr, is; root_vertex=root_vertex, method=: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 8ae0c5b

Please sign in to comment.