Skip to content

Commit e5047fc

Browse files
committed
Rename tdvp to time_evolve. Add tests.
1 parent c081dfb commit e5047fc

File tree

2 files changed

+88
-12
lines changed

2 files changed

+88
-12
lines changed

src/solvers/applyexp.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ import ConstructionBase: setproperties
77
current_time::Number = 0.0
88
end
99

10-
ITensorNetworks.state(tdvp::ApplyExpProblem) = tdvp.state
11-
operator(tdvp::ApplyExpProblem) = tdvp.operator
12-
current_time(tdvp::ApplyExpProblem) = tdvp.current_time
10+
ITensorNetworks.state(A::ApplyExpProblem) = A.state
11+
operator(A::ApplyExpProblem) = A.operator
12+
current_time(A::ApplyExpProblem) = A.current_time
1313

1414
function region_plan(tdvp::ApplyExpProblem; nsites, time_step, sweep_kwargs...)
1515
return tdvp_regions(state(tdvp), time_step; nsites, sweep_kwargs...)
1616
end
1717

1818
function updater(
19-
T::ApplyExpProblem,
19+
A::ApplyExpProblem,
2020
local_state,
2121
region_iterator;
2222
nsites,
@@ -25,26 +25,26 @@ function updater(
2525
outputlevel,
2626
kws...,
2727
)
28-
local_state, info = solver(x->optimal_map(operator(T), x), time_step, local_state; kws...)
28+
local_state, info = solver(x->optimal_map(operator(A), x), time_step, local_state; kws...)
2929

3030
if nsites==1
3131
curr_reg = current_region(region_iterator)
3232
next_reg = next_region(region_iterator)
3333
if !isnothing(next_reg) && next_reg != curr_reg
34-
next_edge = first(edge_sequence_between_regions(state(T), curr_reg, next_reg))
34+
next_edge = first(edge_sequence_between_regions(state(A), curr_reg, next_reg))
3535
v1, v2 = src(next_edge), dst(next_edge)
36-
psi = copy(state(T))
36+
psi = copy(state(A))
3737
psi[v1], R = qr(local_state, uniqueinds(local_state, psi[v2]))
38-
shifted_operator = position(operator(T), psi, NamedEdge(v1=>v2))
38+
shifted_operator = position(operator(A), psi, NamedEdge(v1=>v2))
3939
R_t, _ = solver(x->optimal_map(shifted_operator, x), -time_step, R; kws...)
4040
local_state = psi[v1]*R_t
4141
end
4242
end
4343

44-
curr_time = current_time(T) + time_step
45-
T = setproperties(T; current_time=curr_time)
44+
curr_time = current_time(A) + time_step
45+
A = setproperties(A; current_time=curr_time)
4646

47-
return T, local_state
47+
return A, local_state
4848
end
4949

5050
function applyexp_sweep_printer(
@@ -90,7 +90,7 @@ end
9090

9191
process_real_times(z) = round(-imag(z); digits=10)
9292

93-
function tdvp(
93+
function time_evolve(
9494
H,
9595
init_state,
9696
time_points;

test/solvers/test_tree_tdvp.jl

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
using Test: @test, @testset
2+
using ITensors
3+
using TensorOperations # Needed to use contraction order finding
4+
import ITensorNetworks: dmrg, maxlinkdim, siteinds, time_evolve, ttn
5+
import Graphs: add_vertex!, add_edge!, vertices
6+
import NamedGraphs: NamedGraph
7+
import ITensorMPS: OpSum
8+
9+
function chain_plus_ancilla(; nchain)
10+
g = NamedGraph()
11+
for j in 1:nchain
12+
add_vertex!(g, j)
13+
end
14+
for j in 1:(nchain - 1)
15+
add_edge!(g, j=>j+1)
16+
end
17+
# Add ancilla vertex near middle of chain
18+
add_vertex!(g, 0)
19+
add_edge!(g, 0=>nchain÷2)
20+
return g
21+
end
22+
23+
@testset "Tree TDVP on chain plus ancilla" begin
24+
outputlevel = 1
25+
26+
N = 10
27+
g = chain_plus_ancilla(; nchain=N)
28+
29+
sites = siteinds("S=1/2", g)
30+
31+
# Make Heisenberg model Hamiltonian
32+
h = OpSum()
33+
for j in 1:(N - 1)
34+
h += "Sz", j, "Sz", j+1
35+
h += 1/2, "S+", j, "S-", j+1
36+
h += 1/2, "S-", j, "S+", j+1
37+
end
38+
H = ttn(h, sites)
39+
40+
# Make initial product state
41+
state = Dict{Int,String}()
42+
for (j, v) in enumerate(vertices(sites))
43+
state[v] = iseven(j) ? "Up" : "Dn"
44+
end
45+
psi0 = ttn(state, sites)
46+
47+
cutoff = 1E-10
48+
maxdim = 100
49+
nsweeps = 5
50+
51+
nsites = 2
52+
trunc = (; cutoff, maxdim)
53+
E, gs_psi = dmrg(H, psi0; inserter_kwargs=(; trunc), nsites, nsweeps, outputlevel)
54+
(outputlevel >= 1) && println("2-site DMRG energy = ", E)
55+
56+
inserter_kwargs=(; trunc)
57+
nsites = 1
58+
tmax = 0.10
59+
time_range = 0.0:0.02:tmax
60+
psi1_t = time_evolve(H, gs_psi, time_range; inserter_kwargs, nsites, outputlevel)
61+
(outputlevel >= 1) && println("Done with $nsites-site TDVP")
62+
63+
@test norm(psi1_t) > 0.999
64+
65+
nsites = 2
66+
psi2_t = time_evolve(H, gs_psi, time_range; inserter_kwargs, nsites, outputlevel)
67+
(outputlevel >= 1) && println("Done with $nsites-site TDVP")
68+
@test norm(psi2_t) > 0.999
69+
70+
@test abs(inner(psi1_t, gs_psi)) > 0.99
71+
@test abs(inner(psi1_t, psi2_t)) > 0.99
72+
73+
# Test that accumulated phase angle is E*tmax
74+
z = inner(psi1_t, gs_psi)
75+
@test abs(atan(imag(z)/real(z)) - E*tmax) < 1E-4
76+
end

0 commit comments

Comments
 (0)