Skip to content

Commit

Permalink
add test to multi-thread
Browse files Browse the repository at this point in the history
  • Loading branch information
EigenSolver committed May 27, 2024
1 parent 0d320e4 commit 520cd55
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ include("testintegration.jl")
include("testfidelity.jl")
include("teststochastics.jl")
include("testspectrum.jl")
include("testthreads.jl")
28 changes: 28 additions & 0 deletions test/testthreads.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Test
using SpinShuttling
using DelimitedFiles
# using UnicodePlots
# using ProgressMeter

@testset "test multithreading" begin
T=4; L=10; σ = sqrt(2) / 20; N=501; κₜ=1;κₓ=1;

B=OrnsteinUhlenbeckField(0,[κₜ,κₓ],σ)
model=OneSpinModel(T,L,N,B)

# save the original Σ to text file
if Threads.nthreads() > 1
writedlm("test/cache.csv", model.R.Σ)
else
# read the original Σ from text file
Σ = readdlm("test/cache.csv")
# test the original Σ is the same as the one in the model
@test isapprox(Σ, model.R.Σ, rtol=1e-10)
# delete the cache file
rm("test/cache.csv", force=true)
end

M = 100000;
F=sampling(model, fidelity, M)
println(F)
end

0 comments on commit 520cd55

Please sign in to comment.