Skip to content

Commit

Permalink
Move braidingtensorcheck earlier
Browse files Browse the repository at this point in the history
  • Loading branch information
lkdvos committed Nov 29, 2023
1 parent 6e49c93 commit f85a6e0
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/planar/preprocessors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ function _construct_braidingtensors(ex::Expr)
while i <= length(list)
t = list[i]
if _remove_adjoint(TO.gettensorobject(t)) ==
# verify that the braiding tensor has the correct form
obj, leftind, rightind = TO.decomposetensor(t)
length(leftind) == length(rightind) == 2 ||
throw(ArgumentError("Invalid expression $t. τ is reserved for the braiding, and should have two input and two output indices."))

translatebraidings[t] = Expr(:call, GlobalRef(TensorKit, :BraidingTensor))
deleteat!(list, i)
else
Expand All @@ -110,8 +115,6 @@ function _construct_braidingtensors(ex::Expr)
ischanged = false
for (t, construct_expr) in translatebraidings
obj, leftind, rightind = TO.decomposetensor(t)
length(leftind) == length(rightind) == 2 ||
throw(ArgumentError("The name τ is reserved for the braiding, and should have two input and two output indices."))
if _is_adjoint(obj)
i1b, i2b, = leftind
i2a, i1a, = rightind
Expand Down Expand Up @@ -156,16 +159,17 @@ function _construct_braidingtensors(ex::Expr)
return o
end
end
push!(list, Expr(:typed_vcat, s, Expr(:tuple, leftind...),
Expr(:tuple, rightind...)))
push!(list,
Expr(:typed_vcat, s, Expr(:tuple, leftind...),
Expr(:tuple, rightind...)))

delete!(translatebraidings, t)
ischanged = true
end
end

@assert isempty(translatebraidings) "could not figure out all spaces \n $ex"

return Expr(:block, pre, ex)
end
_construct_braidingtensors(x) = x
Expand Down

0 comments on commit f85a6e0

Please sign in to comment.