-
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?
Changes from 5 commits
571abc9
9665194
0e6036a
01baa16
e575f7d
71842a7
41e8216
5a354fe
d8d26a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,4 +10,4 @@ Manifest.toml | |
| benchmarks/benchmarks_output.json | ||
|
|
||
| .ipynb_checkpoints | ||
| *.ipynb | ||
| .devcontainer/* | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,9 +20,9 @@ function _mcsolve_output_func(sol, i) | |
| return (sol, false) | ||
| end | ||
|
|
||
| function _normalize_state!(u, dims, normalize_states) | ||
| function _normalize_state!(u, dims, normalize_states, type) | ||
| getVal(normalize_states) && normalize!(u) | ||
| return QuantumObject(u, Ket(), dims) | ||
| return QuantumObject(u, type(), dims) | ||
| end | ||
ytdHuang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| function _mcsolve_make_Heff_QobjEvo(H::QuantumObject, c_ops) | ||
|
|
@@ -110,15 +110,15 @@ If the environmental measurements register a quantum jump, the wave function und | |
| """ | ||
| function mcsolveProblem( | ||
| H::Union{AbstractQuantumObject{Operator},Tuple}, | ||
| ψ0::QuantumObject{Ket}, | ||
| ψ0::QuantumObject{X}, | ||
|
||
| tlist::AbstractVector, | ||
| c_ops::Union{Nothing,AbstractVector,Tuple} = nothing; | ||
| e_ops::Union{Nothing,AbstractVector,Tuple} = nothing, | ||
| params = NullParameters(), | ||
| rng::AbstractRNG = default_rng(), | ||
| jump_callback::TJC = ContinuousLindbladJumpCallback(), | ||
| kwargs..., | ||
| ) where {TJC<:LindbladJumpCallbackType} | ||
| ) where {TJC<:LindbladJumpCallbackType,X<:Union{Ket,Operator}} | ||
| haskey(kwargs, :save_idxs) && | ||
| throw(ArgumentError("The keyword argument \"save_idxs\" is not supported in QuantumToolbox.")) | ||
|
|
||
|
|
@@ -221,7 +221,7 @@ If the environmental measurements register a quantum jump, the wave function und | |
| """ | ||
| function mcsolveEnsembleProblem( | ||
| H::Union{AbstractQuantumObject{Operator},Tuple}, | ||
| ψ0::QuantumObject{Ket}, | ||
| ψ0::QuantumObject{X}, | ||
| tlist::AbstractVector, | ||
| c_ops::Union{Nothing,AbstractVector,Tuple} = nothing; | ||
| e_ops::Union{Nothing,AbstractVector,Tuple} = nothing, | ||
|
|
@@ -234,7 +234,7 @@ function mcsolveEnsembleProblem( | |
| prob_func::Union{Function,Nothing} = nothing, | ||
| output_func::Union{Tuple,Nothing} = nothing, | ||
| kwargs..., | ||
| ) where {TJC<:LindbladJumpCallbackType} | ||
| ) where {TJC<:LindbladJumpCallbackType,X<:Union{Ket,Operator}} | ||
| _prob_func = isnothing(prob_func) ? _ensemble_dispatch_prob_func(rng, ntraj, tlist, _mcsolve_prob_func) : prob_func | ||
| _output_func = | ||
| output_func isa Nothing ? | ||
|
|
@@ -261,6 +261,7 @@ function mcsolveEnsembleProblem( | |
| ensemble_prob = TimeEvolutionProblem( | ||
| EnsembleProblem(prob_mc.prob, prob_func = _prob_func, output_func = _output_func[1], safetycopy = false), | ||
| prob_mc.times, | ||
| X, | ||
| prob_mc.dimensions, | ||
| (progr = _output_func[2], channel = _output_func[3]), | ||
| ) | ||
|
|
@@ -358,7 +359,7 @@ If the environmental measurements register a quantum jump, the wave function und | |
| """ | ||
| function mcsolve( | ||
| H::Union{AbstractQuantumObject{Operator},Tuple}, | ||
| ψ0::QuantumObject{Ket}, | ||
| ψ0::QuantumObject{X}, | ||
| tlist::AbstractVector, | ||
| c_ops::Union{Nothing,AbstractVector,Tuple} = nothing; | ||
| alg::AbstractODEAlgorithm = DP5(), | ||
|
|
@@ -374,7 +375,7 @@ function mcsolve( | |
| keep_runs_results::Union{Val,Bool} = Val(false), | ||
| normalize_states::Union{Val,Bool} = Val(true), | ||
| kwargs..., | ||
| ) where {TJC<:LindbladJumpCallbackType} | ||
| ) where {TJC<:LindbladJumpCallbackType} where {X<:Union{Ket,Operator}} | ||
| ens_prob_mc = mcsolveEnsembleProblem( | ||
| H, | ||
| ψ0, | ||
|
|
@@ -415,7 +416,11 @@ function mcsolve( | |
| expvals_all = _expvals_all isa Nothing ? nothing : stack(_expvals_all, dims = 2) # Stack on dimension 2 to align with QuTiP | ||
|
|
||
| # stack to transform Vector{Vector{QuantumObject}} -> Matrix{QuantumObject} | ||
| states_all = stack(map(i -> _normalize_state!.(sol[:, i].u, Ref(dims), normalize_states), eachindex(sol)), dims = 1) | ||
| # states_all = stack(map(i -> _normalize_state!.(sol[:, i].u, Ref(dims), normalize_states), eachindex(sol)), dims = 1) | ||
| states_all = stack( | ||
| map(i -> _normalize_state!.(sol[:, i].u, Ref(dims), normalize_states, ens_prob_mc.states_type), eachindex(sol)), | ||
| dims = 1, | ||
| ) | ||
|
|
||
| col_times = map(i -> _mc_get_jump_callback(sol[:, i]).affect!.col_times, eachindex(sol)) | ||
| col_which = map(i -> _mc_get_jump_callback(sol[:, i]).affect!.col_which, eachindex(sol)) | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -6,17 +6,17 @@ _mesolve_make_L_QobjEvo(H::Union{QuantumObjectEvolution,Tuple}, c_ops) = liouvil | |||||
| _mesolve_make_L_QobjEvo(H::Nothing, c_ops::Nothing) = throw(ArgumentError("Both H and | ||||||
| c_ops are Nothing. You are probably running the wrong function.")) | ||||||
|
|
||||||
| function _gen_mesolve_solution(sol, times, dimensions, isoperket::Val) | ||||||
| if getVal(isoperket) | ||||||
| ρt = map(ϕ -> QuantumObject(ϕ, type = OperatorKet(), dims = dimensions), sol.u) | ||||||
| function _gen_mesolve_solution(sol, prob::TimeEvolutionProblem{X}) where {X<:Union{Operator,OperatorKet,SuperOperator}} | ||||||
| if X() == Operator() | ||||||
| ρ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) | ||||||
|
||||||
| ρt = map(ϕ -> QuantumObject(ϕ, type = X(), dims = prob.dimensions), sol.u) | |
| ρt = map(ϕ -> QuantumObject(ϕ, type = prob.states_type, dims = prob.dimensions), sol.u) |
Outdated
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).
Outdated
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
Outdated
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
Outdated
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
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, |
Uh oh!
There was an error while loading. Please reload this page.