From 32ebca76e9029b15249f65625204a4f5548e957a Mon Sep 17 00:00:00 2001 From: Joey Date: Fri, 18 Oct 2024 17:53:43 +0100 Subject: [PATCH] Post order dsf edges region --- src/abstractitensornetwork.jl | 5 +---- src/edge_sequences.jl | 5 +++++ src/treetensornetworks/abstracttreetensornetwork.jl | 9 +++------ 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/abstractitensornetwork.jl b/src/abstractitensornetwork.jl index 653303aa..244a24d7 100644 --- a/src/abstractitensornetwork.jl +++ b/src/abstractitensornetwork.jl @@ -631,10 +631,7 @@ end # the network as a tree spanned by a spanning tree. # TODO: Rename `tree_orthogonalize`. function ITensorMPS.orthogonalize(ψ::AbstractITensorNetwork, region::Vector) - spanning_tree_edges = post_order_dfs_edges(bfs_tree(ψ, first(region)), first(region)) - spanning_tree_edges = filter( - e -> !(src(e) ∈ region && dst(e) ∈ region), spanning_tree_edges - ) + spanning_tree_edges = post_order_dfs_edges_region(bfs_tree(ψ, first(region)), region) return orthogonalize(ψ, spanning_tree_edges) end diff --git a/src/edge_sequences.jl b/src/edge_sequences.jl index 9dab9fff..9b385c68 100644 --- a/src/edge_sequences.jl +++ b/src/edge_sequences.jl @@ -44,3 +44,8 @@ end @traitfn function edge_sequence(::Algorithm"parallel", g::::(!IsDirected)) return [[e] for e in vcat(edges(g), reverse.(edges(g)))] end + +function post_order_dfs_edges_region(g::AbstractGraph, region) + es = post_order_dfs_edges(g, first(region)) + return filter(e -> !((src(e) ∈ region) && (dst(e) ∈ region)), es) +end diff --git a/src/treetensornetworks/abstracttreetensornetwork.jl b/src/treetensornetworks/abstracttreetensornetwork.jl index 13d78197..f75e9de2 100644 --- a/src/treetensornetworks/abstracttreetensornetwork.jl +++ b/src/treetensornetworks/abstracttreetensornetwork.jl @@ -10,7 +10,6 @@ using NamedGraphs: namedgraph_a_star using IsApprox: IsApprox, Approx using ITensors: @Algorithm_str, directsum, hasinds, permute, plev using ITensorMPS: linkind, loginner, lognorm, orthogonalize -using TupleTools: TupleTools abstract type AbstractTreeTensorNetwork{V} <: AbstractITensorNetwork{V} end @@ -36,11 +35,9 @@ function set_ortho_region(tn::AbstractTTN, new_region) end function ITensorMPS.orthogonalize(ttn::AbstractTTN, region::Vector; kwargs...) - paths = [ - namedgraph_a_star(underlying_graph(ttn), rp, r) for r in region for - rp in ortho_region(ttn) - ] - path = unique(reduce(vcat, paths)) + new_path = post_order_dfs_edges_region(ttn, region) + existing_path = post_order_dfs_edges_region(ttn, ortho_region(ttn)) + path = setdiff(new_path, existing_path) if !isempty(path) ttn = typeof(ttn)(orthogonalize(ITensorNetwork(ttn), path; kwargs...)) end