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

Commit

Permalink
Define Product ansatz
Browse files Browse the repository at this point in the history
  • Loading branch information
mofeing committed Dec 15, 2023
1 parent 5e4372f commit 9b6cc30
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Qrochet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ export boundary, Open, Periodic
export Product
export MatrixProduct

include("Quantum/Product.jl")
export Product

end
42 changes: 42 additions & 0 deletions src/Quantum/Product.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Tenet

struct Product{S<:Socket} <: Ansatz
wrap::TensorNetwork

function Product{S}(arrays; order = defaultorder(Product{S})) where {S}
if S <: State
all(==(1) ndims, arrays) || throw(DimensionMismatch("Product{State} is constructed with vectors"))
elseif S <: Operator
all(==(2) ndims, arrays) || throw(DimensionMismatch("Product{Operator} is constructed with matrices"))
end

n = length(arrays)

oinds = map(genoutsym, 1:n)
iinds = map(geninsym, 1:n)

tensors::Vector{Tensor} = map(enumerate(arrays)) do (i, array)
inds = map(order) do dir
if dir === :o
oinds[i]
elseif dir === :i
iinds[i]
end
end
Tensor(array, inds)
end

return new{S}(TensorNetwork(tensors))
end
end

defaultorder(::Type{Product{Scalar}}) = ()
defaultorder(::Type{Product{State}}) = (:o,)
defaultorder(::Type{Product{Operator}}) = (:i, :o)

socket(::Type{<:Product{S}}) where {S} = S()

# AbstractTensorNetwork interface
for f in [:(Tenet.inds), :(Tenet.tensors), :(Base.size)]
@eval $f::Product; kwargs...) = $f.wrap; kwargs...)
end

0 comments on commit 9b6cc30

Please sign in to comment.