Skip to content

Commit 3e00302

Browse files
Add tests, changelog and format code
1 parent abaa9c2 commit 3e00302

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
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
- Fix Dynamical Fock Dimension states saving due to wrong saving of dimensions. ([#375])
1111
- Support a list of observables for `expect`. ([#374], [#376])
12+
- 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])
1213

1314
## [v0.25.0]
1415
Release date: 2025-01-20
@@ -89,3 +90,4 @@ Release date: 2024-11-13
8990
[#374]: https://github.com/qutip/QuantumToolbox.jl/issues/374
9091
[#375]: https://github.com/qutip/QuantumToolbox.jl/issues/375
9192
[#376]: https://github.com/qutip/QuantumToolbox.jl/issues/376
93+
[#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)