# Using symmetry with TensorKit: ERROR: LoadError: MethodError: no method matching similarstructure\_from\_indices

**URL:** <https://discourse.julialang.org/t/using-symmetry-with-tensorkit-error-loaderror-methoderror-no-method-matching-similarstructure-from-indices/59572>\
**Category:** Numerics\
**Tags:** tensors\
**Created:** [April 19, 2021, 1:02am UTC](https://discourse.julialang.org/t/using-symmetry-with-tensorkit-error-loaderror-methoderror-no-method-matching-similarstructure-from-indices/59572 "2021-04-19T01:02:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nellatur](https://avatars.discourse-cdn.com/v4/letter/n/76d3ee/32.png) [@Nellatur](https://discourse.julialang.org/u/Nellatur)\
**Post date:** [April 19, 2021, 1:02am UTC](https://discourse.julialang.org/t/using-symmetry-with-tensorkit-error-loaderror-methoderror-no-method-matching-similarstructure-from-indices/59572/1 "2021-04-19T01:02:01Z")

</div>

I tried to utilize symmetry in tensor contraction ` A[a,b]*B[b,c,d] = C[a,c,d]` with `B[b,c,d] = B[b,d,c]`.  
Based on [Tutorial · TensorKit.jl](https://jutho.github.io/TensorKit.jl/stable/man/tutorial/#Symmetries)  
I tried the following code

```julia
using TensorKit
using BenchmarkTools

#using TensorOperations
# A[a,b]*B[b,c,d] = C[a,c,d]
na = nb = nc = nd = 12
A = Tensor(randn, ℝ^na ⊗ ℝ^nb)
println(A)
#TensorMap((ℝ^na ⊗ ℝ^nb) ← ProductSpace{CartesianSpace, 0}()):
#A = rand(na, nb)
B = rand(nb, nc, nd)
C = zeros(na, nc, nd)
# symmetrize
for c in 1:nc
  for d in 1:c
    B[:,c,d] = B[:,d,c] 
  end 
end    
    
print("test symm",B[1,2,3], B[1,3,2] )

#@btime @tensor $C[a,c,d] := $A[a,b] * $B[b,c,d]
@btime @tensor C[a,c,d] := A[a,b] * B[b,c,d]

```

I got

```julia
7ERROR: LoadError: MethodError: no method matching similarstructure_from_indices(::Type{Float64}, ::Tuple{Int64}, ::Tuple{Int64, Int64}, ::Tuple{Int64, Int64, Int64}, ::Tuple{}, ::Tensor{CartesianSpace, 2, Trivial, Matrix{Float64}, Nothing, Nothing}, ::Array{Float64, 3}, ::Symbol, ::Symbol)
Closest candidates are:
  similarstructure_from_indices(::Type, ::Tuple{Vararg{Int64, N}} where N, ::Tuple{Vararg{Int64, N}} where N, ::Tuple{Vararg{Int64, N}} where N, ::Tuple{Vararg{Int64, N}} where N, ::AbstractArray, ::AbstractArray, ::Symbol, ::Symbol) at /home/cwang/.julia/packages/TensorOperations/Ydu0m/src/implementation/stridedarray.jl:33
  similarstructure_from_indices(::Type, ::Tuple{Vararg{Int64, N}} where N, ::Tuple{Vararg{Int64, N}} where N, ::Tuple{Vararg{Int64, N}} where N, ::Tuple{Vararg{Int64, N}} where N, ::AbstractTensorMap, ::AbstractTensorMap, ::Symbol, ::Symbol) at /home/cwang/.julia/packages/TensorKit/GctVn/src/tensors/tensoroperations.jl:353
  similarstructure_from_indices(::Type, ::Tuple{Vararg{Int64, N}} where N, ::Tuple{Vararg{Int64, N}} where N, ::Tuple{Vararg{Int64, N}} where N, ::Tuple{Vararg{Int64, N}} where N, ::AbstractArray, ::AbstractArray, ::Symbol)

```

error message. How to program it properly ☹ In general, if there are many symmetries in tensors, will it speed up the contraction?

---

<div class="post-metadata">

**Author:** ![Nellatur](https://avatars.discourse-cdn.com/v4/letter/n/76d3ee/32.png) [@Nellatur](https://discourse.julialang.org/u/Nellatur)\
**Post date:** [April 22, 2021, 2:53am UTC](https://discourse.julialang.org/t/using-symmetry-with-tensorkit-error-loaderror-methoderror-no-method-matching-similarstructure-from-indices/59572/2 "2021-04-22T02:53:58Z")

</div>

> [@Nellatur](#):
>
> `@btime @tensor C[a,c,d] := A[a,b] * B[b,c,d]`

I managed to work it out. I need to define

```julia
B = Tensor(randn, ℝ^nb ⊗ ℝ^nc⊗ ℝ^nd)

```
