Skip to content

Commit 32ebca7

Browse files
committed
Post order dsf edges region
1 parent d460884 commit 32ebca7

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

src/abstractitensornetwork.jl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -631,10 +631,7 @@ end
631631
# the network as a tree spanned by a spanning tree.
632632
# TODO: Rename `tree_orthogonalize`.
633633
function ITensorMPS.orthogonalize::AbstractITensorNetwork, region::Vector)
634-
spanning_tree_edges = post_order_dfs_edges(bfs_tree(ψ, first(region)), first(region))
635-
spanning_tree_edges = filter(
636-
e -> !(src(e) region && dst(e) region), spanning_tree_edges
637-
)
634+
spanning_tree_edges = post_order_dfs_edges_region(bfs_tree(ψ, first(region)), region)
638635
return orthogonalize(ψ, spanning_tree_edges)
639636
end
640637

src/edge_sequences.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,8 @@ end
4444
@traitfn function edge_sequence(::Algorithm"parallel", g::::(!IsDirected))
4545
return [[e] for e in vcat(edges(g), reverse.(edges(g)))]
4646
end
47+
48+
function post_order_dfs_edges_region(g::AbstractGraph, region)
49+
es = post_order_dfs_edges(g, first(region))
50+
return filter(e -> !((src(e) region) && (dst(e) region)), es)
51+
end

src/treetensornetworks/abstracttreetensornetwork.jl

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ using NamedGraphs: namedgraph_a_star
1010
using IsApprox: IsApprox, Approx
1111
using ITensors: @Algorithm_str, directsum, hasinds, permute, plev
1212
using ITensorMPS: linkind, loginner, lognorm, orthogonalize
13-
using TupleTools: TupleTools
1413

1514
abstract type AbstractTreeTensorNetwork{V} <: AbstractITensorNetwork{V} end
1615

@@ -36,11 +35,9 @@ function set_ortho_region(tn::AbstractTTN, new_region)
3635
end
3736

3837
function ITensorMPS.orthogonalize(ttn::AbstractTTN, region::Vector; kwargs...)
39-
paths = [
40-
namedgraph_a_star(underlying_graph(ttn), rp, r) for r in region for
41-
rp in ortho_region(ttn)
42-
]
43-
path = unique(reduce(vcat, paths))
38+
new_path = post_order_dfs_edges_region(ttn, region)
39+
existing_path = post_order_dfs_edges_region(ttn, ortho_region(ttn))
40+
path = setdiff(new_path, existing_path)
4441
if !isempty(path)
4542
ttn = typeof(ttn)(orthogonalize(ITensorNetwork(ttn), path; kwargs...))
4643
end

0 commit comments

Comments
 (0)