Skip to content

Commit 43f3272

Browse files
authored
Use @preserve_graph ingauge_edge(Algorithm::"orthogonalize", tn::AbstractITensorNetwork, edge, ...) and truncate(tn::AbstractITensorNetwork, edge, ...) (#237)
1 parent e429920 commit 43f3272

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ITensorNetworks"
22
uuid = "2919e153-833c-4bdc-8836-1ea460a35fc7"
33
authors = ["Matthew Fishman <[email protected]>, Joseph Tindall <[email protected]> and contributors"]
4-
version = "0.13.8"
4+
version = "0.13.9"
55

66
[deps]
77
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"

src/abstractitensornetwork.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -603,12 +603,13 @@ function gauge_edge(
603603
# # TODO: Implement as `only(common_neighbors(tn, src(edge), dst(edge)))`
604604
# new_vertex = only(neighbors(tn, src(edge)) ∩ neighbors(tn, dst(edge)))
605605
# return contract(tn, new_vertex => dst(edge))
606+
!has_edge(tn, edge) && throw(ArgumentError("Edge not in graph."))
606607
tn = copy(tn)
607608
left_inds = uniqueinds(tn, edge)
608609
ltags = tags(tn, edge)
609610
X, Y = factorize(tn[src(edge)], left_inds; tags=ltags, ortho="left", kwargs...)
610-
tn[src(edge)] = X
611-
tn[dst(edge)] *= Y
611+
@preserve_graph tn[src(edge)] = X
612+
@preserve_graph tn[dst(edge)] = tn[dst(edge)]*Y
612613
return tn
613614
end
614615

@@ -677,12 +678,13 @@ end
677678

678679
# TODO: decide whether to use graph mutating methods when resulting graph is unchanged?
679680
function _truncate_edge(tn::AbstractITensorNetwork, edge::AbstractEdge; kwargs...)
681+
!has_edge(tn, edge) && throw(ArgumentError("Edge not in graph."))
680682
tn = copy(tn)
681683
left_inds = uniqueinds(tn, edge)
682684
ltags = tags(tn, edge)
683685
U, S, V = svd(tn[src(edge)], left_inds; lefttags=ltags, kwargs...)
684-
tn[src(edge)] = U
685-
tn[dst(edge)] *= (S * V)
686+
@preserve_graph tn[src(edge)] = U
687+
@preserve_graph tn[dst(edge)] = tn[dst(edge)] * (S*V)
686688
return tn
687689
end
688690

0 commit comments

Comments
 (0)