Skip to content

Commit ff25d59

Browse files
authored
Gauge walks (#211)
1 parent a8c3a0b commit ff25d59

File tree

2 files changed

+43
-28
lines changed

2 files changed

+43
-28
lines changed

src/abstractitensornetwork.jl

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ using Graphs:
1919
using ITensors:
2020
ITensors,
2121
ITensor,
22+
@Algorithm_str,
2223
addtags,
2324
combiner,
2425
commoninds,
@@ -44,7 +45,7 @@ using MacroTools: @capture
4445
using NamedGraphs: NamedGraphs, NamedGraph, not_implemented, steiner_tree
4546
using NamedGraphs.GraphsExtensions:
4647
, directed_graph, incident_edges, rename_vertices, vertextype
47-
using NDTensors: NDTensors, dim
48+
using NDTensors: NDTensors, dim, Algorithm
4849
using SplitApplyCombine: flatten
4950

5051
abstract type AbstractITensorNetwork{V} <: AbstractDataGraph{V,ITensor,ITensor} end
@@ -585,49 +586,59 @@ function LinearAlgebra.factorize(tn::AbstractITensorNetwork, edge::Pair; kwargs.
585586
end
586587

587588
# For ambiguity error; TODO: decide whether to use graph mutating methods when resulting graph is unchanged?
588-
function orthogonalize_walk(tn::AbstractITensorNetwork, edge::AbstractEdge; kwargs...)
589-
return orthogonalize_walk(tn, [edge]; kwargs...)
590-
end
591-
592-
function orthogonalize_walk(tn::AbstractITensorNetwork, edge::Pair; kwargs...)
593-
return orthogonalize_walk(tn, edgetype(tn)(edge); kwargs...)
594-
end
595-
596-
# For ambiguity error; TODO: decide whether to use graph mutating methods when resulting graph is unchanged?
597-
function orthogonalize_walk(
598-
tn::AbstractITensorNetwork, edges::Vector{<:AbstractEdge}; kwargs...
589+
function gauge_edge(
590+
alg::Algorithm"orthogonalize", tn::AbstractITensorNetwork, edge::AbstractEdge; kwargs...
599591
)
600592
# tn = factorize(tn, edge; kwargs...)
601593
# # TODO: Implement as `only(common_neighbors(tn, src(edge), dst(edge)))`
602594
# new_vertex = only(neighbors(tn, src(edge)) ∩ neighbors(tn, dst(edge)))
603595
# return contract(tn, new_vertex => dst(edge))
596+
tn = copy(tn)
597+
left_inds = uniqueinds(tn, edge)
598+
ltags = tags(tn, edge)
599+
X, Y = factorize(tn[src(edge)], left_inds; tags=ltags, ortho="left", kwargs...)
600+
tn[src(edge)] = X
601+
tn[dst(edge)] *= Y
602+
return tn
603+
end
604+
605+
# For ambiguity error; TODO: decide whether to use graph mutating methods when resulting graph is unchanged?
606+
function gauge_walk(
607+
alg::Algorithm, tn::AbstractITensorNetwork, edges::Vector{<:AbstractEdge}; kwargs...
608+
)
604609
tn = copy(tn)
605610
for edge in edges
606-
left_inds = uniqueinds(tn, edge)
607-
ltags = tags(tn, edge)
608-
X, Y = factorize(tn[src(edge)], left_inds; tags=ltags, ortho="left", kwargs...)
609-
tn[src(edge)] = X
610-
tn[dst(edge)] *= Y
611+
tn = gauge_edge(alg, tn, edge; kwargs...)
611612
end
612613
return tn
613614
end
614615

615-
function orthogonalize_walk(tn::AbstractITensorNetwork, edges::Vector{<:Pair}; kwargs...)
616-
return orthogonalize_walk(tn, edgetype(tn).(edges); kwargs...)
616+
function gauge_walk(alg::Algorithm, tn::AbstractITensorNetwork, edge::Pair; kwargs...)
617+
return gauge_edge(alg::Algorithm, tn, edgetype(tn)(edge); kwargs...)
617618
end
618619

619-
# Orthogonalize an ITensorNetwork towards a region, treating
620+
function gauge_walk(
621+
alg::Algorithm, tn::AbstractITensorNetwork, edges::Vector{<:Pair}; kwargs...
622+
)
623+
return gauge_walk(alg, tn, edgetype(tn).(edges); kwargs...)
624+
end
625+
626+
# Gauge a ITensorNetwork towards a region, treating
620627
# the network as a tree spanned by a spanning tree.
621-
function tree_orthogonalize(ψ::AbstractITensorNetwork, region::Vector)
628+
function tree_gauge(alg::Algorithm, ψ::AbstractITensorNetwork, region::Vector)
622629
region_center =
623630
length(region) != 1 ? first(center(steiner_tree(ψ, region))) : only(region)
624631
path = post_order_dfs_edges(bfs_tree(ψ, region_center), region_center)
625632
path = filter(e -> !((src(e) region) && (dst(e) region)), path)
626-
return orthogonalize_walk(ψ, path)
633+
return gauge_walk(alg, ψ, path)
634+
end
635+
636+
function tree_gauge(alg::Algorithm, ψ::AbstractITensorNetwork, region)
637+
return tree_gauge(alg, ψ, [region])
627638
end
628639

629-
function tree_orthogonalize::AbstractITensorNetwork, region)
630-
return tree_orthogonalize(ψ, [region])
640+
function tree_orthogonalize::AbstractITensorNetwork, region; kwargs...)
641+
return tree_gauge(Algorithm("orthogonalize"), ψ, region; kwargs...)
631642
end
632643

633644
# TODO: decide whether to use graph mutating methods when resulting graph is unchanged?

src/treetensornetworks/abstracttreetensornetwork.jl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ using NamedGraphs.GraphsExtensions:
88
a_star
99
using NamedGraphs: namedgraph_a_star, steiner_tree
1010
using IsApprox: IsApprox, Approx
11-
using ITensors: ITensors, @Algorithm_str, directsum, hasinds, permute, plev
11+
using ITensors: ITensors, Algorithm, @Algorithm_str, directsum, hasinds, permute, plev
1212
using ITensorMPS: ITensorMPS, linkind, loginner, lognorm, orthogonalize
1313
using TupleTools: TupleTools
1414

@@ -35,19 +35,23 @@ function set_ortho_region(tn::AbstractTTN, new_region)
3535
return error("Not implemented")
3636
end
3737

38-
function ITensorMPS.orthogonalize(ttn::AbstractTTN, region::Vector; kwargs...)
38+
function gauge(alg::Algorithm, ttn::AbstractTTN, region::Vector; kwargs...)
3939
issetequal(region, ortho_region(ttn)) && return ttn
4040
st = steiner_tree(ttn, union(region, ortho_region(ttn)))
4141
path = post_order_dfs_edges(st, first(region))
4242
path = filter(e -> !((src(e) region) && (dst(e) region)), path)
4343
if !isempty(path)
44-
ttn = typeof(ttn)(orthogonalize_walk(ITensorNetwork(ttn), path; kwargs...))
44+
ttn = typeof(ttn)(gauge_walk(alg, ITensorNetwork(ttn), path; kwargs...))
4545
end
4646
return set_ortho_region(ttn, region)
4747
end
4848

49+
function gauge(alg::Algorithm, ttn::AbstractTTN, region; kwargs...)
50+
return gauge(alg, ttn, [region]; kwargs...)
51+
end
52+
4953
function ITensorMPS.orthogonalize(ttn::AbstractTTN, region; kwargs...)
50-
return orthogonalize(ttn, [region]; kwargs...)
54+
return gauge(Algorithm("orthogonalize"), ttn, region; kwargs...)
5155
end
5256

5357
function tree_orthogonalize(ttn::AbstractTTN, args...; kwargs...)

0 commit comments

Comments
 (0)