-
Notifications
You must be signed in to change notification settings - Fork 13
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
timedependent parameters #93
Comments
That's already possible, just not documented well. We should add an example on that to the documentation. You only have to make sure that you use the same time parameter when deriving the equations of motion as you do in your time-dependent Hamiltonian. You can do this by passing in the using QuantumCumulants
using Symbolics
using ModelingToolkit, OrdinaryDiffEq
@syms t::Real # time parameter
@cnumbers Ω0 κ t0 # other parameters
# Gaussian pulse centred at t0
Ω(t,t0) = Ω0*exp(-(t - t0)^2)
# Hilbert space and operator
h = FockSpace(:cavity)
@qnumbers a::Destroy(h)
# Hamiltonian
H = Ω(t,t0)*(a + a')
# Derive equations -- set iv here
eqs = meanfield(a,H,[a];rates=[κ],iv=t,order=1)
# Proceed as usual
@named sys = ODESystem(eqs)
p = (κ=>1, Ω0=>1, t0=>5)
u0 = zeros(ComplexF64,length(eqs))
prob = ODEProblem(sys,u0,(0.0,15.0),p)
sol = solve(prob,RK4()) For context: ModelingToolkit expects time-dependent variables of the form Note that in the example above the symbolic variables |
Ah cool thanks, if I get it working like I want to i'll write some documentation! |
I think there is a slight improvement possible in the Constructor of CorrelationFunction. eqs = meanfield([a'*a,a],H,[a];rates=[κ],iv=t,order=2)
c = CorrelationFunction(a', a, eqs, iv=t)
@named sys_corr = ODESystem(c)
_t = 5
p0_corr = correlation_p0(c,sol(_t),(p...,t=>_t))
u0_corr = correlation_u0(c,sol(_t))
prob_corr = ODEProblem(sys_corr,u0_corr,(0.0,15.0),(p0_corr...,t=>sol.t[1]))
sol_corr = solve(prob_corr,Tsit5())
plot(t->sol_corr(t,idxs=1), sol.t[[1,end]]...) |
I'm not 100% sure that's what you want. If you set the time parameter in the correlation function to the same one as in the standard time evolution you use as input, you're effectively resetting your time-dependent Hamiltonian to time 0. However, what you really want is to start at time In the example of the pulse, that would mean that another pulse occurs when calculating the correlation function. That won't match the state of the variables which have already been evolved for a longer time. You can actually see the pulse being applied in your solution. The problem is that it actually doesn't seem to work properly. Besides having to use a workaround to update the time-dependent parts in the original equations, I still get errors. Here's how I would do it: @syms τ::Real
@cnumbers t1
# Workaround to get time-dependent parts right
eqs_corr = substitute(eqs, Dict(t=>τ+t1))
c = CorrelationFunction(a', a, eqs_corr, iv=τ)
@named sys_corr = ODESystem(c)
_t = 5
p0_corr = correlation_p0(c,sol(_t),p)
u0_corr = correlation_u0(c,sol(_t))
prob_corr = ODEProblem(sys_corr,u0_corr,(0.0,15.0),(p0_corr...,t1=>sol.t[end]))
sol_corr = solve(prob_corr,Tsit5()) Unfortunately, that results in an |
I think I uderstand the problem, i.e. substitude(de) does only substitute in the equation, when it should also substitude in H, J and kappa. I'll try to write some code that tries to decide on which fieldnames substitution makes sense |
Ok I think it is a bit more complicated as QuantumCumulants.QAdd and so on do not already support substitude. Maybe for this part it would be sufficient to define |
Ah you're right of course. You need to create a full copy of H(t,t0) = Ω(t,t0)*(a + a')
@syms τ::Real
@cnumbers t1
# Workaround to get time-dependent parts right
eqs_corr = meanfield([a'*a,a],H(t1+τ,t0),[a];rates=[κ],iv=t,order=2) I.e., just re-derive the equations accordingly. That's ugly though and annoying if the symbolic derivation of equations takes a long time. We should probably expose
That's a bug. E.g. |
ok if the following assumptions are correct this should hopefully work not need rederivation of the equations and be only slightly confusing:
using QuantumCumulants
using Symbolics
using ModelingToolkit, OrdinaryDiffEq
using Plots
@syms t::Real # τ::Real # time parameter
# We define τ as a cnumber because else it is not detected as a parameter
@cnumbers Ω0 κ t0 τ # other parameters
# Gaussian pulse centred at t0
Ω(t,t0) = Ω0*exp(-(t - t0)^2)
# Hilbert space and operator
h = FockSpace(:cavity)
@qnumbers a::Destroy(h)
# Hamiltonian
H(t) = Ω(t,t0)*(a + a')
# Derive equations -- set iv here
# Workaround to get time-dependent parts right
eqs_corr = meanfield([a'*a,a],H(τ+t),[a];rates=[κ],iv=t,order=2)
@named sys = ODESystem(eqs_corr)
p = (κ=>1, Ω0=>1, t0=>5)
u0 = zeros(ComplexF64,length(eqs))
tmax=30.0
# for the meanfieldequations tau should be 0
prob = ODEProblem(sys,u0,(0.0,tmax),(p..., τ=>0))
sol = solve(prob,Tsit5())
# due to the limitations of cnumbers and Sym{Real} we now need to use t as tau and vice versa
# now t has the meaning of tau and vice versa
c = CorrelationFunction(a', a, eqs_corr, iv=t)
@named sys_corr = ODESystem(c)
function corr(t)
p0_corr = correlation_p0(c,sol(t),(p...,τ=>t))
u0_corr = correlation_u0(c,sol(t))
prob_corr = ODEProblem(sys_corr,u0_corr,(0.0,tmax),p0_corr)
sol_corr = solve(prob_corr,Tsit5())
end
τs = range(0,tmax,length=100)
hm = hcat([corr(t)(τs, idxs=1) for t in τs]...)
heatmap(τs,τs,abs.(hm)) Also I would be glad to help out a bit, it just might take some time for me to figure out the internals better first. |
If I remember correctly those assumptions should be fine. So in the end, this should work. It's a more efficient solution, but yeah, it's a bit confusing 😅 I still think an actual solution to this would be to expose the original time evolution stopping point, something like @syms τ t0
c = CorrelationFunction(a', a, eqs, iv=τ, iv0=t0) and internally substitute (which should be reasonably fast)
That would be great! The |
Do you think this is a bug in QuantumCumulants or Symbolic{s,Utils}, if the former any pointer on where to fix it? |
I'm not sure. It's probably something we missed when updating to the latest versions of the symbolics packages. Maybe there is some functionality missing that we need to implement in order for |
There is now an example with a time dependent pulse on the documentaion. |
thanks for the heads up and the nice example! |
Is it possible (or even in scope) to explicitly time dependent, to for example study the interaction of a pulse and a cavity it would be important to have a time dependent parameter to control the pulse slope.
The text was updated successfully, but these errors were encountered: