Skip to content

Commit

Permalink
Rename callback to finalize
Browse files Browse the repository at this point in the history
  • Loading branch information
pbrehmer committed Aug 16, 2024
1 parent 6663716 commit fdaa7bc
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/PEPSKit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export fixedpoint
export InfinitePEPS, InfiniteTransferPEPS
export InfinitePEPO, InfiniteTransferPEPO
export initializeMPS, initializePEPS
export ReflectDepth, ReflectWidth, RotateReflect, symmetrize!, symmetrize_callback
export ReflectDepth, ReflectWidth, RotateReflect, symmetrize!, symmetrize_finalize
export showtypeofgrad
export square_lattice_tf_ising, square_lattice_heisenberg, square_lattice_j1j2
export square_lattice_pwave
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 @@ -122,14 +122,14 @@ end

"""
fixedpoint(ψ₀::InfinitePEPS{T}, H, alg::PEPSOptimize, [env₀::CTMRGEnv];
callback=(args...) -> identity(args)) where {T}
finalize=(args...) -> identity(args)) where {T}
Optimize `ψ₀` with respect to the Hamiltonian `H` according to the parameters supplied
in `alg`. The initial environment `env₀` serves as an initial guess for the first CTMRG run.
By default, a random initial environment is used.
The `callback` kwarg can be used to insert a function call after each optimization step
which maps `peps, envs, E, grad = callback(peps, envs, E, grad)`.
The `finalize` kwarg can be used to insert a function call after each optimization step
which maps `peps, envs, E, grad = finalize(peps, envs, E, grad)`.
The function returns a `NamedTuple` which contains the following entries:
- `peps`: final `InfinitePEPS`
Expand All @@ -145,7 +145,7 @@ function fixedpoint(
H,
alg::PEPSOptimize,
env₀::CTMRGEnv=CTMRGEnv(ψ₀, field(T)^20);
callback=(args...) -> identity(args),
finalize=(args...) -> identity(args),
) where {T}
(peps, env), E, ∂E, numfg, convhistory = optimize(
(ψ₀, env₀), alg.optimizer; retract=my_retract, inner=my_inner
Expand All @@ -164,7 +164,7 @@ function fixedpoint(
return costfun(ψ, envs´, H)
end
g = only(g) # withgradient returns tuple of gradients `g`
peps, envs, E, g = callback(peps, envs, E, g)
peps, envs, E, g = finalize(peps, envs, E, g)
return E, g
end
return (;
Expand Down
4 changes: 2 additions & 2 deletions src/utility/symmetrization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,11 @@ function symmetrize!(peps::InfinitePEPS, symm::RotateReflect)
end

"""
symmetrize_callback(peps, envs, E, grad, symm::SymmetrizationStyle)
symmetrize_finalize(peps, envs, E, grad, symm::SymmetrizationStyle)
Callback function symmetrizing both the `peps` and `grad` tensors.
"""
function symmetrize_callback(peps, envs, E, grad, symm::SymmetrizationStyle)
function symmetrize_finalize(peps, envs, E, grad, symm::SymmetrizationStyle)
peps_symm = symmetrize!(deepcopy(peps), symm)
grad_symm = symmetrize!(deepcopy(grad), symm)
return peps_symm, envs, E, grad_symm
Expand Down
4 changes: 2 additions & 2 deletions test/j1j2_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ psi_init = PEPSKit.symmetrize!(psi_init, PEPSKit.RotateReflect())
env_init = leading_boundary(CTMRGEnv(psi_init, ComplexSpace(χenv)), psi_init, ctm_alg);

# find fixedpoint
callback = (args...) -> PEPSKit.symmetrize_callback(args..., RotateReflect())
result = fixedpoint(psi_init, H, opt_alg, env_init; callback)
finalize = (args...) -> PEPSKit.symmetrize_finalize(args..., RotateReflect())
result = fixedpoint(psi_init, H, opt_alg, env_init; finalize)
ξ_h, ξ_v, = correlation_length(result.peps, result.env)

# compare against Juraj Hasik's data:
Expand Down

0 comments on commit fdaa7bc

Please sign in to comment.