-
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.
- Loading branch information
Showing
5 changed files
with
42 additions
and
137 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
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 |
---|---|---|
@@ -1,50 +1,41 @@ | ||
using ITensors | ||
using ITensorTDVP | ||
using Test | ||
using Random | ||
|
||
@testset "linsolve with conserve_qns=$conserve_qns and eltype=$eltype" for conserve_qns in | ||
(false, true), | ||
eltype in (Float32, Float64, ComplexF32, ComplexF64) | ||
@eval module $(gensym()) | ||
using ITensors: ITensors, MPO, OpSum, apply, randomMPS, siteinds | ||
using ITensorTDVP: ITensorTDVP, dmrg | ||
using KrylovKit: linsolve | ||
using LinearAlgebra: norm | ||
using Test: @test, @testset | ||
using Random: Random | ||
@testset "linsolve (eltype=$elt, conserve_qns=$conserve_qns)" for elt in ( | ||
Float32, Float64, Complex{Float32}, Complex{Float64} | ||
), | ||
conserve_qns in [false, true] | ||
|
||
N = 6 | ||
s = siteinds("S=1/2", N; conserve_qns) | ||
|
||
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 | ||
H = ITensors.convert_leaf_eltype(eltype, MPO(os, s)) | ||
|
||
H = ITensors.convert_leaf_eltype(elt, MPO(os, s)) | ||
state = [isodd(n) ? "Up" : "Dn" for n in 1:N] | ||
|
||
Random.seed!(1234) | ||
x_c = randomMPS(eltype, s, state; linkdims=2) | ||
e, x_c = dmrg(H, x_c; nsweeps=10, cutoff=1e-6, maxdim=20, outputlevel=0) | ||
|
||
@test ITensors.scalartype(x_c) == eltype | ||
|
||
x_c = randomMPS(elt, s, state; linkdims=2) | ||
x_c = dmrg(H, x_c; nsweeps=10, cutoff=1e-6, maxdim=20, outputlevel=0) | ||
@test ITensors.scalartype(x_c) == elt | ||
# Compute `b = H * x_c` | ||
b = apply(H, x_c; cutoff=1e-8) | ||
|
||
@test ITensors.scalartype(b) == eltype | ||
|
||
@test ITensors.scalartype(b) == elt | ||
# Starting guess | ||
x0 = x_c + eltype(0.05) * randomMPS(eltype, s, state; linkdims=2) | ||
|
||
@test ITensors.scalartype(x0) == eltype | ||
|
||
x0 = x_c + elt(0.05) * randomMPS(elt, s, state; linkdims=2) | ||
@test ITensors.scalartype(x0) == elt | ||
nsweeps = 10 | ||
cutoff = 1e-5 | ||
maxdim = 20 | ||
solver_kwargs = (; tol=1e-4, maxiter=20, krylovdim=30, ishermitian=true) | ||
x = linsolve(H, b, x0; nsweeps, cutoff, maxdim, solver_kwargs) | ||
|
||
@test ITensors.scalartype(x) == eltype | ||
|
||
@test ITensors.scalartype(x) == elt | ||
@test norm(x - x_c) < 1e-2 | ||
end | ||
|
||
nothing | ||
end |
Oops, something went wrong.