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

Transform hyperindices to COPY-tensors on `plot(::TensorNetwork)` #21

Closed mofeing closed 1 year ago

mofeing commented 1 year ago

Our plot function is currently not capable of plotting hyperedges (which should be shown as "bags" or "subsets" containing the connected nodes). One solution is to do as quimb and show hyperindices as tensors connecting involved tensors.

In order to do that, I created the HyperindConverter transformation, which replaces hyperindices with COPY-tensors. It should be as easy to use as:

tn_plot = transform(tn, HyperindConverter)

Inserted COPY-tensors have a metadata parameter called dual that contains the label of the replaced hyperindex. When plotting, the newly created edges of the COPY-tensor should not have its labels shown when the labels=true. Instead, the label in the dual metadata should be used.

Tip This code will return you the list of the newly created COPY-tensors that are dual of hyperindices:

copytensors = filter(Base.Fix2(haskey, :dual), tensors(tn_plot))

Extra-point if the label of the hyperindex is not plot on every edge of the COPY-tensor, but only once per COPY-tensor. Extra-point if COPY-tensors are plot in a different way to the rest of tensors. I was thinking of just small black dots (like now) for COPY-tensors and white-background, black-circunference for the rest of tensors. It would be awesome if COPY-tensors could be represented with rhombus or diamonds shapes.

jofrevalles commented 1 year ago

Extra-point if COPY-tensors are plot in a different way to the rest of tensors. I was thinking of just small black dots (like now) for COPY-tensors and white-background, black-circunference for the rest of tensors. It would be awesome if COPY-tensors could be represented with rhombus or diamonds shapes.

Wouldn't it be better if the COPY tensors were a node with size 0, instead of having a diamond shape. I think that is like how quimb does it as well. Like this: Screenshot from 2023-02-23 14-20-39

mofeing commented 1 year ago

I don't agree that size 0 is better. In the example you provide, it is not clear if it is a COPY-tensor or two unrelated edges.

I think it should be noted by some shape or color that is different to a regular tensor. The diamond shape is due to the fact that diagonal matrices (which are order-2 COPY-tensors) are drawn with diamond shapes.