diff --git a/test/Manifest.toml b/test/Manifest.toml index e962a40..ba86075 100644 --- a/test/Manifest.toml +++ b/test/Manifest.toml @@ -1,8 +1,8 @@ # This file is machine-generated - editing it directly is not advised -julia_version = "1.10.1" +julia_version = "1.10.2" manifest_format = "2.0" -project_hash = "b7d2887a6e0b6afe3c64da83f9f8503f7d6748ea" +project_hash = "2e8f71a970a5211ff0d3acbb9f0479ce789c8a02" [[deps.AbstractFFTs]] deps = ["LinearAlgebra"] @@ -458,6 +458,12 @@ version = "1.4.3" deps = ["Unicode"] uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" +[[deps.ProgressMeter]] +deps = ["Distributed", "Printf"] +git-tree-sha1 = "763a8ceb07833dd51bb9e3bbca372de32c0605ad" +uuid = "92933f4c-e287-5a05-a399-4b506db050ca" +version = "1.10.0" + [[deps.QuadGK]] deps = ["DataStructures", "LinearAlgebra"] git-tree-sha1 = "9b23c31e76e333e6fb4c1595ae6afa74966a729e" diff --git a/test/Project.toml b/test/Project.toml index 0dad22e..0f662b9 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -1,6 +1,7 @@ [deps] FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341" LsqFit = "2fda8390-95c7-5789-9bda-21331edee243" +ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca" Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228" diff --git a/test/runtests.jl b/test/runtests.jl index 2274692..f14e7ad 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,8 +1,9 @@ using Test using SpinShuttling using UnicodePlots +using ProgressMeter -include("testquadrature.jl") +# include("testquadrature.jl") include("testfidelity.jl") -include("teststochastics.jl") -include("testspectrum.jl") +# include("teststochastics.jl") +# include("testspectrum.jl") diff --git a/test/testfidelity.jl b/test/testfidelity.jl index 0208195..f979534 100644 --- a/test/testfidelity.jl +++ b/test/testfidelity.jl @@ -2,85 +2,87 @@ visualize=true ## -@testset begin "test single spin shuttling fidelity" - T=400; L=10; σ = sqrt(2) / 20; M = 20000; N=601; κₜ=1/20;κₓ=1/0.1; - v=L/T; - t=range(0, T, N) - P=hcat(t, v.*t) - B=OrnsteinUhlenbeckField(0,[κₜ,κₓ],σ) +# @testset begin "test single spin shuttling fidelity" +# T=400; L=10; σ = sqrt(2) / 20; M = 20000; N=601; κₜ=1/20;κₓ=1/0.1; +# v=L/T; +# t=range(0, T, N) +# P=hcat(t, v.*t) +# B=OrnsteinUhlenbeckField(0,[κₜ,κₓ],σ) - model=OneSpinModel(T,L,N,B) - # test customize println - println(model) +# model=OneSpinModel(T,L,N,B) +# # test customize println +# println(model) - f1=averagefidelity(model) - f2, f2_err=sampling(model, fidelity, M) - f3=1/2*(1+W(T,L,B)) - @test isapprox(f1, f3,rtol=1e-2) - @test isapprox(f2, f3, rtol=1e-2) - println("NI:", f1) - println("MC:", f2) - println("TH:", f3) -end +# f1=averagefidelity(model) +# f2, f2_err=sampling(model, fidelity, M) +# f3=1/2*(1+W(T,L,B)) +# @test isapprox(f1, f3,rtol=1e-2) +# @test isapprox(f2, f3, rtol=1e-2) +# println("NI:", f1) +# println("MC:", f2) +# println("TH:", f3) +# end -# -@testset begin "test single spin forth-back shuttling fidelity" - T=200; L=10; σ = sqrt(2) / 20; M = 5000; N=501; κₜ=1/20;κₓ=10; - # exponential should be smaller than 100 - B=OrnsteinUhlenbeckField(0,[κₜ,κₓ],σ) +# # +# @testset begin "test single spin forth-back shuttling fidelity" +# T=200; L=10; σ = sqrt(2) / 20; M = 5000; N=501; κₜ=1/20;κₓ=10; +# # exponential should be smaller than 100 +# B=OrnsteinUhlenbeckField(0,[κₜ,κₓ],σ) - if visualize - t=range(1e-2*T,T, 10) - f_mc=[sampling(OneSpinForthBackModel(T,L,N,B), fidelity, M)[1] for T in t] - f_ni=[averagefidelity(OneSpinForthBackModel(T,L,N,B)) for T in t] - f_th=[(1+W(T,L,B,path=:forthback))/2 for T in t] - fig=lineplot(t, f_mc, - xlabel="t", ylabel="F", name="monte-carlo sampling", - # ribbon=@. sqrt(f_mc_err/M) - ) - lineplot!(fig, t, f_ni, name="numerical integration") - lineplot!(fig, t, f_th, name="theoretical fidelity") - display(fig) - end +# if visualize +# t=range(1e-2*T,T, 10) +# f_mc=[sampling(OneSpinForthBackModel(T,L,N,B), fidelity, M)[1] for T in t] +# f_ni=[averagefidelity(OneSpinForthBackModel(T,L,N,B)) for T in t] +# f_th=[(1+W(T,L,B,path=:forthback))/2 for T in t] +# fig=lineplot(t, f_mc, +# xlabel="t", ylabel="F", name="monte-carlo sampling", +# # ribbon=@. sqrt(f_mc_err/M) +# ) +# lineplot!(fig, t, f_ni, name="numerical integration") +# lineplot!(fig, t, f_th, name="theoretical fidelity") +# display(fig) +# end - model=OneSpinForthBackModel(T,L,N,B) - # test customize println - println(model) +# model=OneSpinForthBackModel(T,L,N,B) +# # test customize println +# println(model) - f1=averagefidelity(model) - f2, f2_err=sampling(model, fidelity, M) - f3=1/2*(1+W(T, L, B, path=:forthback)) - @test isapprox(f1, f3,rtol=1e-2) - @test isapprox(f2, f3, rtol=1e-2) - println("NI:", f1) - println("MC:", f2) - println("TH:", f3) -end +# f1=averagefidelity(model) +# f2, f2_err=sampling(model, fidelity, M) +# f3=1/2*(1+W(T, L, B, path=:forthback)) +# @test isapprox(f1, f3,rtol=1e-2) +# @test isapprox(f2, f3, rtol=1e-2) +# println("NI:", f1) +# println("MC:", f2) +# println("TH:", f3) +# end -## -@testset begin "test two spin sequenced shuttling fidelity" - L=10; σ =sqrt(2)/20; M=20000; N=501; T1=200; T0=25*0.05; κₜ=1/20; κₓ=1/0.1; - B=OrnsteinUhlenbeckField(0,[κₜ,κₓ],σ) - model=TwoSpinModel(T0, T1, L, N, B) - if visualize - display(heatmap(collect(model.R.Σ), title="cross covariance matrix, test fig 4")) - end - f1=averagefidelity(model) - f2, f2_err=sampling(model, fidelity, M) - f3=1/2*(1+W(T0, T1, L,B)) - @test isapprox(f1, f3,rtol=1e-2) - @test isapprox(f2, f3, rtol=1e-2) - println("NI:", f1) - println("MC:", f2) - println("TH:", f3) -end +# ## +# @testset begin "test two spin sequenced shuttling fidelity" +# L=10; σ =sqrt(2)/20; M=20000; N=501; T1=200; T0=25*0.05; κₜ=1/20; κₓ=1/0.1; +# B=OrnsteinUhlenbeckField(0,[κₜ,κₓ],σ) +# model=TwoSpinModel(T0, T1, L, N, B) +# if visualize +# display(heatmap(collect(model.R.Σ), title="cross covariance matrix, test fig 4")) +# end +# f1=averagefidelity(model) +# f2, f2_err=sampling(model, fidelity, M) +# f3=1/2*(1+W(T0, T1, L,B)) +# @test isapprox(f1, f3,rtol=1e-2) +# @test isapprox(f2, f3, rtol=1e-2) +# println("NI:", f1) +# println("MC:", f2) +# println("TH:", f3) +# end # @testset "1/f noise chacacteristics" begin - σ = sqrt(2)/20; M = 4000; N=501; L=10; γ=(1e-3,1e3); # MHz + σ = sqrt(2)/20; M = 400; N=501; L=10; γ=(1e-2,1e2); # MHz # 0.01 ~ 100 μs # v = 0.1 ~ 1000 m/s - v=0.1; T=L/v; κₓ=0.01; + v=1; T=L/v; κₓ=10; + # T=10 + # 1/T=0.1 N/T=20 B=PinkBrownianField(0,[κₓ],σ, γ) model=OneSpinModel(T,L,N,B) @@ -93,20 +95,24 @@ end println("MC:", f2) println("TH:", f3) - t=range(0,T,N) - f_mc, f_mc_err=sampling(model, fidelity, M, vector=true) - t_ni, chi_ni=characteristicfunction(model.R) - f_ni= @. (1+real(chi_ni))/2 + k=10 + t=range(0,T,k) + f_mc=zeros(k); f_mc_err=zeros(k); f_ni=zeros(k); + @showprogress for i in eachindex(t) + model=OneSpinModel(t[i],L,N,B) + f_mc[i], f_mc_err[i]=sampling(model, fidelity, M) + f_ni[i]=averagefidelity(model) + end f_th=map(T->(1+W(T,L,B))/2, t)|>collect if visualize fig=lineplot(t,f_mc, xlabel="t", ylabel="F", name="monte-carlo sampling", # ribbon=sqrt.(f_mc_err/M) ) - lineplot!(fig, t_ni, f_ni, name="numerical integration") - lineplot!(fig, t,f_th, name="theoretical fidelity") + lineplot!(fig, t, f_ni, name="numerical integration") + lineplot!(fig, t, f_th, name="theoretical fidelity") display(fig) end - @test all([abs(f_mc[i]-f_th[i]) < sqrt(f_mc_err[i]) for i in 10:N]) + @test all([abs(f_mc[i]-f_th[i]) < sqrt(f_mc_err[i]) for i in eachindex(t)]) end \ No newline at end of file