From 8d1b295da922292dc72cf72f0294e09dd3048e92 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Thu, 16 May 2024 11:14:34 -0400 Subject: [PATCH] Use StableRNGs in tests --- test/Project.toml | 1 + test/test_expand.jl | 16 ++++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/test/Project.toml b/test/Project.toml index c03e08e..7e322e9 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -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" diff --git a/test/test_expand.jl b/test/test_expand.jl index 622f84f..34d8072 100644 --- a/test/test_expand.jl +++ b/test/test_expand.jl @@ -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 @@ -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) @@ -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; @@ -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