Open AmitRotem opened 6 months ago
Hi Amit! Right, so the problem is indeed the type of the current_time
field. We might want it to be a union including the appropriate Dual type here? Does that work if you do it in your Ftdop
above?
Actually, I'm a bit puzzled in this case, as you are not taking a derivative wrt. time. Perhaps you could post the stack trace?
Hi Ash! I hope you're doing well and having fun!
schroedinger_dynamic
is promoting the time and state via DiffEqBase
to account for Dual
https://github.com/qojulia/QuantumOptics.jl/blob/e593ae1a51ebc47661322e8ac2c0116085708b2a/src/schroedinger.jl#L123-L124
This would also happed if I would be taking a derivative wrt. time.
If I initially build the TimeDependentSum
with init_time
as Dual
everything is fine
function Ftdop(q)
H= TimeDependentSum([q, abs2∘sinpi], [sigmaz(base), sigmax(base)]; init_time=0q)
_, ψf = timeevolution.schroedinger_dynamic(range(0,1,2), ψi, H)
abs2(ψt'last(ψf))
end
FD.derivative(Ftdop, 1.0) # O.k.
Thanks. Is it really necessary to promote the times in schroedinger_dynamic
? In any case, I think I agree we should be creating a new TimeDependentSum
automatically with the correct time type here. It's required at minimum for derivatives wrt time.
DiffEq
will promote the times if the input state is a Dual
, so actually there's no need to promote the times in QO when using a function as the Hamiltonian.
But this still mean TimeDependentSum
needs to be promoted.
I've added this solution https://github.com/qojulia/QuantumOptics.jl/pull/378
Maybe another solution could be propagating the Dual
type all the way to https://github.com/qojulia/QuantumOpticsBase.jl/blob/5ad71582770c217718848e14f649ee7b39b2b6db/src/time_dependent_operator.jl#L139
derivative on
TimeDependentSum
fails;schroedinger_dynamic
promotestspan
andstate
toDual
when needed, thenTimeDependentSum
is called with aDual
and fails.Possible to call
_promote_time_and_state
here; https://github.com/qojulia/QuantumOptics.jl/blob/e593ae1a51ebc47661322e8ac2c0116085708b2a/src/schroedinger.jl#L57-L60 and then promoteH
asTimeDependentSum(op.coefficients, op.static_op; init_time=zero(promote_type(eltype(tspan), typeof(current_time(op)))))
Or somehow pass this toschroedinger_dynamic_function
?