From eb556edb2774f3500d667907e6dfa6b1e62a6fc4 Mon Sep 17 00:00:00 2001 From: Benedikt Kloss Date: Mon, 8 Jan 2024 15:57:48 -0500 Subject: [PATCH] Add function barrier, similar to (qn_)svdMPO in ITensors. --- src/treetensornetworks/opsum_to_ttn.jl | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/treetensornetworks/opsum_to_ttn.jl b/src/treetensornetworks/opsum_to_ttn.jl index 6a2d780c..505a427f 100644 --- a/src/treetensornetworks/opsum_to_ttn.jl +++ b/src/treetensornetworks/opsum_to_ttn.jl @@ -41,6 +41,18 @@ Hamiltonian, compressing shared interaction channels. """ function svdTTN( os::OpSum{C}, sites::IndsNetwork{VT,<:Index}, root_vertex::VT; kwargs... +)::TTN where {C,VT} + # Function barrier to improve type stability + ValType = ITensors.determineValType(terms(os)) + return svdTTN(ValType, os, sites, root_vertex; kwargs...) +end + +function svdTTN( + ValType::Type{<:Number}, + os::OpSum{C}, + sites::IndsNetwork{VT,<:Index}, + root_vertex::VT; + kwargs..., )::TTN where {C,VT} mindim::Int = get(kwargs, :mindim, 1) maxdim::Int = get(kwargs, :maxdim, 10000) @@ -223,12 +235,24 @@ end function qn_svdTTN( os::OpSum{C}, sites::IndsNetwork{VT,<:Index}, root_vertex::VT; kwargs... +)::TTN where {C,VT} + # Function barrier to improve type stability + ValType = ITensors.determineValType(terms(os)) + return qn_svdTTN(ValType, os, sites, root_vertex; kwargs...) +end + +function qn_svdTTN( + ValType::Type{<:Number}, + os::OpSum{C}, + sites::IndsNetwork{VT,<:Index}, + root_vertex::VT; + kwargs..., )::TTN where {C,VT} mindim::Int = get(kwargs, :mindim, 1) maxdim::Int = get(kwargs, :maxdim, 10000) cutoff::Float64 = get(kwargs, :cutoff, 1e-15) - ValType = ITensors.determineValType(ITensors.terms(os)) + #ValType = ITensors.determineValType(ITensors.terms(os)) #now included as argument in function signature # traverse tree outwards from root vertex vs = reverse(post_order_dfs_vertices(sites, root_vertex)) # store vertices in fixed ordering relative to root