|
| 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