Skip to content

Commit

Permalink
refactor interface
Browse files Browse the repository at this point in the history
  • Loading branch information
EigenSolver committed Apr 15, 2024
1 parent db45ac0 commit 9f4749d
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion docs/src/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ f2, f2_err=sampling(model, fidelity, M)
```
For the single spin shuttling at constant velocity, analytical solution is also available.
```julia
f3=1/2*(1+φ(T,L,B))
f3=1/2*(1+W(T,L,B))
```
We can compare the results form the three methods.
```julia
Expand Down
2 changes: 1 addition & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ averagefidelity
```

```@docs
φ
W
```

### Stochastics
Expand Down
12 changes: 6 additions & 6 deletions src/SpinShuttling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ OneSpinForthBackModel, TwoSpinParallelModel, RandomFunction, CompositeRandomFunc
OrnsteinUhlenbeckField, PinkBrownianField
export averagefidelity, fidelity, sampling, characteristicfunction, characteristicvalue
export covariance, covariancematrix
export φ
export W

"""
Spin shuttling model defined by a stochastic field, the realization of the stochastic field is
Expand Down Expand Up @@ -256,16 +256,16 @@ function fidelity(model::ShuttlingModel, randseq::Vector{<:Real}; vector::Bool=f
else
Z = missing
end
ϕ = vector ? cumsum(Z)* dt : sum(Z) * dt
return (1 .+ cos.(ϕ)) / 2
W = vector ? cumsum(Z)* dt : sum(Z) * dt
return (1 .+ cos.(W)) / 2
end



"""
Analytical average fidelity of a one-spin shuttling model.
"""
function φ(T::Real,L::Real,B::OrnsteinUhlenbeckField; path=:straight)::Real
function W(T::Real,L::Real,B::OrnsteinUhlenbeckField; path=:straight)::Real
κₜ=B.θ[1]
κₓ=B.θ[2]
σ =B.σ
Expand All @@ -284,7 +284,7 @@ end
"""
Analytical average fidelity of a sequenced two-spin EPR pair shuttling model.
"""
function φ(T0::Real,T1::Real,L::Real,B::OrnsteinUhlenbeckField; path=:sequenced)::Real
function W(T0::Real,T1::Real,L::Real,B::OrnsteinUhlenbeckField; path=:sequenced)::Real
κₜ=B.θ[1]
κₓ=B.θ[2]
σ =B.σ
Expand All @@ -304,7 +304,7 @@ end
"""
Theoretical fidelity of a one-spin shuttling model for a pink-brownian noise.
"""
function φ(T::Real, L::Real, B::PinkBrownianField)::Real
function W(T::Real, L::Real, B::PinkBrownianField)::Real
β= T.*B.γ
γ= L*B.θ[1]
return exp(-B.σ^2*T^2*F4(β, γ))
Expand Down
12 changes: 6 additions & 6 deletions test/testfidelity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ visualize=true

f1=averagefidelity(model)
f2, f2_err=sampling(model, fidelity, M)
f3=1/2*(1+φ(T,L,B))
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)
Expand All @@ -36,7 +36,7 @@ end
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+φ(T,L,B,path=:forthback))/2 for T in t]
f_th=[(1+W(T,L,B,path=:forthback))/2 for T in t]
fig=plot(t, f_mc, size=figsize,
xlabel="t", ylabel="F", label="monte-carlo sampling",
# ribbon=@. sqrt(f_mc_err/M)
Expand All @@ -52,7 +52,7 @@ end

f1=averagefidelity(model)
f2, f2_err=sampling(model, fidelity, M)
f3=1/2*(1+φ(T, L, B, path=:forthback))
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)
Expand All @@ -70,7 +70,7 @@ end
end
f1=averagefidelity(model)
f2, f2_err=sampling(model, fidelity, M)
f3=1/2*(1+φ(T0, T1, L,B))
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)
Expand All @@ -89,7 +89,7 @@ end

f1=averagefidelity(model)
f2, f2_err=sampling(model, fidelity, M)
f3=1/2*(1+φ(T,L,B))
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)
Expand All @@ -100,7 +100,7 @@ end
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
f_th=map(T->(1+φ(T,L,B))/2, t)|>collect
f_th=map(T->(1+W(T,L,B))/2, t)|>collect
if visualize
fig=plot(t,f_mc, size=figsize,
xlabel="t", ylabel="F", label="monte-carlo sampling",
Expand Down
4 changes: 2 additions & 2 deletions test/teststochastics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ end
f1=exp(-integrate(R.Σ[:,:], dt, dt, method=:trapezoid)/2)
f2=exp(-integrate(R.Σ[:,:], dt, dt, method=:simpson)/2)
@test isapprox(f1,f2,rtol=1e-2)
f3=φ(T,L,B)
f3=W(T,L,B)
err1[i]=abs(f1-f3)
err2[i]=abs(f2-f3)
i+=1
Expand Down Expand Up @@ -103,7 +103,7 @@ end
f1=exp(-integrate(R.Σ[:,:], dt, dt, method=:trapezoid)/2)
f1_sym=exp(-integrate(R.Σ, dt)/2)
f2=exp(-integrate(R.Σ[:,:], dt, dt, method=:simpson)/2)
f3=φ(T,v*T,B)
f3=W(T,v*T,B)
err1[i]=abs(f1-f3)/f3
err1_sym[i]=abs(f1_sym-f3)/f3
err2[i]=abs(f2-f3)/f3
Expand Down

0 comments on commit 9f4749d

Please sign in to comment.