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

Change argument order leading_boundary with CTMRG #27

Merged
merged 2 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/heisenberg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ alg = PEPSOptimize(;
# E/N = −0.6694421, which is a QMC estimate from https://arxiv.org/abs/1101.3281.
# Of course there is a noticable bias for small χbond and χenv.
ψ₀ = InfinitePEPS(2, χbond)
env₀ = leading_boundary(ψ₀, ctmalg, CTMRGEnv(ψ₀; Venv=ℂ^χenv))
env₀ = leading_boundary(CTMRGEnv(ψ₀; Venv=ℂ^χenv), ψ₀, ctmalg)
result = fixedpoint(ψ₀, H, alg, env₀)
@show result.E
7 changes: 5 additions & 2 deletions src/algorithms/ctmrg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ Regardless of the truncation scheme, the space can be kept fixed with `fixedspac
end

"""
MPSKit.leading_boundary(state, alg::CTMRG, [envinit])
MPSKit.leading_boundary([envinit], state, alg::CTMRG)

Contract `state` using CTMRG and return the CTM environment.
Per default, a random initial environment is used.
"""
function MPSKit.leading_boundary(state, alg::CTMRG, envinit=CTMRGEnv(state))
function MPSKit.leading_boundary(state, alg::CTMRG)
return MPSKit.leading_boundary(CTMRGEnv(state), state, alg)
end
function MPSKit.leading_boundary(envinit, state, alg::CTMRG)
normold = 1.0
CSold = map(x -> tsvd(x; alg=TensorKit.SVD())[2], envinit.corners)
TSold = map(x -> tsvd(x; alg=TensorKit.SVD())[2], envinit.edges)
Expand Down
10 changes: 5 additions & 5 deletions src/algorithms/peps_opt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ function fixedpoint(
E, g = withgradient(peps) do ψ
envs´ = hook_pullback(
leading_boundary,
envs,
ψ,
alg.boundary_alg,
envs;
alg.boundary_alg;
alg_rrule=alg.gradient_alg,
)
ignore_derivatives() do
Expand Down Expand Up @@ -107,11 +107,11 @@ function _rrule(
gradmode::Union{GradMode,KrylovKit.LinearSolver},
::RuleConfig,
::typeof(MPSKit.leading_boundary),
envinit,
state,
alg::CTMRG,
envinit,
)
envs = leading_boundary(state, alg, envinit)
envs = leading_boundary(envinit, state, alg)

function leading_boundary_pullback(Δenvs′)
Δenvs = unthunk(Δenvs′)
Expand All @@ -127,7 +127,7 @@ function _rrule(
∂f∂x(x)::typeof(envs) = env_vjp(x)[2]
∂F∂envs = fpgrad(Δenvs, ∂f∂x, ∂f∂A, Δenvs, gradmode)

return NoTangent(), ∂F∂envs, NoTangent(), ZeroTangent()
return NoTangent(), ZeroTangent(), ∂F∂envs, NoTangent()
end

return envs, leading_boundary_pullback
Expand Down
4 changes: 2 additions & 2 deletions test/boundarymps/vumps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Random.seed!(29384293742893)
N = abs(sum(expectation_value(mps, T)))

ctm = leading_boundary(
psi, CTMRG(; verbosity=1, fixedspace=true), CTMRGEnv(psi; Venv=ComplexSpace(20))
CTMRGEnv(psi; Venv=ComplexSpace(20)), psi, CTMRG(; verbosity=1, fixedspace=true)
)
N´ = abs(norm(psi, ctm))

Expand All @@ -33,7 +33,7 @@ end
N = abs(prod(expectation_value(mps, T)))

ctm = leading_boundary(
psi, CTMRG(; verbosity=1, fixedspace=true), CTMRGEnv(psi; Venv=ComplexSpace(20))
CTMRGEnv(psi; Venv=ComplexSpace(20)), psi, CTMRG(; verbosity=1, fixedspace=true)
)
N´ = abs(norm(psi, ctm))

Expand Down
4 changes: 2 additions & 2 deletions test/ctmrg/gaugefix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ end
)
alg_fixed = CTMRG(; trscheme=truncdim(dim(ctm_space)), verbosity, fixedspace=true)

ctm = leading_boundary(psi, alg, ctm)
ctm = leading_boundary(ctm, psi, alg)
ctm2, = ctmrg_iter(psi, ctm, alg_fixed)
ctm_fixed = gauge_fix(ctm, ctm2)
@test PEPSKit.check_elementwise_convergence(ctm, ctm_fixed; atol=1e-4)
Expand All @@ -75,7 +75,7 @@ end
)
alg_fixed = CTMRG(; trscheme=truncspace(ctm_space), verbosity, fixedspace=true)

ctm = leading_boundary(psi, alg, ctm)
ctm = leading_boundary(ctm, psi, alg)
ctm2, = ctmrg_iter(psi, ctm, alg_fixed)
ctm_fixed = gauge_fix(ctm, ctm2)
@test PEPSKit.check_elementwise_convergence(ctm, ctm_fixed; atol=1e-4)
Expand Down
4 changes: 2 additions & 2 deletions test/ctmrg/gradients.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ gradmodes = [nothing, GeomSum(; tol), ManualIter(; tol), KrylovKit.GMRES(; tol)]
Random.seed!(42039482038)
dir = InfinitePEPS(2, χbond)
psi = InfinitePEPS(2, χbond)
env = leading_boundary(psi, boundary_alg, CTMRGEnv(psi; Venv=ℂ^χenv))
env = leading_boundary(CTMRGEnv(psi; Venv=ℂ^χenv), psi, boundary_alg)

alphas, fs, dfs1, dfs2 = OptimKit.optimtest(
(psi, env), dir; alpha=steps, retract=PEPSKit.my_retract, inner=PEPSKit.my_inner
) do (peps, envs)
E, g = Zygote.withgradient(peps) do psi
envs2 = PEPSKit.hook_pullback(leading_boundary, psi, boundary_alg, envs; alg_rrule)
envs2 = PEPSKit.hook_pullback(leading_boundary, envs, psi, boundary_alg; alg_rrule)
return costfun(psi, envs2, H)
end
return E, only(g)
Expand Down
2 changes: 1 addition & 1 deletion test/heisenberg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ opt_alg = PEPSOptimize(;
# initialize states
Random.seed!(91283219347)
psi_init = InfinitePEPS(2, χbond)
env_init = leading_boundary(psi_init, ctm_alg, CTMRGEnv(psi_init; Venv=ComplexSpace(χenv)))
env_init = leading_boundary(CTMRGEnv(psi_init; Venv=ComplexSpace(χenv)), psi_init, ctm_alg)

# find fixedpoint
result = fixedpoint(psi_init, H, opt_alg, env_init)
Expand Down
Loading