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

Cache input to master derivative functions #406

Open
apkille opened this issue Jul 31, 2024 · 3 comments
Open

Cache input to master derivative functions #406

apkille opened this issue Jul 31, 2024 · 3 comments

Comments

@apkille
Copy link
Contributor

apkille commented Jul 31, 2024

In several of the master functions, e.g., dmaster_h!, a cached copy of drho is required as input:

dmaster_h!(drho, H, J, Jdagger, rates, rho, drho_cache)

Presumably, this is to improve performance of solvers such as timeevolution.master. However, this feels excessive if we don't want to use the corresponding solver, and instead create an ODE problem directly with our density operators and dmaster_h!. For example, it would be great if we could define an in-place method without the cache input, say

f!(drho, rho, p, t) = timeevolution.dmaster_h!(drho, H, J, Jdagger, rates, rho)
prob  = ODEProblem(f!, rho0, (t0, t1))

This is a natural interface that I'm aiming for with all of the recent broadcasting work (#404, qojulia/QuantumOpticsBase.jl#172). Do the QO maintainers have any comments or oppositions to defining such a method in QO.jl?

@david-pl
Copy link
Member

david-pl commented Aug 7, 2024

It shouldn't create any ambiguities to add that method, so go ahead 👍

@Krastanov
Copy link
Collaborator

this might be related #298

@apkille
Copy link
Contributor Author

apkille commented Aug 15, 2024

@Krastanov to build off our discussion in person: a workaround is assigning the cached drho to the p parameter of the ODEProblem object, which prevents us from caching at each time step if we use OrdinaryDiffEq.jl directly. So we don't have to define any new methods. For example, using dmaster_h! which is already a part of the public API, we have

using QuantumOptics, OrdinaryDiffEq

b = FockBasis(5)
psi0 = fockstate(b, 4)
rho0 = dm(psi0)
tmp = copy(rho0)
H = number(b)
J = [destroy(b), create(b)]
Jdagger = dagger.(J)
rates = [0.7, 0.5]

f!(drho, rho, p, t) = timeevolution.dmaster_h!(drho, H, J, Jdagger, rates, rho, p)
prob = ODEProblem(f!, rho0, (0.0, 1.0), tmp)
sol = solve(prob, DP5(); save_everystep=false)

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

3 participants