Skip to content

Commit 6d2d0b6

Browse files
Add tests, changelog and format code
1 parent e89535f commit 6d2d0b6

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

CHANGELOG.md

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

88
## [Unreleased](https://github.com/qutip/QuantumToolbox.jl/tree/main)
99

10+
11+
- Add checks for `tlist` in time evolution solvers. The checks are to ensure that `tlist` is not empty, the elements are in increasing order, and the elements are unique. ([#378])
12+
1013
## [v0.25.0]
1114
Release date: 2025-01-20
1215

@@ -83,3 +86,4 @@ Release date: 2024-11-13
8386
[#360]: https://github.com/qutip/QuantumToolbox.jl/issues/360
8487
[#370]: https://github.com/qutip/QuantumToolbox.jl/issues/370
8588
[#371]: https://github.com/qutip/QuantumToolbox.jl/issues/371
89+
[#378]: https://github.com/qutip/QuantumToolbox.jl/issues/378

src/time_evolution/time_evolution.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@ struct DiscreteLindbladJumpCallback <: LindbladJumpCallbackType end
213213
ContinuousLindbladJumpCallback(; interp_points::Int = 10) = ContinuousLindbladJumpCallback(interp_points)
214214

215215
function _check_tlist(tlist, T::Type)
216-
217216
tlist = convert(Vector{T}, tlist) # Convert it to support GPUs and avoid type instabilities for OrdinaryDiffEq.jl
218217

219218
# Check if the list of times is not empty

test/core-test/time_evolution.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@
6363
"abstol = $(sol2.abstol)\n" *
6464
"reltol = $(sol2.reltol)\n"
6565

66+
tlist1 = Float64[]
67+
tlist2 = [0, 0.2, 0.1]
68+
tlist3 = [0, 0.1, 0.1, 0.2]
69+
@test_throws ArgumentError sesolve(H, ψ0, tlist1, progress_bar = Val(false))
70+
@test_throws ArgumentError sesolve(H, ψ0, tlist2, progress_bar = Val(false))
71+
@test_throws ArgumentError sesolve(H, ψ0, tlist3, progress_bar = Val(false))
72+
6673
@testset "Memory Allocations" begin
6774
allocs_tot = @allocations sesolve(H, ψ0, tlist, e_ops = e_ops, progress_bar = Val(false)) # Warm-up
6875
allocs_tot = @allocations sesolve(H, ψ0, tlist, e_ops = e_ops, progress_bar = Val(false))
@@ -190,6 +197,19 @@
190197
"abstol = $(sol_sse.abstol)\n" *
191198
"reltol = $(sol_sse.reltol)\n"
192199

200+
tlist1 = Float64[]
201+
tlist2 = [0, 0.2, 0.1]
202+
tlist3 = [0, 0.1, 0.1, 0.2]
203+
@test_throws ArgumentError mesolve(H, ψ0, tlist1, c_ops, progress_bar = Val(false))
204+
@test_throws ArgumentError mesolve(H, ψ0, tlist2, c_ops, progress_bar = Val(false))
205+
@test_throws ArgumentError mesolve(H, ψ0, tlist3, c_ops, progress_bar = Val(false))
206+
@test_throws ArgumentError mcsolve(H, ψ0, tlist1, c_ops, progress_bar = Val(false))
207+
@test_throws ArgumentError mcsolve(H, ψ0, tlist2, c_ops, progress_bar = Val(false))
208+
@test_throws ArgumentError mcsolve(H, ψ0, tlist3, c_ops, progress_bar = Val(false))
209+
@test_throws ArgumentError ssesolve(H, ψ0, tlist1, c_ops, progress_bar = Val(false))
210+
@test_throws ArgumentError ssesolve(H, ψ0, tlist2, c_ops, progress_bar = Val(false))
211+
@test_throws ArgumentError ssesolve(H, ψ0, tlist3, c_ops, progress_bar = Val(false))
212+
193213
# Time-Dependent Hamiltonian
194214
# ssesolve is slow to be run on CI. It is not removed from the test because it may be useful for testing in more powerful machines.
195215

0 commit comments

Comments
 (0)