Skip to content
This repository has been archived by the owner on Jul 7, 2024. It is now read-only.

Commit

Permalink
Fix isleftcanonical and isrightcanonical to work for boundary ten…
Browse files Browse the repository at this point in the history
…sors (#29)

* Fix isleftcanonical to be able to work for right-most tensor

* Fix isrightcanonical to be able to work for left-most tensor
  • Loading branch information
jofrevalles authored Mar 13, 2024
1 parent 85dadeb commit 31df08d
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/Ansatz/Chain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -311,14 +311,15 @@ end

function isleftcanonical(qtn::Chain, site; atol::Real = 1e-12)
right_ind = rightindex(qtn, site)
tensor = select(qtn, :tensor, site)

# we are at right-most site, which cannot be left-canonical
# we are at right-most site, we need to add an extra dummy dimension to the tensor
if isnothing(right_ind)
return false
tensor = Tensor(reshape(parent(tensor), size(tensor)..., 1), (inds(tensor)..., :dummy_ind))
right_ind = :dummy_ind
end

# TODO is replace(conj(A)...) copying too much?
tensor = select(qtn, :tensor, site)
contracted = contract(tensor, replace(conj(tensor), right_ind => :new_ind_name))
n = size(tensor, right_ind)
identity_matrix = Matrix(I, n, n)
Expand All @@ -328,14 +329,15 @@ end

function isrightcanonical(qtn::Chain, site; atol::Real = 1e-12)
left_ind = leftindex(qtn, site)
tensor = select(qtn, :tensor, site)

# we are at left-most site, which cannot be right-canonical
# we are at left-most site, we need to add an extra dummy dimension to the tensor
if isnothing(left_ind)
return false
tensor = Tensor(reshape(parent(tensor), 1, size(tensor)...), (:dummy_ind, inds(tensor)...))
left_ind = :dummy_ind
end

#TODO is replace(conj(A)...) copying too much?
tensor = select(qtn, :tensor, site)
contracted = contract(tensor, replace(conj(tensor), left_ind => :new_ind_name))
n = size(tensor, left_ind)
identity_matrix = Matrix(I, n, n)
Expand Down

0 comments on commit 31df08d

Please sign in to comment.