Skip to content

Commit 39a5eee

Browse files
committed
Address remaining review comments
1 parent 2cecd17 commit 39a5eee

File tree

3 files changed

+51
-34
lines changed

3 files changed

+51
-34
lines changed

src/algorithms/optimization/peps_optimization.jl

+29-22
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,9 @@ function fixedpoint(
195195
if isnothing(alg.symmetrization)
196196
retract = peps_retract
197197
else
198-
retract, symm_finalize! = symmetrize_retract_and_finalize!(alg.symmetrization)
199-
fin! = finalize! # Previous finalize!
200-
finalize! = (x, f, g, numiter) -> fin!(symm_finalize!(x, f, g, numiter)..., numiter)
198+
retract, finalize! = symmetrize_retract_and_finalize!(
199+
alg.symmetrization, retract, finalize!
200+
)
201201
end
202202

203203
# :fixed mode compatibility
@@ -282,19 +282,19 @@ end
282282
Performs a norm-preserving retraction of an infinite PEPS `A = x[1]` along `η` with step
283283
size `α`, giving a new PEPS `A´`,
284284
```math
285-
A' \\leftarrow \\cos \\left( α \\frac{||η||}{||A||} \\right) A + \\sin \\left( α \\frac{||η||}{||A||} \\right) ||A|| \\frac{η}{||η||},
285+
A' \\cos ( α ‖η‖ / ‖A‖ ) A + \\sin ( α ‖η‖ / ‖A‖ ) ‖A‖ η / ‖η‖,
286286
```
287287
and corresponding directional derivative `ξ`,
288288
```math
289-
ξ = \\cos \\left( α \\frac{||η||}{||A||} \\right) η - \\sin \\left( α \\frac{||η||}{||A||} \\right) ||η|| \\frac{A}{||A||},
289+
ξ = \\cos ( α ‖η‖ / ‖A‖ ) η - \\sin ( α ‖η‖ / ‖A‖ ) ‖η‖ A / ‖A‖,
290290
```
291-
such that ``\\langle A', ξ \\rangle = 0`` and ``||A'|| = ||A||``.
291+
such that `` A', ξ = 0`` and ``‖A'‖ = ‖A‖``.
292292
"""
293293
function peps_retract(x, η, α)
294294
peps = x[1]
295295
env = deepcopy(x[2])
296296

297-
retractions = vector_retract.(unitcell(peps), unitcell(η), α)
297+
retractions = norm_preserving_retract.(unitcell(peps), unitcell(η), α)
298298
peps´ = InfinitePEPS(map(first, retractions))
299299
ξ = InfinitePEPS(map(last, retractions))
300300

@@ -308,19 +308,21 @@ Transports a direction at `A = x[1]` to a valid direction at `A´ = x´[1]` corr
308308
the norm-preserving retraction of `A` along `η` with step size `α`. In particular, starting
309309
from a direction `η` of the form
310310
```math
311-
ξ = \\left\\langle \\frac{η}{||η||}, ξ \\right\\rangle \\frac{η}{||η||} + Δξ
311+
ξ = ⟨ η / ‖η‖, ξ ⟩ η / ‖η‖ + Δξ
312312
```
313-
where ``\\langle Δξ, A \\rangle = \\langle Δξ, η \\rangle = 0``, it returns
313+
where `` Δξ, A = Δξ, η = 0``, it returns
314314
```math
315-
ξ(α) = \\left\\langle \\frac{η}{||η||}, ξ \\right \\rangle \\left( \\cos \\left( α \\frac{||η||}{||A||} \\right) \\frac{η}{||η||} - \\sin( \\left( α \\frac{||η||}{||A||} \\right) \\frac{A}{||A||} \\right) + Δξ
315+
ξ(α) = ⟨ η / ‖η‖, ξ ( \\cos ( α ‖η‖ / ‖A‖ ) η / ‖η‖ - \\sin( ( α ‖η‖ / ‖A‖ ) A / ‖A‖ ) + Δξ
316316
```
317-
such that ``||ξ(α)|| = ||ξ||, \\langle A', ξ(α) \\rangle = 0``.
317+
such that ``ξ(α) = ‖ξ‖, ⟨ A', ξ(α) = 0``.
318318
"""
319319
function peps_transport!(ξ, x, η, α, x´)
320320
peps = x[1]
321321
peps´ = x´[1]
322322

323-
vector_transport!.(unitcell(ξ), unitcell(peps), unitcell(η), α, unitcell(peps´))
323+
norm_preserving_transport!.(
324+
unitcell(ξ), unitcell(peps), unitcell(η), α, unitcell(peps´)
325+
)
324326

325327
return ξ
326328
end
@@ -333,17 +335,22 @@ real_inner(_, η₁, η₂) = real(dot(η₁, η₂))
333335
334336
Return the `retract` and `finalize!` function for symmetrizing the `peps` and `grad` tensors.
335337
"""
336-
function symmetrize_retract_and_finalize!(symm::SymmetrizationStyle)
337-
finf = function symmetrize_finalize!((peps, env), E, grad, _)
338+
function symmetrize_retract_and_finalize!(
339+
symm::SymmetrizationStyle, retract=peps_retract, (finalize!)=OptimKit._finalize!
340+
)
341+
function symmetrize_then_finalize!((peps, env), E, grad, numiter)
342+
# symmetrize the gradient
338343
grad_symm = symmetrize!(grad, symm)
339-
return (peps, env), E, grad_symm
344+
# then finalize
345+
return finalize!((peps, env), E, grad_symm, numiter)
340346
end
341-
retf = function symmetrize_retract((peps, env), η, α)
342-
peps_symm = deepcopy(peps)
343-
peps_symm.A .+= η.A .* α
344-
env′ = deepcopy(env)
345-
symmetrize!(peps_symm, symm)
346-
return (peps_symm, env′), η
347+
function retract_then_symmetrize((peps, env), η, α)
348+
# retract
349+
(peps´, env´), ξ = retract((peps, env), η, α)
350+
# symmetrize retracted point and directional derivative
351+
peps´_symm = symmetrize!(peps´, symm)
352+
ξ_symm = symmetrize!(ξ, symm)
353+
return (peps´_symm, env′), ξ_symm
347354
end
348-
return retf, finf
355+
return retract_then_symmetrize, symmetrize_then_finalize!
349356
end

src/utility/retractions.jl

+20-10
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,25 @@ Utilities for preserving the norm of (VectorInterface-compliant) vectors during
33
=#
44

55
"""
6-
vector_retract(A, η, α)
6+
norm_preserving_retract(A, η, α)
77
88
Performs a norm-preserving retraction of vector `A` along the direction `η` with step size
99
`α`, giving a new vector `A´`,
1010
```math
11-
A' \\leftarrow \\cos \\left( α \\frac{||η||}{||A||} \\right) A + \\sin \\left( α \\frac{||η||}{||A||} \\right) ||A|| \\frac{η}{||η||},
11+
A' \\cos ( α ‖η‖ / ‖A‖ ) A + \\sin ( α ‖η‖ / ‖A‖ ) ‖A‖ η / ‖η‖,
1212
```
1313
and corresponding directional derivative `ξ`,
1414
```math
15-
ξ = \\cos \\left( α \\frac{||η||}{||A||} \\right) η - \\sin \\left( α \\frac{||η||}{||A||} \\right) ||η|| \\frac{A}{||A||},
15+
ξ = \\cos ( α ‖η‖ / ‖A‖ ) η - \\sin ( α ‖η‖ / ‖A‖ ) ‖η‖ A / ‖A‖,
1616
```
17-
such that ``\\langle A', ξ \\rangle = 0`` and ``||A'|| = ||A||``.
17+
such that ``⟨ A', ξ ⟩ = 0`` and ``‖A'‖ = ‖A‖``.
18+
19+
!!! note
20+
The vectors `A` and `η` should satisfy the interface specified by
21+
[VectorInterface.jl](https://github.com/Jutho/VectorInterface.jl)
22+
1823
"""
19-
function vector_retract(A, η, α)
24+
function norm_preserving_retract(A, η, α)
2025
n_A = norm(A)
2126
n_η = norm(η)
2227
sn, cs = sincos* n_η / n_A)
@@ -28,21 +33,26 @@ function vector_retract(A, η, α)
2833
end
2934

3035
"""
31-
vector_transport!(ξ, A, η, α, A′)
36+
norm_preserving_transport!(ξ, A, η, α, A′)
3237
3338
Transports a direction `ξ` at `A` to a valid direction at `A´` corresponding to
3439
the norm-preserving retraction of `A` along `η` with step size `α`. In particular, starting
3540
from a direction `η` of the form
3641
```math
3742
ξ = ⟨ η / ‖η‖, ξ ⟩ η / ‖η‖ + Δξ
3843
```
39-
where ``\\langle Δξ, A \\rangle = \\langle Δξ, η \\rangle = 0``, it returns
44+
where `` Δξ, A = Δξ, η = 0``, it returns
4045
```math
41-
ξ(α) = \\left\\langle \\frac{η}{||η||}, ξ \\right \\rangle \\left( \\cos \\left( α \\frac{||η||}{||A||} \\right) \\frac{η}{||η||} - \\sin( \\left( α \\frac{||η||}{||A||} \\right) \\frac{A}{||A||} \\right) + Δξ
46+
ξ(α) = ⟨ η / ‖η‖, ξ ( \\cos ( α ‖η‖ / ‖A‖ ) η / ‖η‖ - \\sin( ( α ‖η‖ / ‖A‖ ) A / ‖A‖ ) + Δξ
4247
```
43-
such that ``||ξ(α)|| = ||ξ||, \\langle A', ξ(α) \\rangle = 0``.
48+
such that ``‖ξ(α)‖ = ‖ξ‖, ⟨ A', ξ(α) ⟩ = 0``.
49+
50+
!!! note
51+
The vectors `A` and `η` should satisfy the interface specified by
52+
[VectorInterface.jl](https://github.com/Jutho/VectorInterface.jl)
53+
4454
"""
45-
function vector_transport!(ξ, A, η, α, A´)
55+
function norm_preserving_transport!(ξ, A, η, α, A´)
4656
n_A = norm(A)
4757
n_η = norm(η)
4858
sn, cs = sincos* n_η / n_A)

test/utility/retractions.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ Vpepss = [ℂ^4, U1Space(0 => 2, -1 => 1, 1 => 1)]
2525
add!(η, normalized_A, -inner(normalized_A, η))
2626
add!(ζ, normalized_A, -inner(normalized_A, ζ))
2727

28-
A´, ξ = PEPSKit.vector_retract(A, η, α)
28+
A´, ξ = PEPSKit.norm_preserving_retract(A, η, α)
2929
@test norm(A´) norm(A) rtol = 1e-12
3030

31-
PEPSKit.vector_transport!(ζ, A, η, α, A´)
31+
PEPSKit.norm_preserving_transport!(ζ, A, η, α, A´)
3232
@test inner(ζ, A´) 0 atol = 1e-12
3333
end

0 commit comments

Comments
 (0)