-
Notifications
You must be signed in to change notification settings - Fork 110
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
Get the DifferentialEquations.jl
problem object
#298
Comments
I really like this idea. I've actually been thinking about this myself for a while now, but never got around to actually doing it. I'm not sure yet what the best way to do this is though.
It would be awesome if you could take a stab at this! Let me know if you need help. |
Concerning the wrapping in |
"Simple interfaces" might have overstated it a bit, but here are a few more details https://discourse.julialang.org/t/juliadiffeq-with-custom-types/16294 |
Getting DiffEq to work directly on QO types would be ideal. Not sure how easy it is to do that. It's easy enough thinking about the simple matrix*vector Schrödinger equation, but there are other cases such as |
Just for reference, after #306 gets merged you can just do something like this: using QuantumOptics
using OrdinaryDiffEq
b = SpinBasis(1//2)
ψ0 = spindown(b)
H = DenseOperator(sigmax(b))
const Hdata = H.data
function f(du,u,p,t)
QuantumOptics.timeevolution.dschroedinger(u, Hdata, du)
return nothing
end
prob = ODEProblem(f,ψ0.data,(0.0,10.0))
sol = solve(prob,Tsit5()) That will give you an |
Would it be possible to change the signature of |
@PhilipVinc certainly. It's not part of the public API yet, so changing it should be fine. Maybe we should add it to the API afterwards. Also, if we go for this option it might make sense to add some convenience function that defines the derivative function needed by DiffEq for you, rewrapping things as |
After #312 gets merged, the syntax will be function f(du,u,p,t)
timeevolution.dschroedinger!(du, Hdata, u)
return nothing
end It's actually rather simple to work with non-data operators as well. You can just use the b1 = SpinBasis(1//2)
b = b1^2
ψ0 = tensor([spindown(b1) for i=1:2]...)
const Hlazy = LazyTensor(b,[1,2],(sigmax(b1),sigmax(b1)))
const dpsi = Ket(b)
const psi = Ket(b)
function f(du,u,p,t)
timeevolution.recast!(dpsi,du)
timeevolution.recast!(psi,u)
timeevolution.dschroedinger!(dpsi,Hlazy,psi)
timeevolution.recast!(du,dpsi)
return nothing
end
prob = ODEProblem(f,ψ0.data,(0.0,10.0))
sol = solve(prob,Tsit5()) That's a pretty solid way to do this as it works with any type QO.jl implements and it will be just as fast as the functions from The only thing that might still be missing now is a neat way to define such an @Krastanov What do you think? I'd actually prefer this approach here as we don't have to worry about performance - as opposed to what we started in qojulia/QuantumOpticsBase.jl#16 |
I think it is important for both features to be implemented. Julia is supposed to provide zero cost abstractions and these So, while the example from the last comment seems like a great improvement, it falls short from a truly natural interface like: b1 = SpinBasis(1//2)
b = b1^2
ψ0 = tensor([spindown(b1) for i=1:2]...)
const Hlazy = LazyTensor(b,[1,2],(sigmax(b1),sigmax(b1)))
const dpsi = Ket(b)
const psi = Ket(b)
function f(du,u,p,t)
timeevolution.dschroedinger!(du,Hlazy,u)
return nothing
end
prob = ODEProblem(f,ψ0,(0.0,10.0))
sol = solve(prob,Tsit5()) On the other hand, my complaint can be sidestepped by simply implementing multiple methods for dschroedinger!. Especially given that I have not had time to work on qojulia/QuantumOpticsBase.jl#16 What is your opinion on this suggestion:
The reason I believe point 3 is important, is because it drastically simplifies the ODE code in this library, which makes it much easier to use the advanced features of the ODE solvers. One extremely important example is autodifferentiation: currently it is extremely painful to get autodifferentiation to work with QuantumOptics, which makes optimal control tasks unnecessarily difficult to write (exactly the thing that julia is promising should not be a problem). Another reason is so that we can run QuantumOptics on a GPU. These and many other interoperability features will become possible once the interfaces for point 3 are implemented. |
I am excited to see #312 merged. If my point 3 above works, it would just make |
As a side note: things should already run on GPU. The |
Hi! What is missing for this to be merged? Is there any way I can help with it? |
Is there a way to do the same for a time-dependent Hamiltonian? If I run something similar: using QuantumOptics
using OrdinaryDiffEq
fock = FockBasis(n_photon)
a = destroy(fock); at = create(fock);
n = number(fock); I = identityoperator(fock)
ψ0 = fockstate(fock, 1)
H = TimeDependentSum([1.0, fcomp(-1), fcomp(1)],[omega0*n, -0.1*(a + at), -0.1*(a + at)])
const D = timeevolution.schroedinger_dynamic_function(H)
function f(du,u,p,t)
timeevolution.dschroedinger_dynamic!(du, D, u, t)
return nothing
end
prob = ODEProblem(f,ψ0.data,(0.0,10.0))
sol = solve(prob,Tsit5()) I get the MethodError: MethodError: no method matching mul!(::Vector{ComplexF64}, ::TimeDependentSum{...}) |
I think we may want to consider having our own "Problem" type rather like Bloqade is doing. That way we can have a |
@amilsted Thank you! Looking into the source code worked out for me. I needed this to utilise the ability of threading with |
There are a lot of extra tools that
DifferentialEquations.jl
provides that I want to be able to use (e.g. sensitivity analysis and optimal control, which I would prefer to do directly, instead of having them wrapped into something specific toQuantumOptics.jl
).Looking at some of the timeevolution objects, it seems those objects are not really abstracted away and easily available to the user. How receptive are the developers of
QuantumOptics
to introducing:dschroedinger
from https://github.com/qojulia/QuantumOptics.jl/blob/master/src/schroedinger.jl public, stable, and documented)?If this is acceptable, I might be able to volunteer making these changes myself. It would drastically expand the problems in which I would be using
QuantumOptics
.The text was updated successfully, but these errors were encountered: