11@eval module $ (gensym())
2- using ITensors: ITensors, MPO, OpSum, apply, randomMPS, siteinds
2+ using ITensors: scalartype
3+ using ITensors. ITensorMPS: MPO, OpSum, apply, randomMPS, siteinds
34using ITensorTDVP: ITensorTDVP, dmrg
45using KrylovKit: linsolve
56using LinearAlgebra: norm
7+ using StableRNGs: StableRNG
68using Test: @test, @test_throws, @testset
79using Random: Random
810@testset " linsolve (eltype=$elt , conserve_qns=$conserve_qns )" for elt in (
@@ -18,25 +20,26 @@ using Random: Random
1820 os += 0.5 , " S-" , j, " S+" , j + 1
1921 os += " Sz" , j, " Sz" , j + 1
2022 end
21- H = ITensors . convert_leaf_eltype (elt, MPO( os, s) )
23+ H = MPO (elt, os, s)
2224 state = [isodd(n) ? " Up" : " Dn" for n in 1 : N]
23- Random . seed! (1234 )
24- x_c = randomMPS(elt, s, state; linkdims= 2 )
25+ rng = StableRNG (1234 )
26+ x_c = randomMPS(rng, elt, s, state; linkdims= 2 )
2527 e, x_c = dmrg(H, x_c; nsweeps= 10 , cutoff= 1e-6 , maxdim= 20 , outputlevel= 0 )
26- @test ITensors . scalartype(x_c) == elt
28+ @test scalartype(x_c) == elt
2729 # Compute `b = H * x_c`
2830 b = apply(H, x_c; cutoff= 1e-8 )
29- @test ITensors . scalartype(b) == elt
31+ @test scalartype(b) == elt
3032 # Starting guess
31- x0 = x_c + elt(0.05 ) * randomMPS(elt, s, state; linkdims= 2 )
32- @test ITensors. scalartype(x0) == elt
33+ rng = StableRNG(1234 )
34+ x0 = x_c + elt(0.05 ) * randomMPS(rng, elt, s, state; linkdims= 2 )
35+ @test scalartype(x0) == elt
3336 nsweeps = 10
3437 cutoff = 1e-5
3538 maxdim = 20
3639 updater_kwargs = (; tol= 1e-4 , maxiter= 20 , krylovdim= 30 , ishermitian= true )
3740 @test_throws ErrorException linsolve(H, b, x0; cutoff, maxdim, updater_kwargs)
3841 x = linsolve(H, b, x0; nsweeps, cutoff, maxdim, updater_kwargs)
39- @test ITensors . scalartype(x) == elt
42+ @test scalartype(x) == elt
4043 @test norm(x - x_c) < 1e-2
4144end
4245end
0 commit comments