Skip to content

Commit

Permalink
Use StableRNGs in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mtfishman committed May 16, 2024
1 parent e9fa36a commit 8d1b295
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ Observers = "338f10d5-c7f1-4033-a7d1-f9dec39bcaa0"
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
16 changes: 8 additions & 8 deletions test/test_expand.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ using ITensors: scalartype
using ITensors.ITensorMPS: OpSum, MPO, MPS, inner, linkdims, maxlinkdim, randomMPS, siteinds
using ITensorTDVP: dmrg, expand, tdvp
using LinearAlgebra: normalize
using Random: Random
using StableRNGs: StableRNG
using Test: @test, @testset
const elts = (Float32, Float64, Complex{Float32}, Complex{Float64})
@testset "expand (eltype=$elt)" for elt in elts
Expand All @@ -13,9 +13,9 @@ const elts = (Float32, Float64, Complex{Float32}, Complex{Float64})
)
n = 6
s = siteinds("S=1/2", n; conserve_qns)
Random.seed!(1234)
state = randomMPS(elt, s, j -> isodd(j) ? "" : ""; linkdims=4)
reference = randomMPS(elt, s, j -> isodd(j) ? "" : ""; linkdims=2)
rng = StableRNG(1234)
state = randomMPS(rng, elt, s, j -> isodd(j) ? "" : ""; linkdims=4)
reference = randomMPS(rng, elt, s, j -> isodd(j) ? "" : ""; linkdims=2)
state_expanded = expand(state, [reference]; alg="orthogonalize")
@test scalartype(state_expanded) === elt
@test inner(state_expanded, state) inner(state, state)
Expand Down Expand Up @@ -57,8 +57,8 @@ const elts = (Float32, Float64, Complex{Float32}, Complex{Float64})
opsum += "Sz", j, "Sz", j + 2
end
operator = MPO(elt, opsum, s)
Random.seed!(1234)
init = randomMPS(elt, s; linkdims=30)
rng = StableRNG(1234)
init = randomMPS(rng, elt, s; linkdims=30)
reference_energy, reference_state = dmrg(
operator,
init;
Expand All @@ -67,8 +67,8 @@ const elts = (Float32, Float64, Complex{Float32}, Complex{Float64})
cutoff=((eps(real(elt)))),
noise=((eps(real(elt)))),
)
Random.seed!(1234)
state = randomMPS(elt, s)
rng = StableRNG(1234)
state = randomMPS(rng, elt, s)
nexpansions = 10
tau = elt(0.5)
for step in 1:nexpansions
Expand Down

0 comments on commit 8d1b295

Please sign in to comment.