Skip to content

Commit

Permalink
Make gauge edge lowest level function
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeyT1994 committed Nov 26, 2024
1 parent 75ca249 commit e9610e9
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions src/abstractitensornetwork.jl
Original file line number Diff line number Diff line change
Expand Up @@ -586,38 +586,37 @@ 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 gauge_walk(
alg::Algorithm, tn::AbstractITensorNetwork, edge::AbstractEdge; kwargs...
function gauge_edge(
alg::Algorithm"orthogonalize", tn::AbstractITensorNetwork, edge::AbstractEdge; kwargs...
)
return gauge_walk(tn, [edge]; kwargs...)
end

function gauge_walk(alg::Algorithm, tn::AbstractITensorNetwork, edge::Pair; kwargs...)
return gauge_walk(alg::Algorithm, tn, edgetype(tn)(edge); kwargs...)
# tn = factorize(tn, edge; kwargs...)
# # TODO: Implement as `only(common_neighbors(tn, src(edge), dst(edge)))`
# new_vertex = only(neighbors(tn, src(edge)) ∩ neighbors(tn, dst(edge)))
# return contract(tn, new_vertex => dst(edge))
tn = copy(tn)
left_inds = uniqueinds(tn, edge)
ltags = tags(tn, edge)
X, Y = factorize(tn[src(edge)], left_inds; tags=ltags, ortho="left", kwargs...)
tn[src(edge)] = X
tn[dst(edge)] *= Y
return tn
end

# For ambiguity error; TODO: decide whether to use graph mutating methods when resulting graph is unchanged?
function gauge_walk(
alg::Algorithm"orthogonalize",
tn::AbstractITensorNetwork,
edges::Vector{<:AbstractEdge};
kwargs...,
alg::Algorithm, tn::AbstractITensorNetwork, edges::Vector{<:AbstractEdge}; kwargs...
)
# tn = factorize(tn, edge; kwargs...)
# # TODO: Implement as `only(common_neighbors(tn, src(edge), dst(edge)))`
# new_vertex = only(neighbors(tn, src(edge)) ∩ neighbors(tn, dst(edge)))
# return contract(tn, new_vertex => dst(edge))
tn = copy(tn)
for edge in edges
left_inds = uniqueinds(tn, edge)
ltags = tags(tn, edge)
X, Y = factorize(tn[src(edge)], left_inds; tags=ltags, ortho="left", kwargs...)
tn[src(edge)] = X
tn[dst(edge)] *= Y
tn = gauge_edge(alg, tn, edge; kwargs...)
end
return tn
end

function gauge_walk(alg::Algorithm, tn::AbstractITensorNetwork, edge::Pair; kwargs...)
return gauge_edge(alg::Algorithm, tn, edgetype(tn)(edge); kwargs...)
end

function gauge_walk(
alg::Algorithm, tn::AbstractITensorNetwork, edges::Vector{<:Pair}; kwargs...
)
Expand Down

0 comments on commit e9610e9

Please sign in to comment.