-
Notifications
You must be signed in to change notification settings - Fork 32
Adding operator support to time evolution problem #606
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
base: main
Are you sure you want to change the base?
Adding operator support to time evolution problem #606
Conversation
…nsions for examples.
src/time_evolution/time_evolution.jl
Outdated
| For a given `prob::TimeEvolutionProblem`, `prob.dims` or `getproperty(prob, :dims)` returns its `dimensions` in the type of integer-vector. | ||
| """ | ||
| struct TimeEvolutionProblem{PT<:AbstractSciMLProblem,TT<:AbstractVector,DT<:AbstractDimensions,KWT} | ||
| struct TimeEvolutionProblem{ST,PT<:AbstractSciMLProblem,TT<:AbstractVector,DT<:AbstractDimensions,KWT} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about
| struct TimeEvolutionProblem{ST,PT<:AbstractSciMLProblem,TT<:AbstractVector,DT<:AbstractDimensions,KWT} | |
| struct TimeEvolutionProblem{ST<:QuantumObjectType,DT<:AbstractDimensions,PT<:AbstractSciMLProblem,TT<:AbstractVector,KWT} |
cause I think the type of state_type and dimensions will be used more frequently.
By the way, can you also add state_type to the docstring ?
src/time_evolution/mesolve.jl
Outdated
| ρt = map(ϕ -> QuantumObject(vec2mat(ϕ), type = X(), dims = prob.dimensions), sol.u) | ||
| else | ||
| ρt = map(ϕ -> QuantumObject(vec2mat(ϕ), type = Operator(), dims = dimensions), sol.u) | ||
| ρt = map(ϕ -> QuantumObject(ϕ, type = X(), dims = prob.dimensions), sol.u) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, just use prob.states_type
| ρt = map(ϕ -> QuantumObject(ϕ, type = X(), dims = prob.dimensions), sol.u) | |
| ρt = map(ϕ -> QuantumObject(ϕ, type = prob.states_type, dims = prob.dimensions), sol.u) |
src/time_evolution/mesolve.jl
Outdated
| state_type = SuperOperator() | ||
| else | ||
| to_dense(_complex_float_type(T), mat2vec(ket2dm(ψ0).data)) | ||
| throw(ArgumentError("Unsupported state type for ψ0 in mesolveProblem.")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is redundant cause there is no method for other state type (as you defined above).
src/time_evolution/mesolve.jl
Outdated
| prob = ODEProblem{getVal(inplace),FullSpecialize}(L, ρ0, tspan, params; kwargs4...) | ||
|
|
||
| return TimeEvolutionProblem(prob, tlist, L_evo.dimensions, (isoperket = Val(isoperket(ψ0)),)) | ||
| return TimeEvolutionProblem(prob, tlist, state_type, L_evo.dimensions)#, (isoperket = Val(isoperket(ψ0)),)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can remove the comment directly
src/time_evolution/mesolve.jl
Outdated
| sol = solve(prob.prob, alg; kwargs...) | ||
|
|
||
| return _gen_mesolve_solution(sol, prob.times, prob.dimensions, prob.kwargs.isoperket) | ||
| return _gen_mesolve_solution(sol, prob)#, prob.kwargs.isoperket) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can remove the comment directly
src/time_evolution/mesolve.jl
Outdated
| to_dense(_complex_float_type(T), copy(state.data)) | ||
| else | ||
| to_dense(T, mat2vec(ket2dm(state).data)) | ||
| throw(ArgumentError("Unsupported state type for ψ0 in mesolveProblem.")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same, this is redundant
src/time_evolution/mcsolve.jl
Outdated
| function mcsolveProblem( | ||
| H::Union{AbstractQuantumObject{Operator},Tuple}, | ||
| ψ0::QuantumObject{Ket}, | ||
| ψ0::QuantumObject{X}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We seldom use X here in Julia. Usually will be T or ST to represent (State) Type.
Can you also change it for the other places ?
| jump_callback::TJC = ContinuousLindbladJumpCallback(), | ||
| kwargs..., | ||
| ) where {TJC<:LindbladJumpCallbackType} | ||
| ) where {TJC<:LindbladJumpCallbackType,ST<:Union{Ket,Operator}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| ) where {TJC<:LindbladJumpCallbackType,ST<:Union{Ket,Operator}} | |
| ) where {ST<:Union{Ket,Operator},TJC<:LindbladJumpCallbackType} |
| output_func::Union{Tuple,Nothing} = nothing, | ||
| kwargs..., | ||
| ) where {TJC<:LindbladJumpCallbackType} | ||
| ) where {TJC<:LindbladJumpCallbackType,ST<:Union{Ket,Operator}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| ) where {TJC<:LindbladJumpCallbackType,ST<:Union{Ket,Operator}} | |
| ) where {ST<:Union{Ket,Operator},TJC<:LindbladJumpCallbackType} |
| ensemble_prob = TimeEvolutionProblem( | ||
| EnsembleProblem(prob_mc.prob, prob_func = _prob_func, output_func = _output_func[1], safetycopy = false), | ||
| prob_mc.times, | ||
| ST(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| ST(), | |
| ψ0.type, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was replaced with prob_mc.states_type.
| normalize_states::Union{Val,Bool} = Val(true), | ||
| kwargs..., | ||
| ) where {TJC<:LindbladJumpCallbackType} | ||
| ) where {TJC<:LindbladJumpCallbackType} where {ST<:Union{Ket,Operator}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| ) where {TJC<:LindbladJumpCallbackType} where {ST<:Union{Ket,Operator}} | |
| ) where {ST<:Union{Ket,Operator},TJC<:LindbladJumpCallbackType} |
| ens_prob = TimeEvolutionProblem( | ||
| EnsembleProblem(prob.prob, prob_func = _prob_func, output_func = _output_func[1], safetycopy = false), | ||
| prob.times, | ||
| StateOpType(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| StateOpType(), | |
| prob.state_type, |
| prob = ODEProblem{getVal(inplace),FullSpecialize}(U, ψ0, tspan, params; kwargs4...) | ||
|
|
||
| return TimeEvolutionProblem(prob, tlist, H_evo.dimensions) | ||
| return TimeEvolutionProblem(prob, tlist, ST(), H_evo.dimensions) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| return TimeEvolutionProblem(prob, tlist, ST(), H_evo.dimensions) | |
| return TimeEvolutionProblem(prob, tlist, ψ0.type, H_evo.dimensions) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is needed because psi0 gets overwritten in line 82 and is no longer a quantum object in line 93. I can leave like this or I can put a line states_type = ѱ0.data somewhere before 82.
Edit: actually that is exactly what I did for mesolve so I will do the same for sesolve and elsewhere.
| ) | ||
|
|
||
| return TimeEvolutionProblem(prob, tlist, dims, (isoperket = Val(isoperket(ψ0)),)) | ||
| return TimeEvolutionProblem(prob, tlist,StateOpType(), dims, ()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| return TimeEvolutionProblem(prob, tlist,StateOpType(), dims, ()) | |
| return TimeEvolutionProblem(prob, tlist,ψ0.type, dims) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to mesolve, I introduced a states_type variable that is defined during the definition of
| ensemble_prob = TimeEvolutionProblem( | ||
| EnsembleProblem(prob_sme, prob_func = _prob_func, output_func = _output_func[1], safetycopy = true), | ||
| prob_sme.times, | ||
| StateOpType(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| StateOpType(), | |
| ψ0.type, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was replaced with prob_sme.states_type.
| ) | ||
|
|
||
| return TimeEvolutionProblem(prob, tlist, dims) | ||
| return TimeEvolutionProblem(prob, tlist, ST(), dims) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| return TimeEvolutionProblem(prob, tlist, ST(), dims) | |
| return TimeEvolutionProblem(prob, tlist, ψ0.type, dims) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to sesolve, this got updated to a states_type variable defined near the top of the function.
| ensemble_prob = TimeEvolutionProblem( | ||
| EnsembleProblem(prob_sme, prob_func = _prob_func, output_func = _output_func[1], safetycopy = true), | ||
| prob_sme.times, | ||
| ST(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| ST(), | |
| ψ0.type, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This became prob_sme.times. (actually prob_sse, I changed it to be consistent). Though, as of right now, the only type ssesolve will take is just Ket. The there is some issue with how the problem is defined that makes it so it cannot take in matrices. Same also didn't update smesolve for the same reason.
Checklist
Thank you for contributing to
QuantumToolbox.jl! Please make sure you have finished the following tasks before opening the PR.make test.juliaformatted by running:make format.docs/folder) related to code changes were updated and able to build locally by running:make docs.CHANGELOG.mdshould be updated (regarding to the code changes) and built by running:make changelog.Request for a review after you have completed all the tasks. If you have not finished them all, you can also open a Draft Pull Request to let the others know this on-going work.
Description
Updated TimeEvolutionProblem be parametrically typed using the type of the starting state as well as expanded sesolve, mesolve and mcsolve to allow them to take in operators, superoperators and operators respectively (along with other changes to facilitate this). ssesolve and smesolve are still in progress.
Related issues or PRs
Working on #521