Skip to content

Commit db3422e

Browse files
Updated ssesolve, smesolve and mcsolve to be minimal changes along with a few other changes.
1 parent d8d26a3 commit db3422e

File tree

5 files changed

+26
-22
lines changed

5 files changed

+26
-22
lines changed

src/time_evolution/mcsolve.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ function mcsolveProblem(
118118
rng::AbstractRNG = default_rng(),
119119
jump_callback::TJC = ContinuousLindbladJumpCallback(),
120120
kwargs...,
121-
) where {TJC<:LindbladJumpCallbackType,ST<:Union{Ket,Operator}}
121+
) where {ST<:Union{Ket,Operator}, TJC<:LindbladJumpCallbackType}
122122
haskey(kwargs, :save_idxs) &&
123123
throw(ArgumentError("The keyword argument \"save_idxs\" is not supported in QuantumToolbox."))
124124

@@ -234,7 +234,7 @@ function mcsolveEnsembleProblem(
234234
prob_func::Union{Function,Nothing} = nothing,
235235
output_func::Union{Tuple,Nothing} = nothing,
236236
kwargs...,
237-
) where {TJC<:LindbladJumpCallbackType,ST<:Union{Ket,Operator}}
237+
) where {ST<:Union{Ket,Operator}, TJC<:LindbladJumpCallbackType}
238238
_prob_func = isnothing(prob_func) ? _ensemble_dispatch_prob_func(rng, ntraj, tlist, _mcsolve_prob_func) : prob_func
239239
_output_func =
240240
output_func isa Nothing ?
@@ -261,7 +261,7 @@ function mcsolveEnsembleProblem(
261261
ensemble_prob = TimeEvolutionProblem(
262262
EnsembleProblem(prob_mc.prob, prob_func = _prob_func, output_func = _output_func[1], safetycopy = false),
263263
prob_mc.times,
264-
ST(),
264+
prob_mc.states_type,
265265
prob_mc.dimensions,
266266
(progr = _output_func[2], channel = _output_func[3]),
267267
)
@@ -375,7 +375,7 @@ function mcsolve(
375375
keep_runs_results::Union{Val,Bool} = Val(false),
376376
normalize_states::Union{Val,Bool} = Val(true),
377377
kwargs...,
378-
) where {TJC<:LindbladJumpCallbackType} where {ST<:Union{Ket,Operator}}
378+
) where {ST<:Union{Ket,Operator}, TJC<:LindbladJumpCallbackType}
379379
ens_prob_mc = mcsolveEnsembleProblem(
380380
H,
381381
ψ0,

src/time_evolution/mesolve.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,16 @@ function mesolveProblem(
114114
# end
115115
if isoper(ψ0)
116116
ρ0 = to_dense(_complex_float_type(T), mat2vec(ψ0.data))
117-
state_type = Operator()
117+
states_type = Operator()
118118
elseif isoperket(ψ0)
119119
ρ0 = to_dense(_complex_float_type(T), copy(ψ0.data))
120-
state_type = OperatorKet()
120+
states_type = OperatorKet()
121121
elseif isket(ψ0)
122122
ρ0 = to_dense(_complex_float_type(T), mat2vec(ket2dm(ψ0).data))
123-
state_type = Operator()
123+
states_type = Operator()
124124
elseif issuper(ψ0)
125125
ρ0 = to_dense(_complex_float_type(T), copy(ψ0.data))
126-
state_type = SuperOperator()
126+
states_type = SuperOperator()
127127
end
128128

129129
L = cache_operator(L_evo.data, ρ0)
@@ -136,7 +136,7 @@ function mesolveProblem(
136136

137137
prob = ODEProblem{getVal(inplace),FullSpecialize}(L, ρ0, tspan, params; kwargs4...)
138138

139-
return TimeEvolutionProblem(prob, tlist, state_type, L_evo.dimensions)
139+
return TimeEvolutionProblem(prob, tlist, states_type, L_evo.dimensions)
140140
end
141141

142142
@doc raw"""
@@ -398,7 +398,7 @@ function mesolve_map(
398398
ens_prob = TimeEvolutionProblem(
399399
EnsembleProblem(prob.prob, prob_func = _prob_func, output_func = _output_func[1], safetycopy = false),
400400
prob.times,
401-
StateOpType(),
401+
prob.states_type,
402402
prob.dimensions,
403403
(progr = _output_func[2], channel = _output_func[3]),
404404
)

src/time_evolution/sesolve.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ function sesolveProblem(
7373
throw(ArgumentError("The keyword argument \"save_idxs\" is not supported in QuantumToolbox."))
7474

7575
tlist = _check_tlist(tlist, _float_type(ψ0))
76+
states_type = ψ0.type
7677

7778
H_evo = _sesolve_make_U_QobjEvo(H) # Multiply by -i
7879
isoper(H_evo) || throw(ArgumentError("The Hamiltonian must be an Operator."))
@@ -90,7 +91,7 @@ function sesolveProblem(
9091

9192
prob = ODEProblem{getVal(inplace),FullSpecialize}(U, ψ0, tspan, params; kwargs4...)
9293

93-
return TimeEvolutionProblem(prob, tlist, ST(), H_evo.dimensions)
94+
return TimeEvolutionProblem(prob, tlist, states_type, H_evo.dimensions)
9495
end
9596

9697
@doc raw"""

src/time_evolution/smesolve.jl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,12 @@ function smesolveProblem(
108108
dims = L_evo.dimensions
109109

110110
T = Base.promote_eltype(L_evo, ψ0)
111-
ρ0 = if isoperket(ψ0) # Convert it to dense vector with complex element type
112-
to_dense(_complex_float_type(T), copy(ψ0.data))
111+
if isoperket(ψ0) # Convert it to dense vector with complex element type
112+
ρ0 = to_dense(_complex_float_type(T), copy(ψ0.data))
113+
states_type = OperatorKet()
113114
else
114-
to_dense(_complex_float_type(T), mat2vec(ket2dm(ψ0).data))
115+
ρ0 = to_dense(_complex_float_type(T), mat2vec(ket2dm(ψ0).data))
116+
states_type = Operator()
115117
end
116118

117119
sc_ops_evo_data = Tuple(map(get_data QobjEvo, sc_ops_list))
@@ -153,7 +155,7 @@ function smesolveProblem(
153155
kwargs4...,
154156
)
155157

156-
return TimeEvolutionProblem(prob, tlist,StateOpType(), dims, ())
158+
return TimeEvolutionProblem(prob, tlist, states_type, dims, ())
157159
end
158160

159161
@doc raw"""
@@ -281,7 +283,7 @@ function smesolveEnsembleProblem(
281283
ensemble_prob = TimeEvolutionProblem(
282284
EnsembleProblem(prob_sme, prob_func = _prob_func, output_func = _output_func[1], safetycopy = true),
283285
prob_sme.times,
284-
StateOpType(),
286+
prob_sme.states_type,
285287
prob_sme.dimensions,
286288
(progr = _output_func[2], channel = _output_func[3]),
287289
)

src/time_evolution/ssesolve.jl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ function ssesolveProblem(
9595
sc_ops_isa_Qobj = sc_ops isa AbstractQuantumObject # We can avoid using non-diagonal noise if sc_ops is just an AbstractQuantumObject
9696

9797
tlist = _check_tlist(tlist, _float_type(ψ0))
98+
states_type = ψ0.type
9899

99100
H_eff_evo = _mcsolve_make_Heff_QobjEvo(H, sc_ops_list)
100101
isoper(H_eff_evo) || throw(ArgumentError("The Hamiltonian must be an Operator."))
@@ -142,7 +143,7 @@ function ssesolveProblem(
142143
kwargs4...,
143144
)
144145

145-
return TimeEvolutionProblem(prob, tlist, ST(), dims)
146+
return TimeEvolutionProblem(prob, tlist, states_type, dims)
146147
end
147148

148149
@doc raw"""
@@ -252,7 +253,7 @@ function ssesolveEnsembleProblem(
252253
progr_desc = "[ssesolve] ",
253254
) : output_func
254255

255-
prob_sme = ssesolveProblem(
256+
prob_sse = ssesolveProblem(
256257
H,
257258
ψ0,
258259
tlist,
@@ -266,10 +267,10 @@ function ssesolveEnsembleProblem(
266267
)
267268

268269
ensemble_prob = TimeEvolutionProblem(
269-
EnsembleProblem(prob_sme, prob_func = _prob_func, output_func = _output_func[1], safetycopy = true),
270-
prob_sme.times,
271-
ST(),
272-
prob_sme.dimensions,
270+
EnsembleProblem(prob_sse, prob_func = _prob_func, output_func = _output_func[1], safetycopy = true),
271+
prob_sse.times,
272+
prob_sse.states_type,
273+
prob_sse.dimensions,
273274
(progr = _output_func[2], channel = _output_func[3]),
274275
)
275276

0 commit comments

Comments
 (0)