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

Planar automatic differentiation. #11

Closed
Gertian opened this issue Feb 12, 2024 · 7 comments
Closed

Planar automatic differentiation. #11

Gertian opened this issue Feb 12, 2024 · 7 comments

Comments

@Gertian
Copy link
Contributor

Gertian commented Feb 12, 2024

I tried to use @lkdvos his new https://github.com/Jutho/TensorKit.jl/tree/ld/planar-ad to get the automatic derivative of the planar PEPS implementation but this seems to fail.

More specifically the /examples/fermionic.jl file fails to execute due to a space mismatch whilst calculating the derivative :
image

Please note that this is still with ComplexSpaces, the only fermionic part of the code is my usage of @planar and tau symbols.

Edit : my branch is at https://github.com/quantumghent/PEPSKit.jl/tree/planar_branch

@lkdvos
Copy link
Member

lkdvos commented Feb 12, 2024

Could you also include what you ran?

@Gertian
Copy link
Contributor Author

Gertian commented Feb 12, 2024

This file : https://github.com/quantumghent/PEPSKit.jl/blob/planar_branch/examples/fermionic.jl

It's mostly the old testfile from the square lattice Heisenberg. The error comes at line 103 : cfun((ψ₀, env₀)) where

function cfun(x)
    (ψ, env) = x

    function fun(peps)
        env = leading_boundary(peps, alg_ctm, env)
        x = H_expectation_value(peps, env, SqLatHeisenberg())
        return x
    end

    env = leading_boundary(ψ, alg_ctm, env)
    E = H_expectation_value(ψ, env, SqLatHeisenberg())
    ∂E = fun'(ψ)
    @assert !isnan(norm(∂E))    
    return E, ∂E
end

Note that

function H_expectation_value::InfinitePEPS, env::PEPSKit.CTMRGEnv, H::AbstractTensorMap{S,2,2}) where {S}
    E = 0.0
    for r in 1:size(ψ, 1), c in 1:size(ψ, 2)
        ρ₂ = PEPSKit.ρ₂_horizontal(r, c, ψ, env)

        @planar norm_state = ρ₂[1 2; 1 2]
        @planar energy_horizonal = H[1 3; 2 4] * ρ₂[2 4; 1 3]

        E = E + (energy_horizonal*(-1)^r )/norm_state
    end
    if !(E  real(E)) 
        @warn "Zygote seems to manage to generate a state for which the energy is infinite. This is not good."
        @show E 
    end
    return real(E)
end

returns real(E) if not zygote stalls earlier because it seems to find a state with E = inf + im*inf that then triggers an error in gradient calculation because it's doesn't want to calculate gradients of complex functions.

@lkdvos
Copy link
Member

lkdvos commented Feb 12, 2024

Ok I'm a bit confused about why it works at all now, I haven't actually implemented any traces at all, so the 6th line of your expectation value shouldn't be working :p

@Gertian
Copy link
Contributor Author

Gertian commented Feb 12, 2024

It's already failing when taking the derivative of the 4th line.

@lkdvos
Copy link
Member

lkdvos commented Feb 12, 2024

yes, but it should be deriving things backwards, so the 6th line comes first 🙃

@Gertian
Copy link
Contributor Author

Gertian commented Feb 12, 2024

Ok, fair enough 😅

Then this is the first contraction it's coming across that contains tau symbols

@lkdvos
Copy link
Member

lkdvos commented Jul 9, 2024

Will close this issue for now, the fermions should be supported, and I don't think there are too many plans to support anyonic systems in the near future.

@lkdvos lkdvos closed this as completed Jul 9, 2024
@lkdvos lkdvos closed this as not planned Won't fix, can't repro, duplicate, stale Jul 9, 2024
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