-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new
Observer
that gets updated after each time step (#22)
- Loading branch information
Showing
6 changed files
with
141 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using ITensors | ||
using ITensorTDVP | ||
|
||
include("05_utils.jl") | ||
|
||
function heisenberg(N) | ||
os = OpSum() | ||
for j in 1:(N - 1) | ||
os += 0.5, "S+", j, "S-", j + 1 | ||
os += 0.5, "S-", j, "S+", j + 1 | ||
os += "Sz", j, "Sz", j + 1 | ||
end | ||
return os | ||
end | ||
|
||
N = 10 | ||
cutoff = 1e-12 | ||
outputlevel = 1 | ||
nsteps = 10 | ||
time_steps = [n ≤ 2 ? -0.2im : -0.1im for n in 1:nsteps] | ||
|
||
obs = Observer("times" => (; current_time) -> current_time, "psis" => (; psi) -> psi) | ||
|
||
s = siteinds("S=1/2", N; conserve_qns=true) | ||
H = MPO(heisenberg(N), s) | ||
|
||
psi0 = MPS(s, n -> isodd(n) ? "Up" : "Dn") | ||
psi = tdvp_nonuniform_timesteps( | ||
ProjMPO(H), psi0; time_steps, cutoff, outputlevel, (step_observer!)=obs | ||
) | ||
|
||
res = results(obs) | ||
times = res["times"] | ||
psis = res["psis"] | ||
|
||
println("\nResults") | ||
println("=======") | ||
print("step = ", 0) | ||
print(", time = ", zero(ComplexF64)) | ||
print(", ⟨Sᶻ⟩ = ", round(expect(psi0, "Sz"; sites=N ÷ 2); digits=3)) | ||
println() | ||
for n in 1:length(times) | ||
print("step = ", n) | ||
print(", time = ", round(times[n]; digits=3)) | ||
print(", ⟨Sᶻ⟩ = ", round(expect(psis[n], "Sz"; sites=N ÷ 2); digits=3)) | ||
println() | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using ITensors | ||
using ITensorTDVP | ||
using Observers | ||
using Printf | ||
|
||
using ITensorTDVP: tdvp_solver, process_sweeps, TDVPOrder | ||
|
||
function tdvp_nonuniform_timesteps( | ||
solver, | ||
PH, | ||
psi::MPS; | ||
time_steps, | ||
reverse_step=true, | ||
time_start=0.0, | ||
order=2, | ||
(step_observer!)=Observer(), | ||
kwargs..., | ||
) | ||
nsweeps = length(time_steps) | ||
maxdim, mindim, cutoff, noise = process_sweeps(; nsweeps, kwargs...) | ||
tdvp_order = TDVPOrder(order, Base.Forward) | ||
current_time = time_start | ||
for sw in 1:nsweeps | ||
sw_time = @elapsed begin | ||
psi, PH, info = tdvp( | ||
tdvp_order, | ||
solver, | ||
PH, | ||
time_steps[sw], | ||
psi; | ||
kwargs..., | ||
current_time, | ||
reverse_step, | ||
sweep=sw, | ||
maxdim=maxdim[sw], | ||
mindim=mindim[sw], | ||
cutoff=cutoff[sw], | ||
noise=noise[sw], | ||
) | ||
end | ||
current_time += time_steps[sw] | ||
|
||
update!(step_observer!; psi, sweep=sw, outputlevel, current_time) | ||
|
||
if outputlevel ≥ 1 | ||
print("After sweep ", sw, ":") | ||
print(" maxlinkdim=", maxlinkdim(psi)) | ||
@printf(" maxerr=%.2E", info.maxtruncerr) | ||
print(" current_time=", round(current_time; digits=3)) | ||
print(" time=", round(sw_time; digits=3)) | ||
println() | ||
flush(stdout) | ||
end | ||
end | ||
return psi | ||
end | ||
|
||
function tdvp_nonuniform_timesteps(H, psi::MPS; kwargs...) | ||
return tdvp_nonuniform_timesteps(tdvp_solver(; kwargs...), H, psi; kwargs...) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
acd15ef
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
acd15ef
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/60668
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: