Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
neil-glikin committed Feb 6, 2023
1 parent aef4eac commit c17a290
Show file tree
Hide file tree
Showing 24 changed files with 572 additions and 528 deletions.
6 changes: 3 additions & 3 deletions src/analyticfunctions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ where ``s`` is the order of the (blue) sideband that we are driving and ``L_{n}^
associated Laguerre polynomial. [ref](https://doi.org/10.1103/RevModPhys.75.281)
"""
function rabiflop(tspan, Ω::Real, η::Real, n̄::Real; s::Int = 0)
function rabiflop(tspan, Ω::Real, η::Real, n̄::Real; s::Int=0)
*= 1.0
Ω *= 2π
p = Vector{Float64}(undef, 0)
Expand All @@ -59,7 +59,7 @@ function rabiflop(tspan, Ω::Real, η::Real, n̄::Real; s::Int = 0)
Ω / 2 *
exp(-η^2 / 2) *
η^s *
sqrt(1 / prod((n + 1):(n + s))) *
sqrt(1 / prod((n+1):(n+s))) *
_alaguerre^2, n, s) *
t
)^2
Expand All @@ -72,7 +72,7 @@ end
function _laguerre(x, n)
L = 1.0, -x + 1
if n < 2
return L[n + 1]
return L[n+1]
end
for i in 2:n
L = L[2], ((2i - 1 - x) * L[2] - (i - 1) * L[1]) / i
Expand Down
146 changes: 96 additions & 50 deletions src/chambers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ mutable struct Chamber
_cnst_δB::Bool
function Chamber(;
iontrap::LinearChain,
B = 0,
Bhat = ẑ,
∇B = 0,
δB::TδB = 0,
lasers = Laser[]
B=0,
Bhat=ẑ,
∇B=0,
δB::TδB=0,
lasers=Laser[]
) where {TδB}
warn = nothing
for i in 1:length(lasers)
Expand All @@ -102,7 +102,7 @@ mutable struct Chamber
push!(lasers[i].pointing, (n, 1.0))
end
end
for j in (i + 1):length(lasers)
for j in (i+1):length(lasers)
if lasers[j] lasers[i]
lasers[j] = copy(lasers[i])
if isnothing(warn)
Expand All @@ -112,7 +112,7 @@ mutable struct Chamber
end
end
end
@assert isapprox(norm(Bhat), 1, rtol = 1e-6) "!(|$Bhat| = 1)"
@assert isapprox(norm(Bhat), 1, rtol=1e-6) "!(|$Bhat| = 1)"
for (li, l) in enumerate(lasers), p in l.pointing
@assert p[1] <= length(iontrap.ions) (
"""lasers[$li] points at iontrap.ions[$(p[1])], but there are only
Expand Down Expand Up @@ -200,7 +200,7 @@ Sets `chamber.Bhat` to `Bhat`
"""
function bfield_unitvector!(chamber::Chamber, Bhat::NamedTuple{(:x, :y, :z)})
rtol = 1e-6
@assert isapprox(norm(Bhat), 1, rtol = rtol) "!(|̂B| = 1)"
@assert isapprox(norm(Bhat), 1, rtol=rtol) "!(|̂B| = 1)"
chamber.Bhat = Bhat
end

Expand Down Expand Up @@ -247,14 +247,14 @@ end
basis(chamber::Chamber)
Returns the composite basis describing the Hilbert space for `chamber`.
This is the same as basis(iontrap(chain)).
"""
"""
function basis(T::Chamber)
return tensor(
T.iontrap.ions...,
T.iontrap.selectedmodes.x...,
T.iontrap.selectedmodes.y...,
T.iontrap.selectedmodes.z...,
)
return tensor(
T.iontrap.ions...,
T.iontrap.selectedmodes.x...,
T.iontrap.selectedmodes.y...,
T.iontrap.selectedmodes.z...,
)
end


Expand Down Expand Up @@ -347,7 +347,9 @@ function intensity_from_pitime(
s_indx = findall(x -> x[1] == ionnumber(ion), p)
@assert length(s_indx) > 0 "This laser doesn't shine on this ion"
s = p[s_indx[1]][2]
Ω = s * matrixelement(ion, transition, 1.0, polarization(laser), wavevector(laser), Bhat)
Ω =
s *
matrixelement(ion, transition, 1.0, polarization(laser), wavevector(laser), Bhat)
if Ω < 3e-14 # After change from Efield to intensity: This inequality changed so that it serves the same function but now for intensity = 1.0 rather than efield = 1.0 (specificially, increased by a factor of √(2/(cϵ₀)) ∼ 30 in SI units)
# even when coupling strength is zero, numerical error causes it to be finite
# (on order 1e-14), this is a band-aid to prevent users from unknowingly setting
Expand All @@ -373,7 +375,13 @@ function intensity_from_pitime(
transition::Tuple,
chamber::Chamber
)
return intensity_from_pitime(laser, pi_time, ion, transition, bfield_unitvector(chamber))
return intensity_from_pitime(
laser,
pi_time,
ion,
transition,
bfield_unitvector(chamber)
)
end
function intensity_from_pitime(
laser_index::Int,
Expand All @@ -387,7 +395,8 @@ function intensity_from_pitime(
pi_time,
ions(chamber)[ion_index],
transition,
bfield_unitvector(chamber))
bfield_unitvector(chamber)
)
end


Expand Down Expand Up @@ -453,7 +462,7 @@ function intensity_from_rabifrequency(
transition::Tuple,
Bhat::NamedTuple{(:x, :y, :z)}
)
return intensity_from_pitime(laser, 1/(2*rabi_frequency), ion, transition, Bhat)
return intensity_from_pitime(laser, 1 / (2 * rabi_frequency), ion, transition, Bhat)
end

"""
Expand All @@ -473,7 +482,13 @@ function intensity_from_rabifrequency(
transition::Tuple,
chamber::Chamber
)
return intensity_from_rabifrequency(laser, rabi_frequency, ion, transition, bfield_unitvector(chamber))
return intensity_from_rabifrequency(
laser,
rabi_frequency,
ion,
transition,
bfield_unitvector(chamber)
)
end
function intensity_from_rabifrequency(
laser_index::Int,
Expand All @@ -487,7 +502,8 @@ function intensity_from_rabifrequency(
rabi_frequency,
ions(chamber)[ion_index],
transition,
bfield_unitvector(chamber))
bfield_unitvector(chamber)
)
end


Expand Down Expand Up @@ -519,7 +535,8 @@ function intensity_from_rabifrequency!(
transition::Tuple,
chamber::Chamber
)
I::Float64 = intensity_from_rabifrequency(laser, rabi_frequency, ion, transition, chamber)
I::Float64 =
intensity_from_rabifrequency(laser, rabi_frequency, ion, transition, chamber)
intensity!(laser, I)
return I
end
Expand All @@ -530,7 +547,13 @@ function intensity_from_rabifrequency!(
transition::Tuple,
chamber::Chamber
)
I::Float64 = intensity_from_rabifrequency(laser_index, rabi_frequency, ion_index, transition, chamber)
I::Float64 = intensity_from_rabifrequency(
laser_index,
rabi_frequency,
ion_index,
transition,
chamber
)
laser = lasers(chamber)[laser_index]
intensity!(laser, I)
return I
Expand All @@ -555,43 +578,55 @@ end
Returns The frequency of the transition `transition` including the Zeeman shift experienced by `ion` given its position in `T`.
`ion` may be either an Ion or an Int indicating the desired ion's index within `chamber`.
"""
transitionfrequency(ion::Ion, transition::Tuple, chamber::Chamber; ignore_manualshift = false) =
transitionfrequency(
ion,
transition;
B = bfield(chamber, ion),
ignore_manualshift = ignore_manualshift
)
transitionfrequency(ion_index::Int, transition::Tuple, chamber::Chamber; ignore_manualshift = false) =
transitionfrequency(
ions(chamber)[ion_index],
transition,
chamber,
ignore_manualshift = ignore_manualshift
)
transitionfrequency(
ion::Ion,
transition::Tuple,
chamber::Chamber;
ignore_manualshift=false
) = transitionfrequency(
ion,
transition;
B=bfield(chamber, ion),
ignore_manualshift=ignore_manualshift
)
transitionfrequency(
ion_index::Int,
transition::Tuple,
chamber::Chamber;
ignore_manualshift=false
) = transitionfrequency(
ions(chamber)[ion_index],
transition,
chamber,
ignore_manualshift=ignore_manualshift
)

"""
transitionwavelength(ion, transition::Tuple, chamber::Chamber; ignore_manualshift=false)
Returns The wavelength of the transition `transition` including the Zeeman shift experienced by `ion` given its position in `T`.
`ion` may be either an Ion or an Int indicating the desired ion's index within `chamber`.
"""
transitionwavelength(ion::Ion, transition::Tuple, chamber::Chamber; ignore_manualshift = false) =
transitionwavelength(
ion,
transition;
B = bfield(chamber, ion),
ignore_manualshift = ignore_manualshift
)
transitionwavelength(
ion::Ion,
transition::Tuple,
chamber::Chamber;
ignore_manualshift=false
) = transitionwavelength(
ion,
transition;
B=bfield(chamber, ion),
ignore_manualshift=ignore_manualshift
)
transitionwavelength(
ion_index::Int,
transition::Tuple,
chamber::Chamber;
ignore_manualshift = false
ignore_manualshift=false
) = transitionwavelength(
ions(chamber)[ion_index],
transition,
chamber;
ignore_manualshift = ignore_manualshift
ignore_manualshift=ignore_manualshift
)

"""
Expand All @@ -611,12 +646,22 @@ Sets the wavelength of `laser` to the transition wavelength of `transition` in t
at the magnetic field seen by `ion` in `chamber`.
`ion` may be either an Ion or an Int indicating the desired ion's index within `chamber`.
"""
function wavelength_from_transition!(laser::Laser, ion::Ion, transition::Tuple, chamber::Chamber)
function wavelength_from_transition!(
laser::Laser,
ion::Ion,
transition::Tuple,
chamber::Chamber
)
λ = transitionwavelength(ion, transition, chamber)
wavelength!(laser, λ)
return λ
end
function wavelength_from_transition!(laser::Laser, ion_index::Int, transition::Tuple, chamber::Chamber)
function wavelength_from_transition!(
laser::Laser,
ion_index::Int,
transition::Tuple,
chamber::Chamber
)
ion = ions(chamber)[ion_index]
λ = transitionwavelength(ion, transition, chamber)
wavelength!(laser, λ)
Expand All @@ -633,7 +678,8 @@ Calls `matrixelement(ion, transition, I, ϵhat, khat, Bhat)` with `I`, `ϵhat`,
`ion` and `laser` must either both be indices or both their respective Structs.
"""
matrixelement(ion::Ion, transition::Tuple, laser::Laser, chamber::Chamber, time::Real) =
matrixelement(ion,
matrixelement(
ion,
transition,
intensity(laser)(time),
polarization(laser),
Expand Down Expand Up @@ -706,7 +752,7 @@ The Lamb-Dicke parameter:
``|k|cos(\\theta)\\sqrt{\\frac{\\hbar}{2m\\nu}}``
for a given vibrational mode, ion and laser.
"""
function lambdicke(V::VibrationalMode, I::Ion, L::Laser; scaled = false)
function lambdicke(V::VibrationalMode, I::Ion, L::Laser; scaled=false)
@fastmath begin
k = 2π / L.λ
scaled ? ν = 1 : ν = V.ν
Expand Down
18 changes: 9 additions & 9 deletions src/constants.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const c_rank2 = cat(
1 / 3 * [[-1, 0, 0] [0, -1, 0] [0, 0, 2]], #q=0
1 / sqrt(6) * [[0, 0, -1] [0, 0, im] [-1, im, 0]], #q=1
1 / sqrt(6) * [[1, -im, 0] [-im, -1, 0] [0, 0, 0]];
dims = 3
dims=3
) #q=2

Base.print(pc::PhysicalConstant) = print("$(pc.x) [$(pc.units)]")
Expand All @@ -83,9 +83,9 @@ end # module

export x̂, ŷ, ẑ, ndot

const= (x = 1, y = 0, z = 0)
const= (x = 0, y = 1, z = 0)
const= (x = 0, y = 0, z = 1)
const= (x=1, y=0, z=0)
const= (x=0, y=1, z=0)
const= (x=0, y=0, z=1)

function _print_axis(a::NamedTuple{(:x, :y, :z)})
if a ==
Expand All @@ -102,11 +102,11 @@ end
ndot(a::NamedTuple{(:x, :y, :z)}, b::NamedTuple{(:x, :y, :z)}) =
a.x * b.x + a.y * b.y + a.z * b.z
function Base.:+(a::NamedTuple{(:x, :y, :z)}, b::NamedTuple{(:x, :y, :z)})
return (x = a.x + b.x, y = a.y + b.y, z = a.z + b.z)
return (x=a.x + b.x, y=a.y + b.y, z=a.z + b.z)
end
function Base.:-(a::NamedTuple{(:x, :y, :z)}, b::NamedTuple{(:x, :y, :z)})
return (x = a.x - b.x, y = a.y - b.y, z = a.z - b.z)
return (x=a.x - b.x, y=a.y - b.y, z=a.z - b.z)
end
Base.:/(a::NamedTuple{(:x, :y, :z)}, b::Number) = (x = a.x / b, y = a.y / b, z = a.z / b)
Base.:*(a::NamedTuple{(:x, :y, :z)}, b::Number) = (x = a.x * b, y = a.y * b, z = a.z * b)
Base.:*(b::Number, a::NamedTuple{(:x, :y, :z)}) = (x = a.x * b, y = a.y * b, z = a.z * b)
Base.:/(a::NamedTuple{(:x, :y, :z)}, b::Number) = (x=a.x / b, y=a.y / b, z=a.z / b)
Base.:*(a::NamedTuple{(:x, :y, :z)}, b::Number) = (x=a.x * b, y=a.y * b, z=a.z * b)
Base.:*(b::Number, a::NamedTuple{(:x, :y, :z)}) = (x=a.x * b, y=a.y * b, z=a.z * b)
Loading

0 comments on commit c17a290

Please sign in to comment.