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

Commit

Permalink
Add canonize! function
Browse files Browse the repository at this point in the history
  • Loading branch information
mofeing committed Feb 4, 2024
1 parent bb4a7d7 commit 482ac90
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/Ansatz/Chain.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Tenet
using Tenet: letter
using LinearAlgebra

struct Chain <: Ansatz
super::Quantum
Expand Down Expand Up @@ -132,3 +133,39 @@ function rightindex(::Open, tn::Chain, site::Site)
(select(tn, :tensor, site)|>inds)[end]
end
end

canonize!(tn::Chain, args...; kwargs...) = canonize!(boundary(tn), tn, args...; kwargs...)

# NOTE spectral weights are stored in a vector connected to the now virtual hyperindex!
function canonize!(::Open, tn::Chain, site::Site; direction::Symbol)
left_inds = Symbol[]
right_inds = Symbol[]

virtualind = if direction === :left
site == Site(1) && throw(ArgumentError("Cannot left-canonize left-most tensor"))
push!(left_inds, leftindex(tn, site))

site == Site(nsites(tn)) || push!(right_inds, rightindex(tn, site))
push!(right_inds, Quantum(tn)[site])

only(left_inds)
elseif direction === :right
site == Site(nsites(tn)) && throw(ArgumentError("Cannot right-canonize right-most tensor"))
push!(right_inds, rightindex(tn, site))

site == Site(1) || push!(left_inds, leftindex(tn, site))
push!(left_inds, Quantum(tn)[site])

only(right_inds)
else
throw(ArgumentError("Unknown direction=:$direction"))
end

tmpind = gensym(:tmp)
qr!(TensorNetwork(tn); left_inds, right_inds, virtualind = tmpind)

contract!(TensorNetwork(tn), virtualind)
replace!(TensorNetwork(tn), tmpind => virtualind)

return tn
end
1 change: 1 addition & 0 deletions src/Qrochet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export Product
include("Ansatz/Chain.jl")
export Chain
export MPS, pMPS, MPO, pMPO
export leftindex, rightindex, canonize!

# reexports from Tenet
using Tenet
Expand Down

0 comments on commit 482ac90

Please sign in to comment.