# Using Tensorial.jl to deal with Tensors with high symmetries

**URL:** <https://discourse.julialang.org/t/using-tensorial-jl-to-deal-with-tensors-with-high-symmetries/116360>\
**Category:** Performance\
**Tags:** tensors\
**Created:** [June 28, 2024, 1:51pm UTC](https://discourse.julialang.org/t/using-tensorial-jl-to-deal-with-tensors-with-high-symmetries/116360 "2024-06-28T13:51:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Uranium238](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uranium238/32/209706_2.png) [@Uranium238](https://discourse.julialang.org/u/Uranium238)\
**Post date:** [June 28, 2024, 1:51pm UTC](https://discourse.julialang.org/t/using-tensorial-jl-to-deal-with-tensors-with-high-symmetries/116360/1 "2024-06-28T13:51:53Z")

</div>

I am writing code that deals with contractions of large tensors which possess high symmetry.

As an example, I have a tensor `g` whose certain entries are read from a data file. The remaining entries are entered using the permutational symmetries

```julia
        g[K,L,I,J]=g[I,J,K,L]
        g[J,I,L,K]=g[I,J,K,L]
        g[L,K,J,I]=g[I,J,K,L]
        g[J,I,K,L]=g[I,J,K,L]
        g[L,K,I,J]=g[I,J,K,L]
        g[I,J,L,K]=g[I,J,K,L]
        g[K,L,J,I]=g[I,J,K,L]

```

I know that Tensorial.jl has support for `SymmetricFourthOrderTensors` , but I cannot figure out how exactly to exploit the symmetry in question. As a direct example of where it might be helpful :

I am dealing with contractions like

```julia
@tensor Trm2[a_1,a_2,i_1,i_2] := - g_voov[a_1,i_3,i_1,a_3] * T2[a_2,a_3,i_3,i_2]

```

Where each tensor can be of rank `60x60x10x10` , which is quite large. However, the tensors on the RHS `g_voov` and `T2` posses many permutational symmetries which are not being exploited in TensorOperation.jl 's `@tensor` macro inheretly. Tensoril.jl 's [Benchmarks](https://keitanakamura.github.io/Tensorial.jl/stable/Benchmarks/) indicate we can get massive speedups when using tensors of appropriate symmetry class. It would be really helpful if someone could give me a direction in which I can move in to start exploiting these symmetries using the Tensorial.jl package. Whenever I am dealing with these contractions, the tensors like `g_voov` are going to be read from the disk. Is there any way to auto-detect the symmetries during reading the binaries ? Or if I am aware beforehand of the symmetries : How can I initialize the tensor in memory such that the program is aware of the symmetries.

---

<div class="post-metadata">

**Author:** ![juthohaegeman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juthohaegeman/32/8620_2.png) [@juthohaegeman](https://discourse.julialang.org/u/juthohaegeman)\
**Post date:** [June 28, 2024, 3:32pm UTC](https://discourse.julialang.org/t/using-tensorial-jl-to-deal-with-tensors-with-high-symmetries/116360/2 "2024-06-28T15:32:35Z")

</div>

While I am not familiar with the details of Tensorial.jl, it seems to have an `@einsum` macro, which would behave similar to TensorOperations.jl `@tensor` and would probably address your question.
