@@ -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
613614end
614615
@@ -677,12 +678,13 @@ end
677678
678679# TODO : decide whether to use graph mutating methods when resulting graph is unchanged?
679680function _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
687689end
688690
0 commit comments