Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UndefVarError: avg not defined #108

Closed
a7b opened this issue Aug 22, 2022 · 2 comments
Closed

UndefVarError: avg not defined #108

a7b opened this issue Aug 22, 2022 · 2 comments

Comments

@a7b
Copy link

a7b commented Aug 22, 2022

Hi,

I have been trying to do some calculations with QuantumCumulants.jl but when I try to solve the resulting ODEProblem, I keep getting this UndefVarError saying that avg is not defined. Here is a short script that reproduces the issue. I am using v0.2.7.

using QuantumCumulants
using OrdinaryDiffEq, ModelingToolkit
using Plots

@syms t::Real
@register r(t)
@register i(t)

hq = NLevelSpace(:qubit,(:g,:e))
a = Transition(hq, :annihilate, :g, :e)
σ = Transition(hq, )
σz = σ(:g, :g) - σ(:e, :e)
σy = 1im*(σ(:e, :g)-σ(:g, :e))
σx = σ(:g, :e) + σ(:e, :g)

#Hamiltonian 

H = r(t) * (a' + a) + i(t)*1im*(a' - a)

eqns = meanfield([σx, σy, σz], H)

@named sys = ODESystem(eqns)


function r(t)
    return 2π*19e-3
end

function i(t)
    return 0.
end

u0 = [1.0 + 0im, 0. + 0im, 0. + 0im]

prob = ODEProblem(sys, u0, (0.0, 1/(4*19e-3)))

sol = solve(prob, Tsit5()) #where error happens

t = sol.t
s22 = real.(sol[σz])
plot(t, s22, xlabel="t", ylabel="⟨σz⟩", legend=false, size=(600,300))

And here is the resulting stacktrace.

image

Is this some kind of versioning issue? I can't seem to install v0.2.8.

Thank you so much,

Aditya

@ChristophHotter
Copy link
Member

Hi Aditya,
You are using operator sums on the left hand side of the equations. This is not possible.
In your case QuantumCumulants.jl always uses sigma_eg and sigma_ee. Just derive the equations for them. You can then calculate the desired numerical averages after the time evolution.

And you are also defining two different operators (symbol name) on the same Hilbertspace, this also causes problems. (Just don't use a and a' here)

@a7b
Copy link
Author

a7b commented Sep 4, 2022

I see. That seemed to be the issue. Thank you so much!

@a7b a7b closed this as completed Sep 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants