Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
EigenSolver committed Apr 19, 2024
1 parent 2b66fb1 commit 2e72ee5
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/SpinShuttling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function Base.show(io::IO, model::ShuttlingModel)
println(io, "Process Time: T=$(model.T)")
println(io, "Shuttling Paths:")
t=range(0, model.T, model.N)
fig=lineplot(t, model.X[1].(t); width=20, height=5,
fig=lineplot(t, model.X[1].(t); width=30, height=9,
name="x1(t)")
for i in 2:model.n
lineplot!(fig, t, model.X[i].(t), name="x$i(t)")
Expand Down
9 changes: 2 additions & 7 deletions src/stochastics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,8 @@ Covariance function of Gaussian random field.
- `p₂::Point`: time-position array
- `process<:GaussianRandomField`: a Gaussian random field, e.g. `OrnsteinUhlenbeckField` or `PinkBrownianField`
"""

function covariance(p₁::Point, p₂::Point, process::OrnsteinUhlenbeckField)::Real
process.σ^2 / 4*prod( process.θ) * exp(-dot(process.θ, abs.(p₁ .- p₂)))
end

function covariance(p₁::Vector{<:Real}, p₂::Vector{<:Real}, process::OrnsteinUhlenbeckField)::Real
process.σ^2 / 4*prod( process.θ) * exp(-dot(process.θ, abs.(p₁ .- p₂)))
process.σ^2 / prod(2* process.θ) * exp(-dot(process.θ, abs.(p₁ .- p₂)))
end

function covariance(p₁::Point, p₂::Point, process::PinkBrownianField)::Real
Expand Down Expand Up @@ -163,7 +158,7 @@ Auto-Covariance matrix of a Gaussian random process.
"""
function covariancematrix(P::Vector{<:Point}, process::GaussianRandomField)::Symmetric
N = size(P, 1)
N = length(P)
A = Matrix{Real}(undef, N, N)
Threads.@threads for i in 1:N
for j in i:N
Expand Down
6 changes: 3 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ using SpinShuttling
using UnicodePlots
using ProgressMeter

# include("testintegration.jl")
include("testintegration.jl")
include("testfidelity.jl")
# include("teststochastics.jl")
# include("testspectrum.jl")
include("teststochastics.jl")
include("testspectrum.jl")
13 changes: 5 additions & 8 deletions test/testfidelity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ visualize=true

##
@testset begin "test single spin shuttling fidelity"
T=200; L=10; σ = sqrt(2) / 20; M = 2000; N=601; κₜ=1/20;κₓ=1/0.1;
T=400; L=10; σ = sqrt(2) / 20; M = 2000; N=601; κₜ=1/20;κₓ=1/0.1;

B=OrnsteinUhlenbeckField(0,[κₜ,κₓ],σ)

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))
Expand All @@ -23,7 +22,7 @@ end

#
@testset begin "test single spin forth-back shuttling fidelity"
T=200; L=10; σ = sqrt(2) / 20; M = 5000; N=501; κₜ=1/20;κₓ=10;
T=200; L=10; σ = sqrt(2) / 20; M = 2000; N=501; κₜ=1/20;κₓ=10;
# exponential should be smaller than 100
B=OrnsteinUhlenbeckField(0,[κₜ,κₓ],σ)

Expand Down Expand Up @@ -57,11 +56,11 @@ 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;
L=10; σ =sqrt(2)/20; M=2000; 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"))
display(heatmap(collect(model.R.Σ), title="cross covariance matrix, two spin EPR"))
end
f1=averagefidelity(model)
f2, f2_err=sampling(model, fidelity, M)
Expand Down Expand Up @@ -111,6 +110,4 @@ end
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 eachindex(t)])
end
8 changes: 4 additions & 4 deletions test/teststochastics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ using SpinShuttling: covariancepartition, Symmetric, Cholesky, ishermitian, issy
using LsqFit
using Statistics: std, mean

visualize=false
visualize=true

#
@testset begin "test of random function"
Expand All @@ -23,7 +23,7 @@ visualize=false

if visualize
display(heatmap(collect(R.Σ), title="covariance matrix, test fig 1"))
display(lineplot([R(),R(),R()],title="random function, test fig 2"))
display(lineplot(R(),title="random function, test fig 2"))
display(heatmap(crosscov, title="cross covariance matrix, test fig 3"))
end

Expand Down Expand Up @@ -70,8 +70,8 @@ end
println("mean 1st order:", mean(err1))
println("mean 2nd order:", mean(err2))
if visualize
fig=plot(err1, xlabel="T", ylabel="error", label="trapezoid")
plot!(err2, label="simpson")
fig=lineplot(err1, xlabel="T", ylabel="error", name="trapezoid")
lineplot!(fig, err2, name="simpson")
display(fig)
end
end
Expand Down

0 comments on commit 2e72ee5

Please sign in to comment.