bsc-quantic / Tenet.jl

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

Inconsistent `node_attr` behavior for invisible "ghost" nodes in `plot` #85

Closed jofrevalles closed 10 months ago

jofrevalles commented 1 year ago

Summary

The graphplot function does not allow plotting graphs with nodes that have unconnected edges. To manage this, "ghost" nodes with zero size are internally created at the edges where there are no direct connections. While these "ghost" nodes are invisible in the plot, they introduce inconsistencies when using the node_attr keyword arguments such as node_size, node_color, etc., in the plot function.

Specifically, when a user passes a Vector for some node_attr, the function also expects values for these invisible "ghost" nodes, which I believe is counter-intuitive to the user. Users would naturally expect to specify attributes only for the "real" nodes, and have the "ghost" nodes' attributes be handled internally by the plot function. Requiring users to pass in extra attribute values for "ghost" nodes complicates the interface and can lead to errors.

Example

julia> using Makie; using CairoMakie; using Tenet

julia> fig = Figure()

julia> t_lm = Tensor(rand(2, 2), (:l, :m))
2×2 Tensor{Float64, 2, Matrix{Float64}}: ...

julia> t_ilm = Tensor(rand(2, 2, 2), (:i, :l, :m))
2×2×2 Tensor{Float64, 3, Array{Float64, 3}}: ...

julia> tn = TensorNetwork([t_ilm, t_lm])
TensorNetwork{Arbitrary, NamedTuple{(), Tuple{}}}(#tensors=2, #inds=3)

julia> plot(tn; node_color=[:red, :green])
Error showing value of type Makie.FigureAxisPlot:
ERROR: All non scalars need same length, Found lengths for each argument: (3, 2, 3, 1, 1, 3, 3, 1), (Vector{Point{2, Float32}}, Vector{ColorTypes.RGBA{Float32}}, Vector{Real}, ColorTypes.RGBA{Float32}, Float32, Vector{BezierPath}, Vector{Vec{2, Float32}}, Quaternionf)
Stacktrace:
...