Skip to content

Commit

Permalink
Refactoring FU ALS cost function
Browse files Browse the repository at this point in the history
  • Loading branch information
Yue-Zhengyuan committed Dec 25, 2024
1 parent 70c51b5 commit 653fbf4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
27 changes: 13 additions & 14 deletions src/algorithms/time_evolution/fu_optimize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -179,21 +179,19 @@ end
"""
Calculate the cost function
```
f(a,b) = | |Psi(a,b)> - |Psi(a2,b2)> |^2
= <Psi(a,b)|Psi(a,b)> + <Psi(a2,b2)|Psi(a2,b2)>
- 2 Re<Psi(a,b)|Psi(a2,b2)>
f(a,b) = | |Psi(a1,b1)> - |Psi(a2,b2)> |^2
= <Psi(a1,b1)|Psi(a1,b1)> + <Psi(a2,b2)|Psi(a2,b2)>
- 2 Re<Psi(a1,b1)|Psi(a2,b2)>
```
"""
function cost_func(

Check warning on line 187 in src/algorithms/time_evolution/fu_optimize.jl

View check run for this annotation

Codecov / codecov/patch

src/algorithms/time_evolution/fu_optimize.jl#L187

Added line #L187 was not covered by tests
env::AbstractTensorMap,
aR::AbstractTensorMap,
bL::AbstractTensorMap,
aR1bL1::AbstractTensorMap,
aR2bL2::AbstractTensorMap,
)
aRbL = _combine_aRbL(aR, bL)
t1 = inner_prod(env, aRbL, aRbL)
t1 = inner_prod(env, aR1bL1, aR1bL1)
t2 = inner_prod(env, aR2bL2, aR2bL2)
t3 = inner_prod(env, aRbL, aR2bL2)
t3 = inner_prod(env, aR1bL1, aR2bL2)
return real(t1) + real(t2) - 2 * real(t3)

Check warning on line 195 in src/algorithms/time_evolution/fu_optimize.jl

View check run for this annotation

Codecov / codecov/patch

src/algorithms/time_evolution/fu_optimize.jl#L192-L195

Added lines #L192 - L195 were not covered by tests
end

Expand Down Expand Up @@ -223,9 +221,8 @@ between two evolution steps
```
"""
function local_fidelity(

Check warning on line 223 in src/algorithms/time_evolution/fu_optimize.jl

View check run for this annotation

Codecov / codecov/patch

src/algorithms/time_evolution/fu_optimize.jl#L223

Added line #L223 was not covered by tests
aR1::AbstractTensorMap, bL1::AbstractTensorMap, aR2bL2::AbstractTensorMap
aR1bL1::AbstractTensorMap, aR2bL2::AbstractTensorMap
)
aR1bL1 = _combine_aRbL(aR1, bL1)
b12 = inner_prod_local(aR1bL1, aR2bL2)
b11 = inner_prod_local(aR1bL1, aR1bL1)
b22 = inner_prod_local(aR2bL2, aR2bL2)
Expand Down Expand Up @@ -279,8 +276,9 @@ function fu_optimize(
@debug @sprintf("%-6s%12s%12s%12s %10s\n", "Step", "Cost", "ϵ_d", "ϵ_ab", "Time/s")
aR, bL = deepcopy(aR0), deepcopy(bL0)
time0 = time()
cost00 = cost_func(env, aR, bL, aR2bL2)
fid00 = local_fidelity(aR, bL, aR2bL2)
aRbL = _combine_aRbL(aR, bL)
cost00 = cost_func(env, aRbL, aR2bL2)
fid00 = local_fidelity(aRbL, aR2bL2)
cost0, fid0 = cost00, fid00

Check warning on line 282 in src/algorithms/time_evolution/fu_optimize.jl

View check run for this annotation

Codecov / codecov/patch

src/algorithms/time_evolution/fu_optimize.jl#L275-L282

Added lines #L275 - L282 were not covered by tests
# no need to further optimize
if abs(cost0) < 5e-15
Expand All @@ -298,8 +296,9 @@ function fu_optimize(
Rb = tensor_Rb(env, aR)
Sb = tensor_Sb(env, aR, aR2bL2)
bL, info_b = solve_ab(Rb, Sb, bL)
cost = cost_func(env, aR, bL, aR2bL2)
fid = local_fidelity(aR, bL, aR2bL2)
aRbL = _combine_aRbL(aR, bL)
cost = cost_func(env, aRbL, aR2bL2)
fid = local_fidelity(aRbL, aR2bL2)
diff_d = abs(cost - cost0) / cost00
diff_ab = abs(fid - fid0) / fid00
time1 = time()
Expand Down
2 changes: 1 addition & 1 deletion src/algorithms/time_evolution/fullupdate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ function update_column!(
costs[row] = cost
aR /= norm(aR, Inf)
bL /= norm(bL, Inf)
localfid += local_fidelity(aR, bL, _combine_aRbL(aR0, bL0))
localfid += local_fidelity(_combine_aRbL(aR, bL), _combine_aRbL(aR0, bL0))

Check warning on line 125 in src/algorithms/time_evolution/fullupdate.jl

View check run for this annotation

Codecov / codecov/patch

src/algorithms/time_evolution/fullupdate.jl#L121-L125

Added lines #L121 - L125 were not covered by tests
#= update and normalize peps, ms
-2 -1 -1 -2
Expand Down

0 comments on commit 653fbf4

Please sign in to comment.