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 `AntiDiagonalGauging` transformation for `TensorNetwork` #61

Closed jofrevalles closed 1 year ago

jofrevalles commented 1 year ago

Summary

This PR addresses the issue #16 (resolves #16) by introducing the AntiDiagonalGauging transformation in the transform! function for TensorNetworks. This transformation applies the anti-diagonal gauging (as defined here) to modify the tensor network while preserving its mathematical properties.

The AntiDiagonalGauging transformation reverses the order of some indices for tensors that fulfill an anti-diagonal condition. While this transformation alone does not directly contribute to computational efficiency, it prepares the tensor network for further simplifications by creating tensors with diagonal indices. These tensors can then be simplified using the DiagonalReduction transformation, which was implemented in PR #58.

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

Example

julia> using Tenet

julia> data = [0.0 1.0; 1.0 0.0;;; 0.0 1.0; 1.0 0.0] # The first and second indices are anti-diagonal
2×2×2 Array{Float64, 3}:
[:, :, 1] =
 0.0  1.0
 1.0  0.0

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

julia> A = Tensor(data, (:i, :j, :k))
2×2×2 Tensor{Float64, 3, Array{Float64, 3}}: ...

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

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

julia> gauged_tn = transform(tn, Tenet.AntiDiagonalGauging)
TensorNetwork{Arbitrary}(#tensors=2, #inds=4)

julia> tensors(gauged_tn)[1] # We see that it now has a diagonal structure
2×2×2 Tensor{Float64, 3, Array{Float64, 3}}:
[:, :, 1] =
 1.0  0.0
 0.0  1.0

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

julia> contract(A, B) ≈ contract(tensors(gauged_tn)[1], tensors(gauged_tn)[2])
true

In this example, we illustrate how the AntiDiagonalGauging transformation converts a tensor with an anti-diagonal structure into one with a diagonal structure.

codecov[bot] commented 1 year ago

Codecov Report

Merging #61 (9750d63) into master (03d0c8b) will increase coverage by 1.18%. The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master      #61      +/-   ##
==========================================
+ Coverage   82.76%   83.95%   +1.18%     
==========================================
  Files          12       12              
  Lines         650      667      +17     
==========================================
+ Hits          538      560      +22     
+ Misses        112      107       -5     
Impacted Files Coverage Δ
src/Transformations.jl 97.50% <100.00%> (+0.94%) :arrow_up:

... and 1 file with indirect coverage changes