I’ve been using QuantumOptics.jl in Jupyter to run some physics simulations, and I’ve encountered an odd behaviour with one of my functions. My function is defined as follows
function lprϕ(Δ, tf, ψ0, tspan1, Δ_11)
tspan2 = [0, tf].*10^-6
tout1, ψ1 = timeevolution.schroedinger(tspan1, ψ0, H_2314(Δ, Δ_11))
tout2, ϕs = timeevolution.schroedinger(tspan2, ψ1[end], H_12; fout = get_phase)
return ϕs
end
ϕs is an array of tuples, one for each element of tout2, which means there are 2 of them in this case. Returning this way works fine, and I call this function successfully:
lprϕ(40000, 168, ψ0, [0,136].*10^-6, 23000)
returns
2-element Vector{Any}:
(0.7652719548899038, -0.28774709756921724)
(0.2373470060104735, -1.3494626427587488)
However, I only actually want the last tuple in the array. So I can just add [end] to the line above and it also works fine:
lprϕ(40000, 168, ψ0, [0,136].*10^-6, 23000)[end]
returns
(0.2373470060104735, -1.3494626427587488)
Here’s the weird part: if I instead have the function return only the last tuple, as follows:
function lprϕ(Δ, tf, ψ0, tspan1, Δ_11)
tspan2 = [0, tf].*10^-6
tout1, ψ1 = timeevolution.schroedinger(tspan1, ψ0, H_2314(Δ, Δ_11))
tout2, ϕs = timeevolution.schroedinger(tspan2, ψ1[end], H_12; fout = get_phase)
return ϕs
end
then it instead returns nonsense
Incidentally, these values are just the output of calling angle() on a complex number.
Anyone know what might be going on here? I’m having a hard time understanding how changing where the [end] is called can be that important intentionally, hence putting it here as a supposed bug. I suppose it’s also possible that this has something to do with Jupyter. I’d be happy to include more of the code if it would be relevant.