@@ -19,6 +19,7 @@ using Graphs:
1919using ITensors:
2020 ITensors,
2121 ITensor,
22+ @Algorithm_str ,
2223 addtags,
2324 combiner,
2425 commoninds,
@@ -44,7 +45,7 @@ using MacroTools: @capture
4445using NamedGraphs: NamedGraphs, NamedGraph, not_implemented, steiner_tree
4546using NamedGraphs. GraphsExtensions:
4647 ⊔ , directed_graph, incident_edges, rename_vertices, vertextype
47- using NDTensors: NDTensors, dim
48+ using NDTensors: NDTensors, dim, Algorithm
4849using SplitApplyCombine: flatten
4950
5051abstract type AbstractITensorNetwork{V} <: AbstractDataGraph{V,ITensor,ITensor} end
@@ -585,49 +586,59 @@ function LinearAlgebra.factorize(tn::AbstractITensorNetwork, edge::Pair; kwargs.
585586end
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
613614end
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... )
617618end
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])
627638end
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 ... )
631642end
632643
633644# TODO : decide whether to use graph mutating methods when resulting graph is unchanged?
0 commit comments