Skip to content

Autodiff for twist? #216

@Confusio

Description

@Confusio

For fPEPS, I define
⊙(t1::AbstractTensorMap, t2::AbstractTensorMap)=twist(t1, filter(i -> !isdual(space(t1, i)), domainind(t1)))*t2
to take account the fermionic parity factors during the contraction. However, I get an error for the autodiff. The complete the code is following:

using MKL, TensorKit, LinearAlgebra,Zygote
(t1::AbstractTensorMap, t2::AbstractTensorMap)=twist(t1, filter(i -> !isdual(space(t1, i)), domainind(t1)))*t2

V=Vect[FermionParitySU2Irrep]((0, 0) => 2, (1, 1 // 2) => 1)
space_1=Vect[FermionParitySU2Irrep]((0, 0) => 2, (1, 1 // 2) => 1)'
space_2=Vect[FermionParitySU2Irrep]((0, 0) => 2, (1, 1 // 2) => 1)'
space_3=Vect[FermionParitySU2Irrep]((0, 0) => 2, (1, 1 // 2) => 1)
space_4=Vect[FermionParitySU2Irrep]((0, 0) => 2, (1, 1 // 2) => 1)
As=randn(ComplexF64,space_1space_2space_3space_4V,one(V))

f(x)=real(scalar(x'x));
en, gd = withgradient(x -> f(x), As)

The output

ERROR: LoadError: Compiling Tuple{typeof(get!), TensorKit.var"#147#148"{TensorMapSpace{GradedSpace{ProductSector{Tuple{FermionParity, SU2Irrep}}, TensorKit.SortedVectorDict{ProductSector{Tuple{FermionParity, SU2Irrep}}, Int64}}, 0, 5}}, LRUCache.LRU{Any, Any}, TensorMapSpace{GradedSpace{ProductSector{Tuple{FermionParity, SU2Irrep}}, TensorKit.SortedVectorDict{ProductSector{Tuple{FermionParity, SU2Irrep}}, Int64}}, 0, 5}}: ArgumentError: array must be non-empty
Stacktrace:
  [1] macro expansion
    @ ~/.julia/packages/Zygote/3To5I/src/compiler/interface2.jl:0 [inlined]
...

Is this an error for the autodiff for twist? How to work around this in a simple way? is heavily used in the code.

Julia and TensorKit version:
Julia Version 1.11.3 (2025-01-21)
[07d1fe3e] TensorKit v0.14.3

Many thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions