Skip to content

Commit 0bb73a3

Browse files
authored
Refactor derivative names (#276)
* Remove unused file * Remove partialpartial * Add `site_derivative` * Fixup docstrings * rename MPO derivative structs * rename JordanMPO derivative structs * update comment * Rename projection operators * rename `**_proj` functions * Add ProjectionOperator tests * Fix proper normalization for projectionoperator expval * Remove `∂_` functions * Remove unused `site_derivative` * Consistently use `CartesianIndex` * Condense a bunch of boilerplate * Small fixes * Fix typo * formatter
1 parent 6ca0df2 commit 0bb73a3

File tree

23 files changed

+323
-348
lines changed

23 files changed

+323
-348
lines changed

src/algorithms/ED.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function exact_diagonalization(H::FiniteMPOHamiltonian;
7272
# optimize the middle site
7373
# Because the MPS is full rank - this is equivalent to the full Hamiltonian
7474
AC₀ = state.AC[middle_site]
75-
H_ac = ∂∂AC(middle_site, state, H, envs)
75+
H_ac = AC_hamiltonian(middle_site, state, H, state, envs)
7676
vals, vecs, convhist = eigsolve(H_ac, AC₀, num, which, alg)
7777

7878
# repack eigenstates

src/algorithms/approximate/fvomps.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function approximate!(ψ::AbstractFiniteMPS, Oϕ, alg::DMRG2,
88
for iter in 1:(alg.maxiter)
99
ϵ = 0.0
1010
for pos in [1:(length(ψ) - 1); (length(ψ) - 2):-1:1]
11-
AC2′ = ac2_proj(pos, ψ, Oϕ, envs)
11+
AC2′ = AC2_projection(pos, ψ, Oϕ, envs)
1212
al, c, ar, = tsvd!(AC2′; trunc=alg.trscheme)
1313

1414
AC2 = ψ.AC[pos] * _transpose_tail.AR[pos + 1])
@@ -45,7 +45,7 @@ function approximate!(ψ::AbstractFiniteMPS, Oϕ, alg::DMRG, envs=environments(
4545
for iter in 1:(alg.maxiter)
4646
ϵ = 0.0
4747
for pos in [1:(length(ψ) - 1); length(ψ):-1:2]
48-
AC′ = ac_proj(pos, ψ, Oϕ, envs)
48+
AC′ = AC_projection(pos, ψ, Oϕ, envs)
4949
AC = ψ.AC[pos]
5050
ϵ = max(ϵ, norm(AC′ - AC) / norm(AC′))
5151

src/algorithms/approximate/idmrg.jl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ function approximate!(ψ::MultilineMPS, toapprox::Tuple{<:MultilineMPO,<:Multili
1212
# left to right sweep
1313
for col in 1:size(ψ, 2)
1414
for row in 1:size(ψ, 1)
15-
ψ.AC[row + 1, col] = ac_proj(row, col, ψ, toapprox, envs)
15+
ψ.AC[row + 1, col] = AC_projection(CartesianIndex(row, col), ψ,
16+
toapprox, envs)
1617
normalize!.AC[row + 1, col])
1718
ψ.AL[row + 1, col], ψ.C[row + 1, col] = leftorth!.AC[row + 1, col])
1819
end
@@ -22,7 +23,8 @@ function approximate!(ψ::MultilineMPS, toapprox::Tuple{<:MultilineMPO,<:Multili
2223
# right to left sweep
2324
for col in size(ψ, 2):-1:1
2425
for row in 1:size(ψ, 1)
25-
ψ.AC[row + 1, col] = ac_proj(row, col, ψ, toapprox, envs)
26+
ψ.AC[row + 1, col] = AC_projection(CartesianIndex(row, col),
27+
ψ, toapprox, envs)
2628
normalize!.AC[row + 1, col])
2729
ψ.C[row + 1, col - 1], temp = rightorth!(_transpose_tail.AC[row + 1,
2830
col]))
@@ -71,7 +73,7 @@ function approximate!(ψ::MultilineMPS, toapprox::Tuple{<:MultilineMPO,<:Multili
7173
# sweep from left to right
7274
for col in 1:size(ψ, 2)
7375
for row in 1:size(ψ, 1)
74-
AC2′ = ac2_proj(row, col, ψ, toapprox, envs)
76+
AC2′ = AC2_projection(CartesianIndex(row, col), ψ, toapprox, envs)
7577
al, c, ar, = tsvd!(AC2′; trunc=alg.trscheme, alg=alg.alg_svd)
7678
normalize!(c)
7779

@@ -88,9 +90,9 @@ function approximate!(ψ::MultilineMPS, toapprox::Tuple{<:MultilineMPO,<:Multili
8890
# sweep from right to left
8991
for col in (size(ψ, 2) - 1):-1:0
9092
for row in 1:size(ψ, 1)
91-
# TODO: also write this as ac2_proj?
93+
# TODO: also write this as AC2_projection?
9294
AC2 = ϕ.AL[row, col] * _transpose_tail.AC[row, col + 1])
93-
AC2′ = ∂∂AC2(row, col, ψ, O, envs) * AC2
95+
AC2′ = AC2_hamiltonian(CartesianIndex(row, col), ψ, O, ϕ, envs) * AC2
9496
al, c, ar, = tsvd!(AC2′; trunc=alg.trscheme, alg=alg.alg_svd)
9597
normalize!(c)
9698

src/algorithms/approximate/vomps.jl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ function Base.iterate(it::IterativeSolver{<:VOMPS}, state::VOMPSState{<:Any,<:Tu
5555
return (mps, envs, ϵ), it.state
5656
end
5757

58-
# TODO: ac_proj and c_proj should be rewritten to also be simply ∂AC/∂C functions
59-
# once these have better support for different above/below mps
6058
function localupdate_step!(::IterativeSolver{<:VOMPS}, state::VOMPSState{<:Any,<:Tuple},
6159
::SerialScheduler)
6260
alg_orth = QRpos()
@@ -65,9 +63,11 @@ function localupdate_step!(::IterativeSolver{<:VOMPS}, state::VOMPSState{<:Any,<
6563
dst_ACs = state.mps isa Multiline ? eachcol(ACs) : ACs
6664

6765
foreach(eachsite) do site
68-
AC = circshift([ac_proj(row, site, state.mps, state.operator, state.envs)
66+
AC = circshift([AC_projection(CartesianIndex(row, site), state.mps, state.operator,
67+
state.envs)
6968
for row in 1:size(state.mps, 1)], 1)
70-
C = circshift([c_proj(row, site, state.mps, state.operator, state.envs)
69+
C = circshift([C_projection(CartesianIndex(row, site), state.mps, state.operator,
70+
state.envs)
7171
for row in 1:size(state.mps, 1)], 1)
7272
dst_ACs[site] = regauge!(AC, C; alg=alg_orth)
7373
return nothing
@@ -87,11 +87,13 @@ function localupdate_step!(::IterativeSolver{<:VOMPS}, state::VOMPSState{<:Any,<
8787
local AC, C
8888
@sync begin
8989
Threads.@spawn begin
90-
AC = circshift([ac_proj(row, site, state.mps, state.operator, state.envs)
90+
AC = circshift([AC_projection(CartesianIndex(row, site), state.mps,
91+
state.operator, state.envs)
9192
for row in 1:size(state.mps, 1)], 1)
9293
end
9394
Threads.@spawn begin
94-
C = circshift([c_proj(row, site, state.mps, state.operator, state.envs)
95+
C = circshift([C_projection(CartesianIndex(row, site), state.mps,
96+
state.operator, state.envs)
9597
for row in 1:size(state.mps, 1)], 1)
9698
end
9799
end

src/algorithms/changebonds/optimalexpand.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function changebonds(ψ::InfiniteMPS, H::InfiniteMPOHamiltonian, alg::OptimalExp
2525
for i in 1:length(ψ)
2626
# determine optimal expansion spaces around bond i
2727
AC2 = _transpose_front.AC[i]) * _transpose_tail.AR[i + 1])
28-
AC2 = ∂∂AC2(i, ψ, H, envs) * AC2
28+
AC2 = AC2_hamiltonian(i, ψ, H, ψ, envs) * AC2
2929

3030
# Use the nullspaces and SVD decomposition to determine the optimal expansion space
3131
VL = leftnull.AL[i])
@@ -51,7 +51,7 @@ function changebonds(ψ::MultilineMPS, H, alg::OptimalExpand, envs=environments(
5151
# determine optimal expansion spaces around bond i
5252
for i in 1:size(ψ, 1), j in 1:size(ψ, 2)
5353
AC2 = _transpose_front.AC[i - 1, j]) * _transpose_tail.AR[i - 1, j + 1])
54-
AC2 = ∂∂AC2(i - 1, j, ψ, H, envs) * AC2
54+
AC2 = AC2_hamiltonian(CartesianIndex(i - 1, j), ψ, H, ψ, envs) * AC2
5555

5656
# Use the nullspaces and SVD decomposition to determine the optimal expansion space
5757
VL = leftnull.AL[i, j])
@@ -80,7 +80,7 @@ function changebonds!(ψ::AbstractFiniteMPS, H, alg::OptimalExpand, envs=environ
8080

8181
for i in 1:(length(ψ) - 1)
8282
AC2 = _transpose_front.AC[i]) * _transpose_tail.AR[i + 1])
83-
AC2 = ∂∂AC2(i, ψ, H, envs) * AC2
83+
AC2 = AC2_hamiltonian(i, ψ, H, ψ, envs) * AC2
8484

8585
#Calculate nullspaces for left and right
8686
NL = leftnull.AC[i])

src/algorithms/changebonds/vumpssvd.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ function changebonds_n(state::InfiniteMPS, H, alg::VUMPSSvdCut, envs=environment
5252
for loc in 1:length(state)
5353
@plansor AC2[-1 -2; -3 -4] := state.AC[loc][-1 -2; 1] * state.AR[loc + 1][1 -4; -3]
5454

55-
h_ac2 = ∂∂AC2(loc, state, H, envs)
56-
_, nAC2 = fixedpoint(h_ac2, AC2, :SR, alg.alg_eigsolve)
55+
Hac2 = AC2_hamiltonian(loc, state, H, state, envs)
56+
_, nAC2 = fixedpoint(Hac2, AC2, :SR, alg.alg_eigsolve)
5757

58-
h_c = ∂∂C(loc + 1, state, H, envs)
59-
_, nC2 = fixedpoint(h_c, state.C[loc + 1], :SR, alg.alg_eigsolve)
58+
Hc = C_hamiltonian(loc + 1, state, H, state, envs)
59+
_, nC2 = fixedpoint(Hc, state.C[loc + 1], :SR, alg.alg_eigsolve)
6060

6161
#svd ac2, get new AL1 and S,V ---> AC
6262
AL1, S, V, eps = tsvd!(nAC2; trunc=alg.trscheme, alg=alg.alg_svd)

0 commit comments

Comments
 (0)