Skip to content

Commit 38351c8

Browse files
authored
Simplify type structure for time evolution solutions (#572)
1 parent a3d7a36 commit 38351c8

File tree

3 files changed

+21
-23
lines changed

3 files changed

+21
-23
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
- Introduce new methods of `sesolve_map` and `mesolve_map` for advanced usage. Users can now customize their own `iter`ator structure, `prob_func` and `output_func`. ([#565])
1111
- Use `ProgressMeter.jl` for progress bar rather than our in-house implementation. ([#569])
12+
- Simplify type structure for time evolution solutions. ([#572])
1213

1314
## [v0.37.0]
1415
Release date: 2025-10-12
@@ -341,3 +342,4 @@ Release date: 2024-11-13
341342
[#557]: https://github.com/qutip/QuantumToolbox.jl/issues/557
342343
[#565]: https://github.com/qutip/QuantumToolbox.jl/issues/565
343344
[#569]: https://github.com/qutip/QuantumToolbox.jl/issues/569
345+
[#572]: https://github.com/qutip/QuantumToolbox.jl/issues/572

src/time_evolution/lr_mesolve.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ struct TimeEvolutionLRSol{
2626
TE<:Matrix{ComplexF64},
2727
RetT<:Enum,
2828
AlgT<:OrdinaryDiffEqAlgorithm,
29-
AT<:Real,
30-
RT<:Real,
29+
TolT<:Real,
3130
TSZB<:AbstractVector,
3231
TM<:Vector{<:Integer},
3332
}
@@ -38,8 +37,8 @@ struct TimeEvolutionLRSol{
3837
fexpect::TE
3938
retcode::RetT
4039
alg::AlgT
41-
abstol::AT
42-
reltol::RT
40+
abstol::TolT
41+
reltol::TolT
4342
z::TSZB
4443
B::TSZB
4544
M::TM

src/time_evolution/time_evolution.jl

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,16 @@ struct TimeEvolutionSol{
6666
TE<:Union{AbstractMatrix,Nothing},
6767
RETT<:Enum,
6868
AlgT<:OrdinaryDiffEqAlgorithm,
69-
AT<:Real,
70-
RT<:Real,
69+
TolT<:Real,
7170
}
7271
times::TT1
7372
times_states::TT2
7473
states::TS
7574
expect::TE
7675
retcode::RETT
7776
alg::AlgT
78-
abstol::AT
79-
reltol::RT
77+
abstol::TolT
78+
reltol::TolT
8079
end
8180

8281
function Base.show(io::IO, sol::TimeEvolutionSol)
@@ -140,8 +139,7 @@ struct TimeEvolutionMCSol{
140139
TJT<:Vector{<:Vector{<:Real}},
141140
TJW<:Vector{<:Vector{<:Integer}},
142141
AlgT<:OrdinaryDiffEqAlgorithm,
143-
AT<:Real,
144-
RT<:Real,
142+
TolT<:Real,
145143
} <: TimeEvolutionMultiTrajSol{TS,TE}
146144
ntraj::Int
147145
times::TT1
@@ -152,8 +150,8 @@ struct TimeEvolutionMCSol{
152150
col_which::TJW
153151
converged::Bool
154152
alg::AlgT
155-
abstol::AT
156-
reltol::RT
153+
abstol::TolT
154+
reltol::TolT
157155
end
158156

159157
function Base.show(io::IO, sol::TimeEvolutionMCSol)
@@ -215,8 +213,7 @@ struct TimeEvolutionStochasticSol{
215213
TE<:Union{AbstractArray,Nothing},
216214
TEM<:Union{AbstractArray,Nothing},
217215
AlgT<:StochasticDiffEqAlgorithm,
218-
AT<:Real,
219-
RT<:Real,
216+
TolT<:Real,
220217
} <: TimeEvolutionMultiTrajSol{TS,TE}
221218
ntraj::Int
222219
times::TT1
@@ -226,8 +223,8 @@ struct TimeEvolutionStochasticSol{
226223
measurement::TEM
227224
converged::Bool
228225
alg::AlgT
229-
abstol::AT
230-
reltol::RT
226+
abstol::TolT
227+
reltol::TolT
231228
end
232229

233230
function Base.show(io::IO, sol::TimeEvolutionStochasticSol)
@@ -408,33 +405,33 @@ function _ensemble_dispatch_prob_func(rng, ntraj, tlist, prob_func; kwargs...)
408405
end
409406

410407
function _ensemble_dispatch_solve(
411-
ens_prob_mc::TimeEvolutionProblem,
408+
ens_prob::TimeEvolutionProblem,
412409
alg::Union{<:OrdinaryDiffEqAlgorithm,<:StochasticDiffEqAlgorithm},
413410
ensemblealg::ET,
414411
ntraj::Int,
415412
) where {ET<:Union{EnsembleSplitThreads,EnsembleDistributed}}
416413
sol = nothing
417414

418415
@sync begin
419-
@async while take!(ens_prob_mc.kwargs.channel)
420-
next!(ens_prob_mc.kwargs.progr)
416+
@async while take!(ens_prob.kwargs.channel)
417+
next!(ens_prob.kwargs.progr)
421418
end
422419

423420
@async begin
424-
sol = solve(ens_prob_mc.prob, alg, ensemblealg, trajectories = ntraj)
425-
put!(ens_prob_mc.kwargs.channel, false)
421+
sol = solve(ens_prob.prob, alg, ensemblealg, trajectories = ntraj)
422+
put!(ens_prob.kwargs.channel, false)
426423
end
427424
end
428425

429426
return sol
430427
end
431428
function _ensemble_dispatch_solve(
432-
ens_prob_mc::TimeEvolutionProblem,
429+
ens_prob::TimeEvolutionProblem,
433430
alg::Union{<:OrdinaryDiffEqAlgorithm,<:StochasticDiffEqAlgorithm},
434431
ensemblealg,
435432
ntraj::Int,
436433
)
437-
sol = solve(ens_prob_mc.prob, alg, ensemblealg, trajectories = ntraj)
434+
sol = solve(ens_prob.prob, alg, ensemblealg, trajectories = ntraj)
438435
return sol
439436
end
440437

0 commit comments

Comments
 (0)