Skip to content

Commit dd3b340

Browse files
author
cailixun
committed
change default ode solver
1 parent 0846c9e commit dd3b340

File tree

10 files changed

+46
-46
lines changed

10 files changed

+46
-46
lines changed

Project.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "QuantumToolbox"
22
uuid = "6c2fb7c5-b903-41d2-bc5e-5a7c320b9fab"
3-
version = "0.38.1"
43
authors = ["Alberto Mercurio", "Yi-Te Huang"]
4+
version = "0.38.1"
55

66
[deps]
77
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
@@ -16,7 +16,7 @@ LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
1616
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1717
LinearSolve = "7ed4a6bd-45f5-4d41-b270-4a48e9bafcae"
1818
OrdinaryDiffEqCore = "bbf590c4-e513-4bbe-9b18-05decba2e5d8"
19-
OrdinaryDiffEqTsit5 = "b1df2697-797e-41e3-8120-5422d3b24e4a"
19+
OrdinaryDiffEqVerner = "79d7bb75-1356-48c1-b8c0-6832512096c2"
2020
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
2121
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"
2222
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
@@ -59,7 +59,7 @@ LinearAlgebra = "1"
5959
LinearSolve = "2, 3"
6060
Makie = "0.24"
6161
OrdinaryDiffEqCore = "1"
62-
OrdinaryDiffEqTsit5 = "1"
62+
OrdinaryDiffEqVerner = "1.5.0"
6363
Pkg = "1"
6464
ProgressMeter = "1.11.0"
6565
Random = "1"

src/QuantumToolbox.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ import SciMLBase:
3232
DiscreteCallback,
3333
AbstractSciMLProblem,
3434
AbstractODEIntegrator,
35-
AbstractODESolution
35+
AbstractODESolution,
36+
AbstractODEAlgorithm
3637
import StochasticDiffEq: StochasticDiffEqAlgorithm, SRA2, SRIW1
3738
import SciMLOperators:
3839
cache_operator,
@@ -51,8 +52,7 @@ import LinearSolve:
5152
SciMLLinearSolveAlgorithm, KrylovJL_MINRES, KrylovJL_GMRES, UMFPACKFactorization, OperatorAssumptions
5253
import DiffEqBase: get_tstops
5354
import DiffEqCallbacks: PeriodicCallback, FunctionCallingCallback, FunctionCallingAffect, TerminateSteadyState
54-
import OrdinaryDiffEqCore: OrdinaryDiffEqAlgorithm
55-
import OrdinaryDiffEqTsit5: Tsit5
55+
import OrdinaryDiffEqVerner: Vern7
5656
import DiffEqNoiseProcess: RealWienerProcess!, RealWienerProcess
5757

5858
# other dependencies (in alphabetical order)

src/qobj/eigsolve.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ end
422422
H::Union{AbstractQuantumObject{HOpType},Tuple},
423423
T::Real,
424424
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
425-
alg::OrdinaryDiffEqAlgorithm = Tsit5(),
425+
alg::AbstractODEAlgorithm = Vern7(),
426426
params::NamedTuple = NamedTuple(),
427427
ρ0::AbstractMatrix = rand_dm(prod(H.dimensions)).data,
428428
eigvals::Int = 1,
@@ -440,7 +440,7 @@ Solve the eigenvalue problem for a Liouvillian superoperator `L` using the Arnol
440440
- `H`: The Hamiltonian (or directly the Liouvillian) of the system. It can be a [`QuantumObject`](@ref), a [`QuantumObjectEvolution`](@ref), or a tuple of the form supported by [`mesolve`](@ref).
441441
- `T`: The time at which to evaluate the time evolution.
442442
- `c_ops`: A vector of collapse operators. Default is `nothing` meaning the system is closed.
443-
- `alg`: The differential equation solver algorithm. Default is `Tsit5()`.
443+
- `alg`: The differential equation solver algorithm. Default is `Vern7()`.
444444
- `params`: A `NamedTuple` containing the parameters of the system.
445445
- `ρ0`: The initial density matrix. If not specified, a random density matrix is used.
446446
- `eigvals`: The number of eigenvalues to compute.
@@ -465,7 +465,7 @@ function eigsolve_al(
465465
H::Union{AbstractQuantumObject{HOpType},Tuple},
466466
T::Real,
467467
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
468-
alg::OrdinaryDiffEqAlgorithm = Tsit5(),
468+
alg::AbstractODEAlgorithm = Vern7(),
469469
params::NamedTuple = NamedTuple(),
470470
ρ0::AbstractMatrix = rand_dm(prod(H.dimensions)).data,
471471
eigvals::Int = 1,

src/steadystate.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ end
4444

4545
@doc raw"""
4646
SteadyStateODESolver(
47-
alg = Tsit5(),
47+
alg = Vern7(),
4848
ψ0 = nothing,
4949
tmax = Inf,
5050
terminate_reltol = 1e-4,
@@ -66,7 +66,7 @@ or
6666
```
6767
6868
# Arguments
69-
- `alg::OrdinaryDiffEqAlgorithm=Tsit5()`: The algorithm to solve the ODE.
69+
- `alg::AbstractODEAlgorithm=Vern7()`: The algorithm to solve the ODE.
7070
- `ψ0::Union{Nothing,QuantumObject}=nothing`: The initial state of the system. If not specified, a random pure state will be generated.
7171
- `tmax::Real=Inf`: The final time step for the steady state problem.
7272
- `terminate_reltol` = The relative tolerance for stationary state terminate condition. Default to `1e-4`.
@@ -78,13 +78,13 @@ or
7878
For more details about the solving `alg`orithms, please refer to [`OrdinaryDiffEq.jl`](https://docs.sciml.ai/OrdinaryDiffEq/stable/).
7979
"""
8080
Base.@kwdef struct SteadyStateODESolver{
81-
MT<:OrdinaryDiffEqAlgorithm,
81+
MT<:AbstractODEAlgorithm,
8282
ST<:Union{Nothing,QuantumObject},
8383
TT<:Real,
8484
RT<:Real,
8585
AT<:Real,
8686
} <: SteadyStateSolver
87-
alg::MT = Tsit5()
87+
alg::MT = Vern7()
8888
ψ0::ST = nothing
8989
tmax::TT = Inf
9090
terminate_reltol::RT = 1e-4

src/time_evolution/lr_mesolve.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ struct TimeEvolutionLRSol{
2525
TS<:AbstractVector,
2626
TE<:Matrix{ComplexF64},
2727
RetT<:Enum,
28-
AlgT<:OrdinaryDiffEqAlgorithm,
28+
AlgT<:AbstractODEAlgorithm,
2929
TolT<:Real,
3030
TSZB<:AbstractVector,
3131
TM<:Vector{<:Integer},
@@ -45,7 +45,7 @@ struct TimeEvolutionLRSol{
4545
end
4646

4747
lr_mesolve_options_default = (
48-
alg = Tsit5(),
48+
alg = Vern7(),
4949
progress = true,
5050
err_max = 0.0,
5151
p0 = 0.0,

src/time_evolution/mcsolve.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ end
274274
ψ0::QuantumObject{Ket},
275275
tlist::AbstractVector,
276276
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
277-
alg::OrdinaryDiffEqAlgorithm = Tsit5(),
277+
alg::AbstractODEAlgorithm = Vern7(),
278278
e_ops::Union{Nothing,AbstractVector,Tuple} = nothing,
279279
params = NullParameters(),
280280
rng::AbstractRNG = default_rng(),
@@ -329,7 +329,7 @@ If the environmental measurements register a quantum jump, the wave function und
329329
- `ψ0`: Initial state of the system ``|\psi(0)\rangle``.
330330
- `tlist`: List of time points at which to save either the state or the expectation values of the system.
331331
- `c_ops`: List of collapse operators ``\{\hat{C}_n\}_n``. It can be either a `Vector` or a `Tuple`.
332-
- `alg`: The algorithm to use for the ODE solver. Default to `Tsit5()`.
332+
- `alg`: The algorithm to use for the ODE solver. Default to `Vern7()`.
333333
- `e_ops`: List of operators for which to calculate expectation values. It can be either a `Vector` or a `Tuple`.
334334
- `params`: Parameters to pass to the solver. This argument is usually expressed as a `NamedTuple` or `AbstractVector` of parameters. For more advanced usage, any custom struct can be used.
335335
- `rng`: Random number generator for reproducibility.
@@ -361,7 +361,7 @@ function mcsolve(
361361
ψ0::QuantumObject{Ket},
362362
tlist::AbstractVector,
363363
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
364-
alg::OrdinaryDiffEqAlgorithm = Tsit5(),
364+
alg::AbstractODEAlgorithm = Vern7(),
365365
e_ops::Union{Nothing,AbstractVector,Tuple} = nothing,
366366
params = NullParameters(),
367367
rng::AbstractRNG = default_rng(),
@@ -398,7 +398,7 @@ end
398398

399399
function mcsolve(
400400
ens_prob_mc::TimeEvolutionProblem,
401-
alg::OrdinaryDiffEqAlgorithm = Tsit5(),
401+
alg::AbstractODEAlgorithm = Vern7(),
402402
ntraj::Int = 500,
403403
ensemblealg::EnsembleAlgorithm = EnsembleThreads(),
404404
keep_runs_results = Val(false),

src/time_evolution/mesolve.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ end
129129
ψ0::QuantumObject,
130130
tlist::AbstractVector,
131131
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
132-
alg::OrdinaryDiffEqAlgorithm = Tsit5(),
132+
alg::AbstractODEAlgorithm = Vern7(),
133133
e_ops::Union{Nothing,AbstractVector,Tuple} = nothing,
134134
params = NullParameters(),
135135
progress_bar::Union{Val,Bool} = Val(true),
@@ -155,7 +155,7 @@ where
155155
- `ψ0`: Initial state of the system ``|\psi(0)\rangle``. It can be either a [`Ket`](@ref), [`Operator`](@ref) or [`OperatorKet`](@ref).
156156
- `tlist`: List of time points at which to save either the state or the expectation values of the system.
157157
- `c_ops`: List of collapse operators ``\{\hat{C}_n\}_n``. It can be either a `Vector` or a `Tuple`.
158-
- `alg`: The algorithm for the ODE solver. The default value is `Tsit5()`.
158+
- `alg`: The algorithm for the ODE solver. The default value is `Vern7()`.
159159
- `e_ops`: List of operators for which to calculate expectation values. It can be either a `Vector` or a `Tuple`.
160160
- `params`: Parameters to pass to the solver. This argument is usually expressed as a `NamedTuple` or `AbstractVector` of parameters. For more advanced usage, any custom struct can be used.
161161
- `progress_bar`: Whether to show the progress bar. Using non-`Val` types might lead to type instabilities.
@@ -180,7 +180,7 @@ function mesolve(
180180
ψ0::QuantumObject{StateOpType},
181181
tlist::AbstractVector,
182182
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
183-
alg::OrdinaryDiffEqAlgorithm = Tsit5(),
183+
alg::AbstractODEAlgorithm = Vern7(),
184184
e_ops::Union{Nothing,AbstractVector,Tuple} = nothing,
185185
params = NullParameters(),
186186
progress_bar::Union{Val,Bool} = Val(true),
@@ -225,7 +225,7 @@ function mesolve(
225225
end
226226
end
227227

228-
function mesolve(prob::TimeEvolutionProblem, alg::OrdinaryDiffEqAlgorithm = Tsit5(); kwargs...)
228+
function mesolve(prob::TimeEvolutionProblem, alg::AbstractODEAlgorithm = Vern7(); kwargs...)
229229
sol = solve(prob.prob, alg; kwargs...)
230230

231231
return _gen_mesolve_solution(sol, prob.times, prob.dimensions, prob.kwargs.isoperket)
@@ -237,7 +237,7 @@ end
237237
ψ0::Union{QuantumObject,AbstractVector{<:QuantumObject}},
238238
tlist::AbstractVector,
239239
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
240-
alg::OrdinaryDiffEqAlgorithm = Tsit5(),
240+
alg::AbstractODEAlgorithm = Vern7(),
241241
ensemblealg::EnsembleAlgorithm = EnsembleThreads(),
242242
e_ops::Union{Nothing,AbstractVector,Tuple} = nothing,
243243
params::Union{NullParameters,Tuple} = NullParameters(),
@@ -267,7 +267,7 @@ for each combination in the ensemble.
267267
- `ψ0`: Initial state(s) of the system. Can be a single [`QuantumObject`](@ref) or a `Vector` of initial states. It can be either a [`Ket`](@ref), [`Operator`](@ref) or [`OperatorKet`](@ref).
268268
- `tlist`: List of time points at which to save either the state or the expectation values of the system.
269269
- `c_ops`: List of collapse operators ``\{\hat{C}_n\}_n``. It can be either a `Vector` or a `Tuple`.
270-
- `alg`: The algorithm for the ODE solver. The default is `Tsit5()`.
270+
- `alg`: The algorithm for the ODE solver. The default is `Vern7()`.
271271
- `ensemblealg`: Ensemble algorithm to use for parallel computation. Default is `EnsembleThreads()`.
272272
- `e_ops`: List of operators for which to calculate expectation values. It can be either a `Vector` or a `Tuple`.
273273
- `params`: A `Tuple` of parameter sets. Each element should be an `AbstractVector` representing the sweep range for that parameter. The function will solve for all combinations of initial states and parameter sets.
@@ -290,7 +290,7 @@ function mesolve_map(
290290
ψ0::AbstractVector{<:QuantumObject{StateOpType}},
291291
tlist::AbstractVector,
292292
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
293-
alg::OrdinaryDiffEqAlgorithm = Tsit5(),
293+
alg::AbstractODEAlgorithm = Vern7(),
294294
ensemblealg::EnsembleAlgorithm = EnsembleThreads(),
295295
e_ops::Union{Nothing,AbstractVector,Tuple} = nothing,
296296
params::Union{NullParameters,Tuple} = NullParameters(),
@@ -357,7 +357,7 @@ mesolve_map(
357357
function mesolve_map(
358358
prob::TimeEvolutionProblem{<:ODEProblem},
359359
iter::AbstractArray,
360-
alg::OrdinaryDiffEqAlgorithm = Tsit5(),
360+
alg::AbstractODEAlgorithm = Vern7(),
361361
ensemblealg::EnsembleAlgorithm = EnsembleThreads();
362362
prob_func::Union{Function,Nothing} = nothing,
363363
output_func::Union{Tuple,Nothing} = nothing,

src/time_evolution/sesolve.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ end
9797
H::Union{AbstractQuantumObject{Operator},Tuple},
9898
ψ0::QuantumObject{Ket},
9999
tlist::AbstractVector;
100-
alg::OrdinaryDiffEqAlgorithm = Tsit5(),
100+
alg::AbstractODEAlgorithm = Vern7(lazy=false),
101101
e_ops::Union{Nothing,AbstractVector,Tuple} = nothing,
102102
params = NullParameters(),
103103
progress_bar::Union{Val,Bool} = Val(true),
@@ -116,7 +116,7 @@ Time evolution of a closed quantum system using the Schrödinger equation:
116116
- `H`: Hamiltonian of the system ``\hat{H}``. It can be either a [`QuantumObject`](@ref), a [`QuantumObjectEvolution`](@ref), or a `Tuple` of operator-function pairs.
117117
- `ψ0`: Initial state of the system ``|\psi(0)\rangle``.
118118
- `tlist`: List of time points at which to save either the state or the expectation values of the system.
119-
- `alg`: The algorithm for the ODE solver. The default is `Tsit5()`.
119+
- `alg`: The algorithm for the ODE solver. The default is `Vern7(lazy=false)`.
120120
- `e_ops`: List of operators for which to calculate expectation values. It can be either a `Vector` or a `Tuple`.
121121
- `params`: Parameters to pass to the solver. This argument is usually expressed as a `NamedTuple` or `AbstractVector` of parameters. For more advanced usage, any custom struct can be used.
122122
- `progress_bar`: Whether to show the progress bar. Using non-`Val` types might lead to type instabilities.
@@ -139,7 +139,7 @@ function sesolve(
139139
H::Union{AbstractQuantumObject{Operator},Tuple},
140140
ψ0::QuantumObject{Ket},
141141
tlist::AbstractVector;
142-
alg::OrdinaryDiffEqAlgorithm = Tsit5(),
142+
alg::AbstractODEAlgorithm = Vern7(lazy=false),
143143
e_ops::Union{Nothing,AbstractVector,Tuple} = nothing,
144144
params = NullParameters(),
145145
progress_bar::Union{Val,Bool} = Val(true),
@@ -171,7 +171,7 @@ function sesolve(
171171
end
172172
end
173173

174-
function sesolve(prob::TimeEvolutionProblem, alg::OrdinaryDiffEqAlgorithm = Tsit5(); kwargs...)
174+
function sesolve(prob::TimeEvolutionProblem, alg::AbstractODEAlgorithm = Vern7(lazy=false); kwargs...)
175175
sol = solve(prob.prob, alg; kwargs...)
176176

177177
return _gen_sesolve_solution(sol, prob.times, prob.dimensions)
@@ -182,7 +182,7 @@ end
182182
H::Union{AbstractQuantumObject{Operator},Tuple},
183183
ψ0::Union{QuantumObject{Ket},AbstractVector{<:QuantumObject{Ket}}},
184184
tlist::AbstractVector;
185-
alg::OrdinaryDiffEqAlgorithm = Tsit5(),
185+
alg::AbstractODEAlgorithm = Vern7(lazy=false),
186186
ensemblealg::EnsembleAlgorithm = EnsembleThreads(),
187187
e_ops::Union{Nothing,AbstractVector,Tuple} = nothing,
188188
params::Union{NullParameters,Tuple} = NullParameters(),
@@ -205,7 +205,7 @@ for each combination in the ensemble.
205205
- `H`: Hamiltonian of the system ``\hat{H}``. It can be either a [`QuantumObject`](@ref), a [`QuantumObjectEvolution`](@ref), or a `Tuple` of operator-function pairs.
206206
- `ψ0`: Initial state(s) of the system. Can be a single [`QuantumObject`](@ref) or a `Vector` of initial states.
207207
- `tlist`: List of time points at which to save either the state or the expectation values of the system.
208-
- `alg`: The algorithm for the ODE solver. The default is `Tsit5()`.
208+
- `alg`: The algorithm for the ODE solver. The default is `Vern7(lazy=false)`.
209209
- `ensemblealg`: Ensemble algorithm to use for parallel computation. Default is `EnsembleThreads()`.
210210
- `e_ops`: List of operators for which to calculate expectation values. It can be either a `Vector` or a `Tuple`.
211211
- `params`: A `Tuple` of parameter sets. Each element should be an `AbstractVector` representing the sweep range for that parameter. The function will solve for all combinations of initial states and parameter sets.
@@ -226,7 +226,7 @@ function sesolve_map(
226226
H::Union{AbstractQuantumObject{Operator},Tuple},
227227
ψ0::AbstractVector{<:QuantumObject{Ket}},
228228
tlist::AbstractVector;
229-
alg::OrdinaryDiffEqAlgorithm = Tsit5(),
229+
alg::AbstractODEAlgorithm = Vern7(lazy=false),
230230
ensemblealg::EnsembleAlgorithm = EnsembleThreads(),
231231
e_ops::Union{Nothing,AbstractVector,Tuple} = nothing,
232232
params::Union{NullParameters,Tuple} = NullParameters(),
@@ -266,7 +266,7 @@ sesolve_map(H::Union{AbstractQuantumObject{Operator},Tuple}, ψ0::QuantumObject{
266266
function sesolve_map(
267267
prob::TimeEvolutionProblem{<:ODEProblem},
268268
iter::AbstractArray,
269-
alg::OrdinaryDiffEqAlgorithm = Tsit5(),
269+
alg::AbstractODEAlgorithm = Vern7(lazy=false),
270270
ensemblealg::EnsembleAlgorithm = EnsembleThreads();
271271
prob_func::Union{Function,Nothing} = nothing,
272272
output_func::Union{Tuple,Nothing} = nothing,

src/time_evolution/time_evolution.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ struct TimeEvolutionSol{
6565
TS<:AbstractVector,
6666
TE<:Union{AbstractMatrix,Nothing},
6767
RETT<:Enum,
68-
AlgT<:OrdinaryDiffEqAlgorithm,
68+
AlgT<:AbstractODEAlgorithm,
6969
TolT<:Real,
7070
}
7171
times::TT1
@@ -138,7 +138,7 @@ struct TimeEvolutionMCSol{
138138
TE<:Union{AbstractArray,Nothing},
139139
TJT<:Vector{<:Vector{<:Real}},
140140
TJW<:Vector{<:Vector{<:Integer}},
141-
AlgT<:OrdinaryDiffEqAlgorithm,
141+
AlgT<:AbstractODEAlgorithm,
142142
TolT<:Real,
143143
} <: TimeEvolutionMultiTrajSol{TS,TE}
144144
ntraj::Int
@@ -406,7 +406,7 @@ end
406406

407407
function _ensemble_dispatch_solve(
408408
ens_prob::TimeEvolutionProblem,
409-
alg::Union{<:OrdinaryDiffEqAlgorithm,<:StochasticDiffEqAlgorithm},
409+
alg::Union{<:AbstractODEAlgorithm,<:StochasticDiffEqAlgorithm},
410410
ensemblealg::ET,
411411
ntraj::Int,
412412
) where {ET<:Union{EnsembleSplitThreads,EnsembleDistributed}}
@@ -427,7 +427,7 @@ function _ensemble_dispatch_solve(
427427
end
428428
function _ensemble_dispatch_solve(
429429
ens_prob::TimeEvolutionProblem,
430-
alg::Union{<:OrdinaryDiffEqAlgorithm,<:StochasticDiffEqAlgorithm},
430+
alg::Union{<:AbstractODEAlgorithm,<:StochasticDiffEqAlgorithm},
431431
ensemblealg,
432432
ntraj::Int,
433433
)

0 commit comments

Comments
 (0)