Skip to content

Commit bf07897

Browse files
[no ci] Return sesolve when mesolve allows it
1 parent 2b5e86e commit bf07897

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/time_evolution/mesolve.jl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ where
4646
4747
- The states will be saved depend on the keyword argument `saveat` in `kwargs`.
4848
- If `e_ops` is empty, the default value of `saveat=tlist` (saving the states corresponding to `tlist`), otherwise, `saveat=[tlist[end]]` (only save the final state). You can also specify `e_ops` and `saveat` separately.
49+
- If `H` is an [`OperatorQuantumObject`](@ref), `ψ0` is a [`KetQuantumObject`](@ref) and `c_ops` is `Nothing`, the function will call [`sesolveProblem`](@ref) instead.
4950
- The default tolerances in `kwargs` are given as `reltol=1e-6` and `abstol=1e-8`.
5051
- For more details about `kwargs` please refer to [`DifferentialEquations.jl` (Keyword Arguments)](https://docs.sciml.ai/DiffEqDocs/stable/basics/common_solver_opts/)
5152
@@ -67,6 +68,17 @@ function mesolveProblem(
6768
HOpType<:Union{OperatorQuantumObject,SuperOperatorQuantumObject},
6869
StateOpType<:Union{KetQuantumObject,OperatorQuantumObject,OperatorKetQuantumObject},
6970
}
71+
(isoper(H) && isket(ψ0) && isnothing(c_ops)) && return sesolveProblem(
72+
H,
73+
ψ0,
74+
tlist;
75+
e_ops = e_ops,
76+
params = params,
77+
progress_bar = progress_bar,
78+
inplace = inplace,
79+
kwargs...,
80+
)
81+
7082
haskey(kwargs, :save_idxs) &&
7183
throw(ArgumentError("The keyword argument \"save_idxs\" is not supported in QuantumToolbox."))
7284

@@ -141,6 +153,7 @@ where
141153
142154
- The states will be saved depend on the keyword argument `saveat` in `kwargs`.
143155
- If `e_ops` is empty, the default value of `saveat=tlist` (saving the states corresponding to `tlist`), otherwise, `saveat=[tlist[end]]` (only save the final state). You can also specify `e_ops` and `saveat` separately.
156+
- If `H` is an [`OperatorQuantumObject`](@ref), `ψ0` is a [`KetQuantumObject`](@ref) and `c_ops` is `Nothing`, the function will call [`sesolveProblem`](@ref) instead.
144157
- The default tolerances in `kwargs` are given as `reltol=1e-6` and `abstol=1e-8`.
145158
- For more details about `alg` please refer to [`DifferentialEquations.jl` (ODE Solvers)](https://docs.sciml.ai/DiffEqDocs/stable/solvers/ode_solve/)
146159
- For more details about `kwargs` please refer to [`DifferentialEquations.jl` (Keyword Arguments)](https://docs.sciml.ai/DiffEqDocs/stable/basics/common_solver_opts/)
@@ -164,6 +177,18 @@ function mesolve(
164177
HOpType<:Union{OperatorQuantumObject,SuperOperatorQuantumObject},
165178
StateOpType<:Union{KetQuantumObject,OperatorQuantumObject,OperatorKetQuantumObject},
166179
}
180+
(isoper(H) && isket(ψ0) && isnothing(c_ops)) && return sesolve(
181+
H,
182+
ψ0,
183+
tlist;
184+
alg = alg,
185+
e_ops = e_ops,
186+
params = params,
187+
progress_bar = progress_bar,
188+
inplace = inplace,
189+
kwargs...,
190+
)
191+
167192
prob = mesolveProblem(
168193
H,
169194
ψ0,

0 commit comments

Comments
 (0)