bsc-quantic / Tenet.jl

Composable Tensor Network library in Julia
https://bsc-quantic.github.io/Tenet.jl/
Apache License 2.0
17 stars 1 forks source link

Add support for visualization of open indices in plot functions #34

Closed jofrevalles closed 1 year ago

jofrevalles commented 1 year ago

Summary

In this PR we address issue #32: we fix the plot functions so now we can visualize the open indices that a TensorNetwork may have. This is done by adding 'ghost' tensors of size zero at the edge of each open index.

Example

julia> using Tenet
julia> using GLMakie; using Makie
julia> tn = TensorNetwork([Tensor(rand([2, 2, 2, 2, 2]...), tuple([:i, :t, :k, :x, :y]...)), Tensor(rand([2, 2, 2, 2]...), tuple([:i, :k, :s, :p]...)), Tensor(rand([2, 2]...), tuple([:i, :s]...)), Tensor(rand([2, 2, 2]...), tuple([:p, :t, :z]...))])
TensorNetwork{Arbitrary}(#tensors=4, #inds=8)
julia> using NetworkLayout
julia> plot(tn; labels=true, layout=Spring(dim=3))
Tuple{Symbol, Vararg{Symbol}}[(:p, :t, :z), (:i1, :t, :k, :x, :y), (:i2, :k, :s, :p), (:i3, :s), (:i1, :i2, :i3), (:y, :x), (:z,)]
julia> [tensor.labels for tensor in tn.tensors]
4-element Vector{Tuple{Symbol, Symbol, Vararg{Symbol}}}:
 (:i, :t, :k, :x, :y)
 (:i, :k, :s, :p)
 (:i, :s)
 (:p, :t, :z)
julia> openinds(tn)
3-element Vector{Index}:
 :y
 :z
 :x

image

codecov[bot] commented 1 year ago

Codecov Report

Merging #34 (c5ed358) into master (f25179f) will decrease coverage by 0.02%. The diff coverage is n/a.

@@            Coverage Diff            @@
##           master     #34      +/-   ##
=========================================
- Coverage    0.50%   0.48%   -0.02%     
=========================================
  Files          10      11       +1     
  Lines         596     613      +17     
=========================================
  Hits            3       3              
- Misses        593     610      +17     
Impacted Files Coverage Δ
src/Tenet.jl 100.00% <0.00%> (ø)
src/Tensor.jl 0.00% <0.00%> (ø)
src/Quantum.jl 0.00% <0.00%> (ø)
src/Differentiation.jl 0.00% <0.00%> (ø)
src/MatrixProductState.jl 0.00% <0.00%> (ø)
src/Numerics.jl 0.00% <0.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

jofrevalles commented 1 year ago

Okey, fixed:

julia> using Tenet
julia> using GLMakie; using Makie
julia> tn = TensorNetwork([Tensor(rand([2, 2, 2]...), tuple([:x, :y, :z]...)), Tensor(rand([2, 2]...), tuple([:x, :y]...)), Tensor(rand([2]...), tuple([:x]...))])
TensorNetwork{Arbitrary}(#tensors=3, #inds=3)
julia> [tensor.labels for tensor in tn.tensors]
3-element Vector{Tuple{Symbol, Vararg{Symbol}}}:
 (:x, :y, :z)
 (:x, :y)
 (:x,)
julia> plot(tn; labels=true)

image

jofrevalles commented 1 year ago

Okay, now it works as expected:

julia> using Tenet
julia> using GLMakie; using Makie
julia> tn = TensorNetwork([Tensor(rand([2, 2, 2, 2]...), tuple([:x, :y, :z, :t]...)), Tensor(rand([2, 2]...), tuple([:x, :y]...)), Tensor(rand([2]...), tuple([:x]...))])
TensorNetwork{Arbitrary}(#tensors=3, #inds=4)
julia> plot(tn; labels=true)

image

I have added a dictionary named opencounter which counts the iteration of each open index so we can add each label consecutively.