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 `DiagonalReduction` transformation for `TensorNetwork` #58

Closed jofrevalles closed 1 year ago

jofrevalles commented 1 year ago

Summary

This PR addresses the issue #14 (resolves #14) by introducing the DiagonalReduction transformation in the transform! function for TensorNetworks. This transformation applies diagonal reduction (as defined here) to simplify the tensor network while preserving its mathematical properties. The key idea is to minimize the number of indices by identifying tensors with a certain diagonal structure and collapsing these indices, potentially leading to computational efficiency.

In addition to the implementation of the transformation, this PR includes tests to ensure correctness and robustness of the new method.

Example

julia> using Tenet

julia> data = [1.0 0.0; 0.0 1.0;;; 1.0 0.0; 0.0 1.0] # We can clearly see that the first and second indices are diagonal
2×2×2 Array{Float64, 3}:
[:, :, 1] =
 1.0  0.0
 0.0  1.0

[:, :, 2] =
 1.0  0.0
 0.0  1.0

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

julia> tn = TensorNetwork([A, B])
TensorNetwork{Arbitrary}(#tensors=2, #inds=5)

julia> [labels(tensor) for tensor in tn.tensors]
2-element Vector{Tuple{Symbol, Symbol, Vararg{Symbol}}}:
 (:i, :k)
 (:i, :l, :m)

This example demonstrates how DiagonalReduction effectively reduces the dimension of the first tensor and updates the rest of the network accordingly.

codecov[bot] commented 1 year ago

Codecov Report

Merging #58 (8ce73a6) into master (6b1ed8c) will increase coverage by 0.65%. The diff coverage is 94.28%.

@@            Coverage Diff             @@
##           master      #58      +/-   ##
==========================================
+ Coverage   82.11%   82.76%   +0.65%     
==========================================
  Files          12       12              
  Lines         615      650      +35     
==========================================
+ Hits          505      538      +33     
- Misses        110      112       +2     
Impacted Files Coverage Δ
src/Transformations.jl 96.55% <94.28%> (-3.45%) :arrow_down:

... and 1 file with indirect coverage changes