Skip to content

Commit

Permalink
Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeyT1994 committed Nov 8, 2024
1 parent 629af71 commit 9a3ca1c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 24 deletions.
20 changes: 10 additions & 10 deletions src/abstractitensornetwork.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand All @@ -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)
Expand Down
23 changes: 10 additions & 13 deletions src/solvers/sweep_plans/sweep_plans.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/treetensornetworks/abstracttreetensornetwork.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9a3ca1c

Please sign in to comment.