Planar automatic differentiation.
Closed this issue · 7 comments
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 :
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
Could you also include what you ran?
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.
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
It's already failing when taking the derivative of the 4th line.
yes, but it should be deriving things backwards, so the 6th line comes first 🙃
Ok, fair enough 😅
Then this is the first contraction it's coming across that contains tau symbols
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.