Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SpaceMismatch for the naive gradient evaluation #147

Open
Confusio opened this issue Mar 3, 2025 · 1 comment
Open

SpaceMismatch for the naive gradient evaluation #147

Confusio opened this issue Mar 3, 2025 · 1 comment

Comments

@Confusio
Copy link

Confusio commented Mar 3, 2025

I define the following function to evaluate the energy and the gradient by naively using the 10 ctmrg steps to avoid the divergent gradient in the fixed-point method. I don't think I need fix the truncation space and then implement truncdim(χenv) for trscheme.

boundary_alg=SimultaneousCTMRG(;projector_alg=FullInfiniteProjector,trscheme=truncdim(χenv))
function engrad(peps, env, operator,boundary_alg)    
    E, gs = withgradient(peps) do ψ
        for _ in 1:10
            env, _ = ctmrg_iteration(InfiniteSquareNetwork(ψ), env, boundary_alg)
        end
        return cost_function(ψ, env, operator)
    end
    return E, only(gs)
end

However, I got the error

ERROR: LoadError: SpaceMismatch("Vect[(FermionParity ⊠ Irrep[U₁])]((0, 0)=>43, (1, 1/2)=>34, (0, 1)=>15, (1, -1/2)=>34, (0, -1)=>15, (1, 3/2)=>2, (1, -3/2)=>2) ← Vect[(FermionParity ⊠ Irrep[U₁])]((0, 0)=>42, (1, 1/2)=>34, (0, 1)=>15, (1, -1/2)=>34, (0, -1)=>15, (1, 3/2)=>2, (1, -3/2)=>2) ≠ Vect[(FermionParity ⊠ Irrep[U₁])]((0, 0)=>43, (1, 1/2)=>35, (0, 1)=>14, (1, -1/2)=>35, (0, -1)=>14, (1, 3/2)=>2, (1, -3/2)=>2) ← Vect[(FermionParity ⊠ Irrep[U₁])]((0, 0)=>42, (1, 1/2)=>35, (0, 1)=>14, (1, -1/2)=>35, (0, -1)=>14, (1, 3/2)=>2, (1, -3/2)=>2)")
Stacktrace:
  [1] add(ty::TensorMap{ComplexF64, GradedSpace{ProductSector{Tuple{FermionParity, U1Irrep}}, TensorKit.SortedVectorDict{ProductSector{Tuple{FermionParity, U1Irrep}}, Int64}}, 1, 1, Vector{ComplexF64}}, tx::TensorMap{ComplexF64, GradedSpace{ProductSector{Tuple{FermionParity, U1Irrep}}, TensorKit.SortedVectorDict{ProductSector{Tuple{FermionParity, U1Irrep}}, Int64}}, 1, 1, Vector{ComplexF64}}, α::VectorInterface.One, β::VectorInterface.One)

due to the call of the function

# Functions used for FP differentiation and by KrylovKit.linsolve
function Base.:+(e₁::CTMRGEnv, e₂::CTMRGEnv)
    return CTMRGEnv(e₁.corners + e₂.corners, e₁.edges + e₂.edges)
end

I want to know where the add function for the environment tensors is called in my defined function. I even don't think it is a well defined operation for adding two environment tensors.

@lkdvos
Copy link
Member

lkdvos commented Mar 3, 2025

This is a Zygote thing: we are representing the cotangents of the CTMRGEnv as CTMRGEnv objects (similar to how the cotangent of a Vector is again a Vector).
In other words, Zygote is trying to "retract" the environment here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants