22# center-move as in textbook single-site DMRG)
33_truncates (:: MatrixAlgebraKit.AbstractAlgorithm ) = false
44_truncates (:: MatrixAlgebraKit.TruncatedAlgorithm ) = true
5+ _truncates (alg:: DMRG3S ) = _truncates (alg. alg_gauge)
6+
7+ # a no-truncation `trscheme` selects a (bond-preserving) QR gauge, anything else a truncated SVD
8+ _build_inner_gauge (trscheme, alg_svd, alg_orth) =
9+ trscheme isa MatrixAlgebraKit. NoTruncation ? alg_orth :
10+ MatrixAlgebraKit. TruncatedAlgorithm (alg_svd, trscheme)
11+
12+ _expands (alg) = false
13+ _expands (:: DMRG3S ) = true
514
615"""
716$(TYPEDEF)
817
918Density Matrix Renormalization Group algorithm for finding the dominant eigenvector.
1019
1120Each site update is, in order: (1) an optional bond expansion (`alg_expand`), (2) a single-site
12- eigensolve, and (3) a gauge step (`alg_gauge`). With the defaults (`alg_expand = nothing` and a
13- non-truncating QR `alg_gauge`) this is textbook single-site DMRG, which cannot change the bond
14- dimension. Setting `alg_expand` to a bond-expansion algorithm (e.g. [`OptimalExpand`](@ref),
15- [`RandExpand`](@ref), [`SketchedExpand`](@ref)) enriches the bond with directions orthogonal to
16- the current state ahead of each eigensolve, recovering Controlled Bond Expansion (CBE) DMRG; a
17- truncating `alg_gauge` is then desirable to cut the enlarged bond back down.
18-
19- The gauge algorithm is selected in the keyword constructor from the `trscheme` argument: when it
20- is `notrunc()` the gauge is a QR decomposition (`alg_orth`, [`Householder`](@extref
21- MatrixAlgebraKit.Householder) by default), otherwise it is a truncated SVD (`alg_svd` with the
22- given `trscheme`).
21+ eigensolve, and (3) a gauge step (`alg_gauge`). With the defaults (`alg_expand = nothing` and
22+ `alg_gauge = nothing`, a non-truncating QR gauge derived from `trscheme = notrunc()`) this is
23+ textbook single-site DMRG, which cannot change the bond dimension. Setting `alg_expand` to a
24+ bond-expansion algorithm (e.g. [`OptimalExpand`](@ref), [`RandExpand`](@ref), [`SketchedExpand`](@ref))
25+ enriches the bond with directions orthogonal to the current state ahead of each eigensolve,
26+ recovering Controlled Bond Expansion (CBE) DMRG. Setting `alg_gauge` to a bond-expanding gauge
27+ algorithm (e.g. [`DMRG3S`](@ref)) instead enriches the bond as part of the gauge step, after the
28+ eigensolve. Either way, a truncating gauge (see below) is then desirable to cut the enlarged
29+ bond back down.
30+
31+ # Choosing the gauge
32+
33+ By default, `alg_gauge` is built for you from `trscheme`/`alg_svd`/`alg_orth`: `trscheme =
34+ notrunc()` (the default) gives a QR decomposition (`alg_orth`, [`Householder`](@extref
35+ MatrixAlgebraKit.Householder) by default), any other `trscheme` gives a truncated SVD (`alg_svd`
36+ with that `trscheme`).
37+
38+ ```julia
39+ DMRG() # QR gauge, no truncation
40+ DMRG(; trscheme = truncdim(50)) # truncated SVD gauge
41+ ```
42+
43+ To use a bond-expanding gauge such as [`DMRG3S`](@ref), pass it directly as `alg_gauge`; `trscheme`
44+ etc. are still routed through to build the *inner* gauge it wraps, exactly as above:
45+
46+ ```julia
47+ DMRG(; alg_gauge = DMRG3S(0.1, ExponentialDecay(0.7)), trscheme = truncdim(50))
48+ ```
49+
50+ If `alg_gauge` is instead given with its inner gauge already set (e.g. `DMRG3S(0.1, sched,
51+ some_gauge)`), `trscheme`/`alg_svd`/`alg_orth` must be left at their defaults — passing both is an
52+ error, since it leaves two conflicting sources for the same setting.
2353
2454## Fields
2555
@@ -44,24 +74,38 @@ struct DMRG{A, F, E, G} <: Algorithm
4474 " algorithm used to expand the bond ahead of each local update, or `nothing` for none"
4575 alg_expand:: E
4676
47- " factorization used for the post-update gauge: a QR algorithm (no truncation) or a truncated SVD"
77+ " gauge algorithm applied after each local update: `NoExpand` for a plain gauge step (a QR
78+ algorithm with no truncation, or a truncated SVD), or an algorithm that additionally expands
79+ the bond beforehand (e.g. [`DMRG3S`](@ref))"
4880 alg_gauge:: G
4981end
5082function DMRG (;
5183 tol = Defaults. tol, maxiter = Defaults. maxiter, alg_eigsolve = (;),
5284 verbosity = Defaults. verbosity, finalize = Defaults. _finalize,
53- alg_expand = nothing , trscheme = notrunc () ,
85+ alg_expand = nothing , alg_gauge = nothing , trscheme = nothing ,
5486 alg_svd = Defaults. alg_svd (), alg_orth = Defaults. alg_orth ()
5587 )
5688 # single-site DMRG defaults to the per-bond adaptive controller (`AdaptiveKrylov`); pass
5789 # `alg_eigsolve = (; adaptive = false, ...)` to opt out (the splat overrides the default).
5890 alg_eigsolve′ = alg_eigsolve isa NamedTuple ?
5991 Defaults. alg_eigsolve (; adaptive = true , alg_eigsolve... ) : alg_eigsolve
60- # a no-truncation `trscheme` selects a (bond-preserving) QR gauge, anything else a truncated SVD
61- alg_gauge = trscheme isa MatrixAlgebraKit. NoTruncation ? alg_orth :
62- MatrixAlgebraKit. TruncatedAlgorithm (alg_svd, trscheme)
63- if ! isnothing (alg_expand) && ! _truncates (alg_gauge)
64- @warn " DMRG with `alg_expand` but no truncation (`trscheme = notrunc()`): the bond dimension will grow unboundedly each sweep."
92+
93+ if isnothing (alg_gauge) || isnothing (alg_gauge. alg_gauge)
94+ trscheme = something (trscheme, notrunc ()) # enforce trscheme default here
95+ inner_gauge = _build_inner_gauge (trscheme, alg_svd, alg_orth)
96+ alg_gauge = set_alg_gauge (alg_gauge, inner_gauge)
97+ else
98+ isnothing (trscheme) || throw (
99+ ArgumentError (
100+ " `trscheme` was given together with an `alg_gauge` that already carries its own " *
101+ " gauge algorithm (e.g. `DMRG3S(noise, schedule, some_gauge)`); set the truncation " *
102+ " via one or the other, not both."
103+ )
104+ )
105+ end
106+
107+ if (! isnothing (alg_expand) || _expands (alg_gauge)) && ! _truncates (alg_gauge)
108+ @warn " DMRG with a bond-expanding `alg_expand` and/or `alg_gauge` but no truncation (`trscheme = notrunc()`): the bond dimension will grow unboundedly each sweep."
65109 end
66110 return DMRG (tol, maxiter, verbosity, alg_eigsolve′, finalize, alg_expand, alg_gauge)
67111end
@@ -71,7 +115,7 @@ function local_update!(
71115 site, direction,
72116 ψ, O, alg:: DMRG , envs,
73117 ϵ_global, ϵ_trunc, decay_rate,
74- timeroutput
118+ iter, timeroutput
75119 )
76120 ϵ_local = calc_galerkin (site, ψ, O, ψ, envs)
77121
@@ -87,8 +131,10 @@ function local_update!(
87131 fixedpoint (H_effective, ac_old, :SR , alg_eigsolve)
88132 end
89133
134+ alg_gauge = _update_alg_gauge (alg. alg_gauge, iter, ϵ_global)
135+
90136 # 3. gauge
91- ψ, ϵ_trunc = @timeit timeroutput " gauge" gauge! (ψ, site, direction, AC′, alg . alg_gauge; normalize = true )
137+ ψ, ϵ_trunc = @timeit timeroutput " gauge" gauge! (ψ, site, direction, O, envs, AC′, alg_gauge; normalize = true )
92138
93139 # 4. bookkeeping: measured contraction factor per matvec, kept a strict contraction in (0, 1)
94140 decay_rate = clamp ((first (info. normres) / ϵ_local)^ (1 / max (1 , info. numops)), 1.0e-3 , 0.999 )
@@ -145,7 +191,7 @@ function local_update!(
145191 pos, direction,
146192 ψ, O, alg:: DMRG2 , envs,
147193 ϵ_global, ϵ_trunc, decay_rate,
148- timeroutput
194+ iter, timeroutput
149195 )
150196 Heff = @timeit timeroutput " AC2_hamiltonian" AC2_hamiltonian (pos, ψ, O, ψ, envs)
151197
@@ -162,9 +208,11 @@ function local_update!(
162208 (newA2center, info)
163209 end
164210
211+ alg_gauge = _update_alg_gauge (alg. alg_gauge, iter, ϵ_global)
212+
165213 # 2. gauge: truncated SVD split back into single-site tensors and install;
166214 # the discarded weight is the truncation error
167- ψ, ϵ_trunc = @timeit timeroutput " gauge" gauge2! (ψ, pos, direction, newA2center, alg . alg_gauge; normalize = true )
215+ ψ, ϵ_trunc = @timeit timeroutput " gauge" gauge2! (ψ, pos, direction, O, envs, newA2center, alg_gauge; normalize = true )
168216
169217 # 3. bookkeeping: measured contraction factor per matvec, kept a strict contraction in (0, 1)
170218 decay_rate = clamp ((first (info. normres) / ϵ_local)^ (1 / max (1 , info. numops)), 1.0e-3 , 0.999 )
@@ -184,6 +232,8 @@ _num_updates(::DMRG2, ψ) = length(ψ) - 1
184232_sweep_ranges (:: DMRG , ψ) = (1 : (length (ψ) - 1 ), length (ψ): - 1 : 2 )
185233_sweep_ranges (:: DMRG2 , ψ) = (1 : (length (ψ) - 1 ), (length (ψ) - 2 ): - 1 : 1 )
186234
235+ inner_alg_gauge (alg:: Union{DMRG, DMRG2} ) = alg_gauge (alg. alg_gauge)
236+
187237function find_groundstate! (
188238 ψ:: AbstractFiniteMPS , H, alg:: Union{DMRG, DMRG2} , envs = environments (ψ, H, ψ)
189239 )
@@ -211,7 +261,7 @@ function find_groundstate!(
211261 pos, Val (:right ),
212262 ψ, H, alg, envs,
213263 ϵ_global, ϵ_truncs[pos], decay_rates[pos],
214- timeroutput
264+ iter, timeroutput
215265 )
216266 ϵ_global = maximum (ϵ_locals)
217267 end
@@ -223,7 +273,7 @@ function find_groundstate!(
223273 pos, Val (:left ),
224274 ψ, H, alg, envs,
225275 ϵ_global, ϵ_truncs[pos], decay_rates[pos],
226- timeroutput
276+ iter, timeroutput
227277 )
228278 ϵ_global = maximum (ϵ_locals)
229279 end
0 commit comments