diff --git a/src/abstractitensornetwork.jl b/src/abstractitensornetwork.jl index f7c148d0..fc0edce4 100644 --- a/src/abstractitensornetwork.jl +++ b/src/abstractitensornetwork.jl @@ -585,16 +585,16 @@ function LinearAlgebra.factorize(tn::AbstractITensorNetwork, edge::Pair; kwargs. end # For ambiguity error; TODO: decide whether to use graph mutating methods when resulting graph is unchanged? -function orthogonalize_path(tn::AbstractITensorNetwork, edge::AbstractEdge; kwargs...) - return orthogonalize_path(tn, [edge]; kwargs...) +function orthogonalize_walk(tn::AbstractITensorNetwork, edge::AbstractEdge; kwargs...) + return orthogonalize_walk(tn, [edge]; kwargs...) end -function orthogonalize_path(tn::AbstractITensorNetwork, edge::Pair; kwargs...) - return orthogonalize_path(tn, edgetype(tn)(edge); kwargs...) +function orthogonalize_walk(tn::AbstractITensorNetwork, edge::Pair; kwargs...) + return orthogonalize_walk(tn, edgetype(tn)(edge); kwargs...) end # For ambiguity error; TODO: decide whether to use graph mutating methods when resulting graph is unchanged? -function orthogonalize_path( +function orthogonalize_walk( tn::AbstractITensorNetwork, edges::Vector{<:AbstractEdge}; kwargs... ) # tn = factorize(tn, edge; kwargs...) @@ -612,18 +612,18 @@ function orthogonalize_path( return tn end -function orthogonalize_path(tn::AbstractITensorNetwork, edges::Vector{<:Pair}; kwargs...) - return orthogonalize_path(tn, edgetype(tn).(edges); kwargs...) +function orthogonalize_walk(tn::AbstractITensorNetwork, edges::Vector{<:Pair}; kwargs...) + return orthogonalize_walk(tn, edgetype(tn).(edges); kwargs...) end # Orthogonalize an ITensorNetwork towards a region, treating # the network as a tree spanned by a spanning tree. function tree_orthogonalize(ψ::AbstractITensorNetwork, region::Vector) - region_centre = + region_center = length(region) != 1 ? first(center(steiner_tree(ψ, region))) : only(region) - path = post_order_dfs_edges(bfs_tree(ψ, region_centre), region_centre) + path = post_order_dfs_edges(bfs_tree(ψ, region_center), region_center) path = filter(e -> !((src(e) ∈ region) && (dst(e) ∈ region)), path) - return orthogonalize_path(ψ, path) + return orthogonalize_walk(ψ, path) end function tree_orthogonalize(ψ::AbstractITensorNetwork, region) diff --git a/src/solvers/sweep_plans/sweep_plans.jl b/src/solvers/sweep_plans/sweep_plans.jl index 384cf8dc..52915e2b 100644 --- a/src/solvers/sweep_plans/sweep_plans.jl +++ b/src/solvers/sweep_plans/sweep_plans.jl @@ -70,20 +70,17 @@ function forward_sweep( kwargs..., ) edges = post_order_dfs_edges(graph, root_vertex) - regions = collect( - flatten(map(i -> forward_region(edges, i; region_kwargs, kwargs...), eachindex(edges))) - ) + regions = map(eachindex(edges)) do i + forward_region(edges, i; region_kwargs, kwargs...) + end + regions = collect(flatten(regions)) if reverse_step - reverse_regions = collect( - flatten( - map( - i -> reverse_region( - edges, i; reverse_edge=reverse_edges, region_kwargs=reverse_kwargs, kwargs... - ), - eachindex(edges), - ), - ), - ) + reverse_regions = map(eachindex(edges)) do i + reverse_region( + edges, i; reverse_edge=reverse_edges, region_kwargs=reverse_kwargs, kwargs... + ) + end + reverse_regions = collect(flatten(reverse_regions)) _check_reverse_sweeps(regions, reverse_regions, graph; kwargs...) regions = interleave(regions, reverse_regions) end diff --git a/src/treetensornetworks/abstracttreetensornetwork.jl b/src/treetensornetworks/abstracttreetensornetwork.jl index 4635ac8a..8815b33f 100644 --- a/src/treetensornetworks/abstracttreetensornetwork.jl +++ b/src/treetensornetworks/abstracttreetensornetwork.jl @@ -41,7 +41,7 @@ function ITensorMPS.orthogonalize(ttn::AbstractTTN, region::Vector; kwargs...) path = post_order_dfs_edges(st, first(region)) path = filter(e -> !((src(e) ∈ region) && (dst(e) ∈ region)), path) if !isempty(path) - ttn = typeof(ttn)(orthogonalize_path(ITensorNetwork(ttn), path; kwargs...)) + ttn = typeof(ttn)(orthogonalize_walk(ITensorNetwork(ttn), path; kwargs...)) end return set_ortho_region(ttn, region) end