I am trying to modify a model with some extra terms, but getting an error.
using QuantumCumulants
using OrdinaryDiffEq, ModelingToolkit
hc = FockSpace(:cavity)
hm = FockSpace(:motion)
h = hc ⊗ hm
t = (0.0,10000.0)
@qnumbers a::Destroy(h,1) b::Destroy(h,2)
@cnumbers Δ ωm t0 gm E gm κ
function F(t,t0,E,Δ)
if t.<=t0
E0=E*t0
F=1im*E0/Δ *(1-exp(1im*Δ*t))
else
F=zero(1im)
end
return F
end
# H= -Δ*a'*a + ωm*b'*b+gm*(a'+a)*(b +b') + E*(a + a') # works fine without exp() and F
H= -Δ*a'*a + ωm*b'*b+gm*(a'+a)*(exp.(-1im*ωm.*t).*b + exp.(1im*ωm.*t).*b') + (F.*a + conj(F).*a')#test Hamiltonian
eqs = meanfield([b'*b,a'*a],H,[a];rates=[κ],order=2)
eqs_completed = complete(eqs)
@named sys = ODESystem(eqs_completed)
u0 = zeros(ComplexF64, length(eqs_completed))
u0[1] = 4*1e3 # Initial condition
p0 = (Δ=>-1, ωm=>10, E=>1e5, gm=>1e-4,t0=>2,κ=>1)
prob = ODEProblem(sys,u0,t,p0)
sol = solve(prob,RK4())
#plot
using Plots
n = abs.(sol[a'*a])
plot(sol.t, n, xlabel="t", label="n_m")
I found an errors:
- no method matching length, I think some issue in vectors multiplication using exp(). In addition, I guess my F has different time length than operators a and b in H etc. Please let me know any hints/comments.
What’s the stacktrace? What line is it pointing to?
It points to the line where Hamiltonian H is written. And Stacktrace is below.
Stacktrace:
[1] _similar_shape(itr::Destroy{ProductSpace{Vector{FockSpace{Symbol}}}, Symbol, Int64, Base.ImmutableDict{DataType, Any}}, #unused#::Base.HasLength)
@ Base ./array.jl:663
[2] _collect(cont::UnitRange{Int64}, itr::Destroy{ProductSpace{Vector{FockSpace{Symbol}}}, Symbol, Int64, Base.ImmutableDict{DataType, Any}}, #unused#::Base.HasEltype, isz::Base.HasLength)
@ Base ./array.jl:718
[3] collect(itr::Destroy{ProductSpace{Vector{FockSpace{Symbol}}}, Symbol, Int64, Base.ImmutableDict{DataType, Any}})
@ Base ./array.jl:712
[4] broadcastable(x::Destroy{ProductSpace{Vector{FockSpace{Symbol}}}, Symbol, Int64, Base.ImmutableDict{DataType, Any}})
@ Base.Broadcast ./broadcast.jl:704
[5] broadcasted(::Function, ::Base.Broadcast.Broadcasted{Base.Broadcast.Style{Tuple}, Nothing, typeof(exp), Tuple{Base.Broadcast.Broadcasted{Base.Broadcast.Style{Tuple}, Nothing, typeof(*), Tuple{Base.RefValue{SymbolicUtils.BasicSymbolic{CNumber}}, Tuple{Float64, Float64}}}}}, ::Destroy{ProductSpace{Vector{FockSpace{Symbol}}}, Symbol, Int64, Base.ImmutableDict{DataType, Any}})
@ Base.Broadcast ./broadcast.jl:1302
[6] top-level scope
@ In[80]:21
This looks like it may not be Symbolics but instead QuantumCumulants-specific. Have you opened an issue on the QuantumCumulants.jl github repo?
No. I don’t know how to do that. but I will try.