1+ function check_state (psi:: InfiniteMPS ,pos= - 10 ,dir= 0 )
2+ psibc= MPIHelper. bcast (psi, MPI. COMM_WORLD)
3+ if ! mpi_is_root ()
4+ for typ in [:AL ,:AR ,:C ]
5+ psi_c= getfield (psibc, typ)
6+ psi_l= getfield (psi, typ)
7+ for i in eachindex (psi_c)
8+ pc= psi_c[i]
9+ pl= psi_l[i]
10+ @assert norm (pc- pl)< 1e-10 " Wrong MPS on rank $(mpi_rank ()) for tensor $typ at site $i : norm difference=$(norm (pc- pl)) and dir=$dir pos=$pos "
11+ end
12+ end
13+ end
14+ end
15+
116function MPSKit. _localupdate_sweep_idmrg! (ψ:: AbstractMPS , H:: MPIOperator , envs, alg_eigsolve, :: IDMRG )
17+ E= 0
218 C_old = ψ. C[0 ]
319 # left to right sweep
420 for pos in 1 : length (ψ)
521 h = AC_hamiltonian (pos, ψ, H, ψ, envs)
6- _, ψ. AC[pos] = fixedpoint (h, ψ. AC[pos], :SR , alg_eigsolve)
7- if pos == length (ψ)
8- # AC needed in next sweep
9- ψ. AL[pos], ψ. C[pos] = mpi_execute_on_root_and_bcast (left_orth,ψ. AC[pos])
10- else
11- ψ. AL[pos], ψ. C[pos] = mpi_execute_on_root_and_bcast (left_orth!,ψ. AC[pos])
12- end
22+
23+ ψ. AC[pos] = MPIHelper. bcast (fixedpoint (h, ψ. AC[pos], :SR , alg_eigsolve)[2 ], MPI. COMM_WORLD)
24+ ψ. AL[pos], ψ. C[pos] = mpi_execute_on_root_and_bcast (left_orth,ψ. AC[pos])
25+
1326 transfer_leftenv! (envs, ψ, H, ψ, pos + 1 )
1427 end
1528
1629 # right to left sweep
1730 for pos in length (ψ): - 1 : 1
1831 h = AC_hamiltonian (pos, ψ, H, ψ, envs)
19- _, ψ. AC[pos] = fixedpoint (h, ψ. AC[pos], :SR , alg_eigsolve)
2032
21- ψ. C[pos - 1 ], temp = mpi_right_orth! (_transpose_tail (ψ. AC[pos]; copy = (pos == 1 )))
33+ E, ψ. AC[pos] = fixedpoint (h, ψ. AC[pos], :SR , alg_eigsolve)
34+ ψ. AC[pos] = MPIHelper. bcast (ψ. AC[pos], MPI. COMM_WORLD)
35+ ψ. C[pos - 1 ], temp = mpi_execute_on_root_and_bcast (right_orth!,_transpose_tail (ψ. AC[pos]; copy = (pos == 1 )))
2236 ψ. AR[pos] = _transpose_front (temp)
2337
2438 transfer_rightenv! (envs, ψ, H, ψ, pos - 1 )
2539 end
26- return ψ, envs, C_old
40+ return ψ, envs, C_old, E
2741end
2842
2943function MPSKit. _localupdate_sweep_idmrg! (ψ:: AbstractMPS , H:: MPIOperator , envs, alg_eigsolve, alg:: IDMRG2 )
@@ -93,7 +107,7 @@ function MPSKit._localupdate_sweep_idmrg!(ψ::AbstractMPS, H::MPIOperator, envs,
93107 ψ. AR[1 ] = _transpose_front (ψ. C[end ] \ _transpose_tail (ψ. AC[1 ]))
94108 ac2 = AC2 (ψ, 0 ; kind = :ACAR )
95109 h_ac2 = AC2_hamiltonian (0 , ψ, H, ψ, envs)
96- _ , ac2′ = fixedpoint (h_ac2, ac2, :SR , alg_eigsolve)
110+ E , ac2′ = fixedpoint (h_ac2, ac2, :SR , alg_eigsolve)
97111 al, c, ar = mpi_execute_on_root_and_bcast (svd_trunc!, ac2′; trunc = alg. trscheme, alg = alg. alg_svd)
98112 normalize! (c)
99113
@@ -107,5 +121,5 @@ function MPSKit._localupdate_sweep_idmrg!(ψ::AbstractMPS, H::MPIOperator, envs,
107121 transfer_leftenv! (envs, ψ, H, ψ, 1 )
108122 transfer_rightenv! (envs, ψ, H, ψ, 0 )
109123
110- return ψ, envs, C_old
124+ return ψ, envs, C_old, E
111125end
0 commit comments