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

Fix crash in `transform` function: `transformations` argument #30

Closed jofrevalles closed 1 year ago

jofrevalles commented 1 year ago

Summary

This PR addresses the bug found in the transform function. This bug was not found before because this function is not included in the tests at the moment. Previously, we could not call the transform function since the transformations argument accepted the type Sequence{Transformation} and Transformation is an abstract type. This is now changed so it accepts a Sequence of structs that inherit from Transformation.

Example

julia> using Tenet
julia> tn = TensorNetwork([Tensor(rand([2, 2, 2]...), tuple([:i, :j, :k]...)), Tensor(rand([2, 2, 2]...), tuple([:i, :k, :l]...)), Tensor(rand([2, 2, 2]...), tuple([:i, :l, :j]...))])
TensorNetwork{Arbitrary}(#tensors=3, #inds=4)
julia> tn = transform(tn, [Tenet.HyperindConverter()])
TensorNetwork{Arbitrary}(#tensors=4, #inds=6)

Although this may be counter-intuitive since the transform! function is called with:

julia> transform!(tn, Tenet.HyperindConverter)

What do you think, @mofeing ?

mofeing commented 1 year ago

The way you have written the code won't work because it implies that the type of all the elements in a Sequence (which is just a helper alias for Union{Tuple,Vector}.

Also, the PR fails an Aqua test.

I've refactored the code in such a way that it solves these problems and also abstract the call to transform! in a better way. Also, I've added some tests for theses cases.