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

Commit

Permalink
Implement conversion from Product to Chain
Browse files Browse the repository at this point in the history
  • Loading branch information
mofeing committed Mar 7, 2024
1 parent 84a20cc commit b37656c
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Ansatz/Chain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,17 @@ function Chain(::Operator, boundary::Open, arrays::Vector{<:AbstractArray})
Chain(Quantum(TensorNetwork(_tensors), sitemap), boundary)
end

function Base.convert(::Type{Chain}, qtn::Product)
arrs::Vector{Array} = arrays(TensorNetwork(qtn))
arrs[1] = reshape(arrs[1], size(arrs[1])..., 1)
arrs[end] = reshape(arrs[end], size(arrs[end])..., 1)
map!(@view(arrs[2:end-1]), @view(arrs[2:end-1])) do arr
reshape(arr, size(arr)..., 1, 1)
end

Chain(socket(qtn), Open(), arrs)
end

leftsite(tn::Chain, site::Site) = leftsite(boundary(tn), tn, site)
leftsite(::Open, tn::Chain, site::Site) = site.id range(2, nlanes(tn)) ? Site(site.id - 1) : nothing
leftsite(::Periodic, tn::Chain, site::Site) = Site(mod1(site.id - 1, nlanes(tn)))
Expand Down

0 comments on commit b37656c

Please sign in to comment.