@@ -36,28 +36,39 @@ function find_groundstate!(ψ::AbstractFiniteMPS, H, alg::DMRG, envs = environme
3636 ϵs = map (pos -> calc_galerkin (pos, ψ, H, ψ, envs), 1 : length (ψ))
3737 ϵ = maximum (ϵs)
3838 log = IterLog (" DMRG" )
39+ timeroutput = TimerOutput (" DMRG" )
40+ alg. verbosity > 3 || disable_timer! (timeroutput)
3941
4042 LoggingExtras. withlevel (; alg. verbosity) do
4143 @infov 2 loginit! (log, ϵ, expectation_value (ψ, H, envs))
4244 for iter in 1 : (alg. maxiter)
4345 alg_eigsolve = updatetol (alg. alg_eigsolve, iter, ϵ)
4446
4547 zerovector! (ϵs)
46- for pos in [1 : (length (ψ) - 1 ); length (ψ): - 1 : 2 ]
47- h = AC_hamiltonian (pos, ψ, H, ψ, envs)
48- _, vec = fixedpoint (h, ψ. AC[pos], :SR , alg_eigsolve)
49- ϵs[pos] = max (ϵs[pos], calc_galerkin (pos, ψ, H, ψ, envs))
50- ψ. AC[pos] = vec
48+ @timeit timeroutput " sweep" begin
49+ for pos in [1 : (length (ψ) - 1 ); length (ψ): - 1 : 2 ]
50+ local vec
51+ @timeit timeroutput " AC_eigsolve" begin
52+ h = AC_hamiltonian (pos, ψ, H, ψ, envs)
53+ _, vec = fixedpoint (h, ψ. AC[pos], :SR , alg_eigsolve)
54+ end
55+ ϵs[pos] = max (ϵs[pos], calc_galerkin (pos, ψ, H, ψ, envs))
56+ @timeit timeroutput " AC_update" ψ. AC[pos] = vec
57+ end
5158 end
5259 ϵ = maximum (ϵs)
5360
54- ψ, envs = alg. finalize (iter, ψ, H, envs):: Tuple{typeof(ψ), typeof(envs)}
61+ ψ, envs = @timeit timeroutput " finalize" alg. finalize (
62+ iter, ψ, H, envs
63+ ):: Tuple{typeof(ψ), typeof(envs)}
5564
5665 if ϵ <= alg. tol
66+ @infov 4 timeroutput
5767 @infov 2 logfinish! (log, iter, ϵ, expectation_value (ψ, H, envs))
5868 break
5969 end
6070 if iter == alg. maxiter
71+ @infov 4 timeroutput
6172 @warnv 1 logcancel! (log, iter, ϵ, expectation_value (ψ, H, envs))
6273 else
6374 @infov 3 logiter! (log, iter, ϵ, expectation_value (ψ, H, envs))
@@ -113,50 +124,68 @@ function find_groundstate!(ψ::AbstractFiniteMPS, H, alg::DMRG2, envs = environm
113124 ϵs = map (pos -> calc_galerkin (pos, ψ, H, ψ, envs), 1 : length (ψ))
114125 ϵ = maximum (ϵs)
115126 log = IterLog (" DMRG2" )
127+ timeroutput = TimerOutput (" DMRG2" )
128+ alg. verbosity > 3 || disable_timer! (timeroutput)
116129
117130 LoggingExtras. withlevel (; alg. verbosity) do
118131 for iter in 1 : (alg. maxiter)
119132 alg_eigsolve = updatetol (alg. alg_eigsolve, iter, ϵ)
120133 zerovector! (ϵs)
121134
122- # left to right sweep
123- for pos in 1 : (length (ψ) - 1 )
124- @plansor ac2[- 1 - 2 ; - 3 - 4 ] := ψ. AC[pos][- 1 - 2 ; 1 ] * ψ. AR[pos + 1 ][1 - 4 ; - 3 ]
125- Hac2 = AC2_hamiltonian (pos, ψ, H, ψ, envs)
126- _, newA2center = fixedpoint (Hac2, ac2, :SR , alg_eigsolve)
127-
128- al, c, ar = svd_trunc! (newA2center; trunc = alg. trscheme, alg = alg. alg_svd)
129- normalize! (c)
130- v = @plansor ac2[1 2 ; 3 4 ] * conj (al[1 2 ; 5 ]) * conj (c[5 ; 6 ]) * conj (ar[6 ; 3 4 ])
131- ϵs[pos] = max (ϵs[pos], abs (1 - abs (v)))
132-
133- ψ. AC[pos] = (al, complex (c))
134- ψ. AC[pos + 1 ] = (complex (c), _transpose_front (ar))
135- end
136-
137- # right to left sweep
138- for pos in (length (ψ) - 2 ): - 1 : 1
139- @plansor ac2[- 1 - 2 ; - 3 - 4 ] := ψ. AL[pos][- 1 - 2 ; 1 ] * ψ. AC[pos + 1 ][1 - 4 ; - 3 ]
140- Hac2 = AC2_hamiltonian (pos, ψ, H, ψ, envs)
141- _, newA2center = fixedpoint (Hac2, ac2, :SR , alg_eigsolve)
142-
143- al, c, ar = svd_trunc! (newA2center; trunc = alg. trscheme, alg = alg. alg_svd)
144- normalize! (c)
145- v = @plansor ac2[1 2 ; 3 4 ] * conj (al[1 2 ; 5 ]) * conj (c[5 ; 6 ]) * conj (ar[6 ; 3 4 ])
146- ϵs[pos] = max (ϵs[pos], abs (1 - abs (v)))
147-
148- ψ. AC[pos + 1 ] = (complex (c), _transpose_front (ar))
149- ψ. AC[pos] = (al, complex (c))
135+ @timeit timeroutput " sweep" begin
136+ # left to right sweep
137+ for pos in 1 : (length (ψ) - 1 )
138+ local ac2, newA2center, al, c, ar
139+ @timeit timeroutput " AC2_eigsolve" begin
140+ @plansor ac2[- 1 - 2 ; - 3 - 4 ] := ψ. AC[pos][- 1 - 2 ; 1 ] * ψ. AR[pos + 1 ][1 - 4 ; - 3 ]
141+ Hac2 = AC2_hamiltonian (pos, ψ, H, ψ, envs)
142+ _, newA2center = fixedpoint (Hac2, ac2, :SR , alg_eigsolve)
143+ end
144+ @timeit timeroutput " svd_trunc" begin
145+ al, c, ar = svd_trunc! (newA2center; trunc = alg. trscheme, alg = alg. alg_svd)
146+ normalize! (c)
147+ v = @plansor ac2[1 2 ; 3 4 ] * conj (al[1 2 ; 5 ]) * conj (c[5 ; 6 ]) * conj (ar[6 ; 3 4 ])
148+ ϵs[pos] = max (ϵs[pos], abs (1 - abs (v)))
149+ end
150+ @timeit timeroutput " update_AC" begin
151+ ψ. AC[pos] = (al, complex (c))
152+ ψ. AC[pos + 1 ] = (complex (c), _transpose_front (ar))
153+ end
154+ end
155+
156+ # right to left sweep
157+ for pos in (length (ψ) - 2 ): - 1 : 1
158+ local ac2, newA2center, al, c, ar
159+ @timeit timeroutput " AC2_eigsolve" begin
160+ @plansor ac2[- 1 - 2 ; - 3 - 4 ] := ψ. AL[pos][- 1 - 2 ; 1 ] * ψ. AC[pos + 1 ][1 - 4 ; - 3 ]
161+ Hac2 = AC2_hamiltonian (pos, ψ, H, ψ, envs)
162+ _, newA2center = fixedpoint (Hac2, ac2, :SR , alg_eigsolve)
163+ end
164+ @timeit timeroutput " svd_trunc" begin
165+ al, c, ar = svd_trunc! (newA2center; trunc = alg. trscheme, alg = alg. alg_svd)
166+ normalize! (c)
167+ v = @plansor ac2[1 2 ; 3 4 ] * conj (al[1 2 ; 5 ]) * conj (c[5 ; 6 ]) * conj (ar[6 ; 3 4 ])
168+ ϵs[pos] = max (ϵs[pos], abs (1 - abs (v)))
169+ end
170+ @timeit timeroutput " update_AC" begin
171+ ψ. AC[pos + 1 ] = (complex (c), _transpose_front (ar))
172+ ψ. AC[pos] = (al, complex (c))
173+ end
174+ end
150175 end
151176
152177 ϵ = maximum (ϵs)
153- ψ, envs = alg. finalize (iter, ψ, H, envs):: Tuple{typeof(ψ), typeof(envs)}
178+ ψ, envs = @timeit timeroutput " finalize" alg. finalize (
179+ iter, ψ, H, envs
180+ ):: Tuple{typeof(ψ), typeof(envs)}
154181
155182 if ϵ <= alg. tol
183+ @infov 4 timeroutput
156184 @infov 2 logfinish! (log, iter, ϵ, expectation_value (ψ, H, envs))
157185 break
158186 end
159187 if iter == alg. maxiter
188+ @infov 4 timeroutput
160189 @warnv 1 logcancel! (log, iter, ϵ, expectation_value (ψ, H, envs))
161190 else
162191 @infov 3 logiter! (log, iter, ϵ, expectation_value (ψ, H, envs))
0 commit comments