Skip to content

Commit 461402e

Browse files
committed
Add docstrings
1 parent 7651853 commit 461402e

File tree

5 files changed

+94
-8
lines changed

5 files changed

+94
-8
lines changed

src/Defaults.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ const eigh_rrule_verbosity = 0
114114
# Projectors
115115
const projector_alg = :halfinfinite # ∈ {:halfinfinite, :fullinfinite}
116116
const projector_verbosity = 0
117-
const projector_alg_c4v = :c4v_eigh
117+
const projector_alg_c4v = :c4v_eigh # ∈ {:c4v_eigh, :c4v_qr (TODO)}
118118

119119
# Fixed-point gradient
120120
const gradient_tol = 1.0e-6

src/algorithms/ctmrg/c4v.jl

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
1+
"""
2+
$(TYPEDEF)
3+
4+
CTMRG algorithm assuming a C₄ᵥ-symmetric PEPS, i.e. invariance under 90° spatial rotation and
5+
Hermitian reflection. This requires a single-site unit cell. The projector is obtained from
6+
`eigh` decomposing the Hermitian enlarged corner.
7+
8+
## Fields
9+
10+
$(TYPEDFIELDS)
11+
12+
## Constructors
13+
14+
C4vCTMRG(; kwargs...)
15+
16+
Construct a C₄ᵥ CTMRG algorithm struct based on keyword arguments.
17+
For a full description, see [`leading_boundary`](@ref). The supported keywords are:
18+
19+
* `tol::Real=$(Defaults.ctmrg_tol)`
20+
* `maxiter::Int=$(Defaults.ctmrg_maxiter)`
21+
* `miniter::Int=$(Defaults.ctmrg_miniter)`
22+
* `verbosity::Int=$(Defaults.ctmrg_verbosity)`
23+
* `trunc::Union{TruncationStrategy,NamedTuple}=(; alg::Symbol=:$(Defaults.trunc))`
24+
* `decomp_alg::Union{<:EighAdjoint,NamedTuple}`
25+
* `projector_alg::Symbol=:$(Defaults.projector_alg_c4v)`
26+
"""
127
struct C4vCTMRG{P <: ProjectorAlgorithm} <: CTMRGAlgorithm
228
tol::Float64
329
maxiter::Int
@@ -10,6 +36,33 @@ function C4vCTMRG(; kwargs...)
1036
end
1137
CTMRG_SYMBOLS[:c4v] = C4vCTMRG
1238

39+
"""
40+
$(TYPEDEF)
41+
42+
Projector algorithm implementing the `eigh` decomposition of a Hermitian enlarged corner.
43+
44+
## Fields
45+
46+
$(TYPEDFIELDS)
47+
48+
## Constructors
49+
50+
C4vEighProjector(; kwargs...)
51+
52+
Construct the C₄ᵥ `eigh`-based projector algorithm based on the following keyword arguments:
53+
54+
* `decomp_alg::Union{<:EighAdjoint,NamedTuple}=EighAdjoint()` : `eigh` algorithm including the reverse rule. See [`EighAdjoint`](@ref).
55+
* `trunc::Union{TruncationStrategy,NamedTuple}=(; alg::Symbol=:$(Defaults.trunc))` : Truncation strategy for the projector computation, which controls the resulting virtual spaces. Here, `alg` can be one of the following:
56+
- `:fixedspace` : Keep virtual spaces fixed during projection
57+
- `:notrunc` : No singular values are truncated and the performed SVDs are exact
58+
- `:truncerror` : Additionally supply error threshold `η`; truncate to the maximal virtual dimension of `η`
59+
- `:truncrank` : Additionally supply truncation dimension `η`; truncate such that the 2-norm of the truncated values is smaller than `η`
60+
- `:truncspace` : Additionally supply truncation space `η`; truncate according to the supplied vector space
61+
- `:trunctol` : Additionally supply singular value cutoff `η`; truncate such that every retained singular value is larger than `η`
62+
* `verbosity::Int=$(Defaults.projector_verbosity)` : Projector output verbosity which can be:
63+
0. Suppress output information
64+
1. Print singular value degeneracy warnings
65+
"""
1366
struct C4vEighProjector{S <: EighAdjoint, T} <: ProjectorAlgorithm
1467
decomp_alg::S
1568
trunc::T
@@ -44,15 +97,26 @@ function ctmrg_iteration(
4497
return CTMRGEnv(corner′, edge′), info
4598
end
4699

100+
"""
101+
c4v_enlarge(network, env, ::C4vEighProjector)
102+
103+
Compute the normalized and Hermitian-symmetrized C₄ᵥ enlarged corner.
104+
"""
47105
function c4v_enlarge(network, env, ::C4vEighProjector)
48-
return TensorMap(EnlargedCorner(network, env, (NORTHWEST, 1, 1)))
106+
enlarged_corner = TensorMap(EnlargedCorner(network, env, (NORTHWEST, 1, 1)))
107+
return 0.5 * (enlarged_corner + enlarged_corner') / norm(enlarged_corner)
49108
end
50109
# function c4v_enlarge(enlarged_corner, alg::C4vQRProjector)
51110
# # TODO
52111
# end
53112

113+
"""
114+
c4v_projector(enlarged_corner, alg::C4vEighProjector)
115+
116+
Compute the C₄ᵥ projector from `eigh` decomposing the Hermitian `enlarged_corner`.
117+
Also return the normalized eigenvalues as the new corner tensor.
118+
"""
54119
function c4v_projector(enlarged_corner, alg::C4vEighProjector)
55-
hermitian_corner = 0.5 * (enlarged_corner + enlarged_corner') / norm(enlarged_corner)
56120
trunc = truncation_strategy(alg, enlarged_corner)
57121
D, U, info = eigh_trunc!(hermitian_corner, decomposition_algorithm(alg); trunc)
58122

@@ -70,11 +134,17 @@ end
70134
# # TODO
71135
# end
72136

137+
"""
138+
c4v_renormalize(network, env, projector)
139+
140+
Renormalize the single edge tensor.
141+
"""
73142
function c4v_renormalize(network, env, projector)
74143
new_edge = renormalize_north_edge(env.edges[1], projector, projector', network[1, 1])
75144
return new_edge / norm(new_edge)
76145
end
77146

147+
# TODO: this should eventually be the constructor for a new C4vCTMRGEnv type
78148
function CTMRGEnv(
79149
corner::AbstractTensorMap{T, S, 1, 1}, edge::AbstractTensorMap{T′, S, N, 1}
80150
) where {T, T′, S, N}

src/algorithms/ctmrg/ctmrg.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ supplied via the keyword arguments or directly as an [`CTMRGAlgorithm`](@ref) st
6666
3. Iteration info
6767
4. Debug info
6868
* `alg::Symbol=:$(Defaults.ctmrg_alg)` : Variant of the CTMRG algorithm. See also [`CTMRGAlgorithm`](@ref).
69-
- `:simultaneous`: Simultaneous expansion and renormalization of all sides.
70-
- `:sequential`: Sequential application of left moves and rotations.
69+
- `:simultaneous` : Simultaneous expansion and renormalization of all sides.
70+
- `:sequential` : Sequential application of left moves and rotations.
71+
- `:c4v` : CTMRG assuming C₄ᵥ-symmetric PEPS and environment.
7172
7273
### Projector algorithm
7374
@@ -82,6 +83,7 @@ supplied via the keyword arguments or directly as an [`CTMRGAlgorithm`](@ref) st
8283
* `projector_alg::Symbol=:$(Defaults.projector_alg)` : Variant of the projector algorithm. See also [`ProjectorAlgorithm`](@ref).
8384
- `:halfinfinite` : Projection via SVDs of half-infinite (two enlarged corners) CTMRG environments.
8485
- `:fullinfinite` : Projection via SVDs of full-infinite (all four enlarged corners) CTMRG environments.
86+
- `:c4v_eigh` : Projection via `eigh` of the Hermitian enlarged corner.
8587
8688
## Return values
8789
@@ -103,6 +105,8 @@ set of vectors and values will be returned as well:
103105
* `U_full` : Last unit cell of all left singular vectors.
104106
* `S_full` : Last unit cell of all singular values.
105107
* `V_full` : Last unit cell of all right singular vectors.
108+
109+
For `C4vCTMRG` instead the last eigendecomposition `U` and `D` (and `U_full`, `D_full`) will be returned.
106110
"""
107111
function leading_boundary(env₀::CTMRGEnv, network::InfiniteSquareNetwork; kwargs...)
108112
alg = select_algorithm(leading_boundary, env₀; kwargs...)

src/algorithms/ctmrg/projectors.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ function ProjectorAlgorithm(;
4545
return alg_type(decomp_algorithm, truncation_strategy, verbosity)
4646
end
4747

48+
"""
49+
decomposition_algorithm(alg::ProjectorAlgorithm)
50+
decomposition_algorithm(alg::ProjectorAlgorithm, (dir, r, c))
51+
52+
Return the tensor decomposition algorithm of the `alg` projector algorithm.
53+
Additionally, the multi-index `(dir, r, c)` can be supplied which will return the
54+
decomposition performed at that index, e.g. when using `FixedEigh` or `FixedSVD`.
55+
"""
4856
decomposition_algorithm(alg::ProjectorAlgorithm) = alg.decomp_alg
4957
function decomposition_algorithm(alg::ProjectorAlgorithm, (dir, r, c))
5058
decomp_alg = decomposition_algorithm(alg)

src/utility/eigh.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Construct a `FullEighPullback` algorithm struct from the following keyword argum
2323
* `verbosity::Int=0` : Suppresses all output if `≤0`, prints gauge dependency warnings if `1`, and always prints gauge dependency if `≥2`.
2424
"""
2525
@kwdef struct FullEighPullback
26-
verbosity::Int = 1
26+
verbosity::Int = 0
2727
end
2828

2929
"""
@@ -44,10 +44,9 @@ Construct a `TruncEighPullback` algorithm struct from the following keyword argu
4444
* `verbosity::Int=0` : Suppresses all output if `≤0`, prints gauge dependency warnings if `1`, and always prints gauge dependency if `≥2`.
4545
"""
4646
@kwdef struct TruncEighPullback
47-
verbosity::Int = 1
47+
verbosity::Int = 0
4848
end
4949

50-
# TODO: should this be same struct as SVDAdjoint?
5150
"""
5251
$(TYPEDEF)
5352
@@ -142,7 +141,9 @@ function MatrixAlgebraKit.eigh_trunc!(
142141
return adjoint(D), adjoint(U), info
143142
end
144143

144+
#
145145
## Forward algorithms
146+
#
146147

147148
# Truncated eigh but also return full D and U to make it compatible with :fixed mode
148149
function _eigh_trunc!(
@@ -331,7 +332,10 @@ function _create_eightensors(t::TensorMap, eighdata, dims)
331332
return D, U
332333
end
333334

335+
#
334336
## Reverse-rule algorithms
337+
#
338+
335339
function _get_pullback_gauge_tol(verbosity::Int)
336340
if verbosity 0 # never print gauge sensitivity
337341
return (_) -> Inf

0 commit comments

Comments
 (0)