Skip to content

Commit

Permalink
Post order dsf edges region
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeyT1994 committed Oct 18, 2024
1 parent d460884 commit 32ebca7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
5 changes: 1 addition & 4 deletions src/abstractitensornetwork.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions src/edge_sequences.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 3 additions & 6 deletions src/treetensornetworks/abstracttreetensornetwork.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down

0 comments on commit 32ebca7

Please sign in to comment.