-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimized tensor network contraction using einexpr when specifying output indices #59
Comments
Found a work around for my specific use case |
Hi, @bartdv123! Thanks for noticing this potential issue. I managed to find a reproducing example of this behavior: julia> using Tenet
julia> using EinExprs
julia> tn = TensorNetwork([
Tensor(rand(2, 2, 2), [:i, :j, :k]),
Tensor(rand(2, 2), [:j, :l]),
Tensor(rand(2, 2, 2, 2), [:l, :k, :m, :n]),
Tensor(rand(2, 2, 2), [:n, :o, :p])])
TensorNetwork (#tensors=4, #inds=8)
julia> output_inds = inds(tn, :open)
4-element Vector{Symbol}:
:m
:o
:p
:i
julia> contract_all = einexpr(tn)
SizedEinExpr{Symbol}(EinExpr{Symbol}([:i, :m, :o, :p], EinExpr{Symbol}[EinExpr{Symbol}([:n, :o, :p], EinExpr{Symbol}[]), EinExpr{Symbol}([:i, :m, :n], EinExpr{Symbol}[EinExpr{Symbol}([:i, :k, :l], EinExpr{Symbol}[EinExpr{Symbol}([:i, :j, :k], EinExpr{Symbol}[]), EinExpr{Symbol}([:j, :l], EinExpr{Symbol}[])]), EinExpr{Symbol}([:l, :k, :m, :n], EinExpr{Symbol}[])])]), Dict(:l => 2, :m => 2, :o => 2, :p => 2, :n => 2, :j => 2, :k => 2, :i => 2))
julia> t1 = contract(tn, path=cpath) |> inds
4-element Vector{Symbol}:
:o
:p
:i
:m
julia> cpath = einexpr(tn, outputs=[:i, :p])
SizedEinExpr{Symbol}(EinExpr{Symbol}([:i, :m, :o, :p], EinExpr{Symbol}[EinExpr{Symbol}([:n, :o, :p], EinExpr{Symbol}[]), EinExpr{Symbol}([:i, :m, :n], EinExpr{Symbol}[EinExpr{Symbol}([:i, :k, :l], EinExpr{Symbol}[EinExpr{Symbol}([:i, :j, :k], EinExpr{Symbol}[]), EinExpr{Symbol}([:j, :l], EinExpr{Symbol}[])]), EinExpr{Symbol}([:l, :k, :m, :n], EinExpr{Symbol}[])])]), Dict(:l => 2, :m => 2, :o => 2, :p => 2, :n => 2, :j => 2, :k => 2, :i => 2))
julia> t2 = contract(tn, path=cpath) |> inds
4-element Vector{Symbol}:
:o
:p
:i
:m @mofeing It seems that |
hi @bartdv123
mmm nope. what it does is it's just selecting and contracting the tensors involved in the
@jofrevalles Well, the I'm moving the issue to EinExprs.jl because that is where the issue has its origin. |
Hi there!
I'm been using Tenet the past year during my master's thesis and I stumbled upon a problem when trying to optimize a partial tensor network contraction, instead of a full contraction. The documentation states in einexpr.jl to specify the open indices in the path. But even when specifying the open indices in the einexpr with the outptus = inds(....) - keyword Tenet.contract(network, path=cpath) contracts the whole network?
Example:
output_inds =[Symbol("7"), :v2, Symbol("12"), Symbol("9"), :v3, :v1, Symbol("8"), :v5, Symbol("14"), :v4, Symbol("15")]
cpath = einexpr(transformed_2_mps_network, outputs = output_inds)
mps_network = Tenet.contract(mps_network, path=cpath)
println(typeof(mps_network)) --> return not a tensor network but a single tensor, so contracts all indices and doesn't leave the specified indices open?
See this image for definition of what the indices mean:
The text was updated successfully, but these errors were encountered: