Skip to content

Commit

Permalink
update version and fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
EigenSolver committed Jul 6, 2024
1 parent 348d229 commit ed86e52
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 33 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SpinShuttling"
uuid = "eff49e45-ae6d-44ae-9170-2124a87971c9"
authors = ["Yuning Zhang"]
version = "0.2.0"
version = "0.2.1"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
41 changes: 9 additions & 32 deletions src/SpinShuttling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -237,29 +237,6 @@ function dephasingcoeffs(n::Int)::Array{Real,3}
end


"""
Calculate the average fidelity of a spin shuttling model using numerical integration
of the covariance matrix.
# Arguments
- `model::ShuttlingModel`: The spin shuttling model
"""
# function statefidelity(model::ShuttlingModel)::Real
# # model.R is immutable
# if model.n == 1
# R = model.R
# elseif model.n == 2
# R = CompositeRandomFunction(model.R, [1, -1])
# elseif model.n > 2
# error("The number of spins is not supported")
# end
# W = real(characteristicvalue(R))
# F = @. 1 / 2 * (1 + W)
# return F
# end


"""
Calculate the state fidelity of a spin shuttling model using numerical integration
of the covariance matrix.
Expand All @@ -283,9 +260,9 @@ Sampling an observable that defines on a specific spin shuttling model
- `objective::Function`: The objective function `objective(mode::ShuttlingModel; randseq)``
- `M::Int`: Monte-Carlo sampling size
"""
function sampling(model::ShuttlingModel, objective::Function, M::Int; vector::Bool=false)
function sampling(model::ShuttlingModel, objective::Function, M::Int; isarray::Bool=false)
randpool = randn(model.n * model.N, M)
samplingfunction = i::Int -> objective(model, randpool[:, i]; tspan=vector)::Union{Real,Vector{<:Real}}
samplingfunction = i::Int -> objective(model, randpool[:, i]; isarray=isarray)::Union{Real,Vector{<:Real}}
return sampling(samplingfunction, M)
end

Expand All @@ -296,13 +273,13 @@ Sample the state fidelity of a spin shuttling model using Monte-Carlo sampling.
# Arguments
- `model::ShuttlingModel`: The spin shuttling model
- `randseq::Vector{<:Real}`: The random sequence
- `tspan::Bool`: Return the dephasing matrix array for each time step
- `isarray::Bool`: Return the dephasing matrix array for each time step
"""
function statefidelity(model::ShuttlingModel, randseq::Vector{<:Real}; tspan=false)::Union{Real,Vector{<:Real}}
w=dephasingmatrix(model, randseq; tspan=tspan)
function statefidelity(model::ShuttlingModel, randseq::Vector{<:Real}; isarray=false)::Union{Real,Vector{<:Real}}
w=dephasingmatrix(model, randseq; isarray=isarray)
ψ = model.Ψ
f= w->real'*(w.**ψ'))*ψ)
return tspan ? vec(mapslices(f, w, dims=[1,2])) : f(w)
return isarray ? vec(mapslices(f, w, dims=[1,2])) : f(w)
end


Expand All @@ -312,17 +289,17 @@ Sample the dephasing matrix array for a given normal random vector.
# Arguments
- `model::ShuttlingModel`: The spin shuttling model
- `randseq::Vector{<:Real}`: The random sequence
- `tspan::Bool`: Return the dephasing matrix array for each time step
- `isarray::Bool`: Return the dephasing matrix array for each time step
"""
function dephasingmatrix(model::ShuttlingModel, randseq::Vector{<:Real}; tspan=false)::Array{<:Complex}
function dephasingmatrix(model::ShuttlingModel, randseq::Vector{<:Real}; isarray=false)::Array{<:Complex}
# model.R || error("covariance matrix is not initialized")
N = model.N
n=model.n
dt = model.T / N
noises = model.R(randseq)
B=[noises[(i-1)*N+1:i*N] for i in 1:n]
c=dephasingcoeffs(n)
if tspan
if isarray
W=ones(Complex, 2^n,2^n, N)
for j in 1:2^n
for k in 1:j-1
Expand Down

0 comments on commit ed86e52

Please sign in to comment.