qojulia/QuantumOptics.jl

Out-of-place functions in semiclassical solvers

apkille opened this issue · 2 comments

According to the docs (https://docs.qojulia.org/semiclassical/), to run a semiclassical solver, say semiclassical.schroedinger_dynamic, one has to define the following functions:

function fquantum_schroedinger(t, ψ, u)
  # update H (Hamiltonian) according to dependencies on
  # classical variables u and quantum state ψ
  return H
end
function fclassical!(du, u, ψ, t)
  # update du (vector of derivatives of classical variables)
  # according to dependencies on classical variables
  # u and quantum state ψ
  # -- no return statement!
end

So we have to define an out-of-place function for the hamiltonian, and an in-place function for classical data. Is there any particular reason why fquantum_schroedinger has to be out-of-place? It is clunky that both functions cannot be in-place and less memory efficient.

Somewhat related to #404.

@apkille You're right. There's no reason in particular, why this is the case. Probably just because there were no nice ways to update operators in-place at the time, other than working with the .data fields directly, which can be a bit of a footgun.

To get the best performance, everything that can be in-place, should be in-place of course.