Skip to content

Commit 72600de

Browse files
ErikQQYKrastanov
andauthored
Switch to TestItems (#201)
--------- Co-authored-by: Stefan Krastanov <[email protected]> Co-authored-by: Stefan Krastanov <[email protected]>
1 parent a836f8d commit 72600de

36 files changed

+107
-90
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ FastGaussQuadrature = "0.5, 1"
2525
FillArrays = "0.13, 1"
2626
LRUCache = "1"
2727
LinearAlgebra = "1"
28-
QuantumInterface = "0.4.0"
28+
QuantumInterface = "0.4"
2929
Random = "1"
3030
RecursiveArrayTools = "3"
3131
SparseArrays = "1"

src/manybody.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,11 @@ function manybodyoperator_2(mb::ManyBodyBasis, op::Operator)
264264
return result
265265
end
266266

267-
function manybodyoperator_2(mb::ManyBodyBasis, op::SparseOpType)
267+
function manybodyoperator_2(mb::ManyBodyBasis, op::SparseOpAdjType)
268+
throw(ArgumentError("`manybodyoperator_2` is not implemented for adjoint operators yet, convert your operator to not contain adjoints of matrices by collecting."))
269+
end
270+
271+
function manybodyoperator_2(mb::ManyBodyBasis, op::SparseOpPureType)
268272
N = length(mb)
269273
S = length(mb.onebodybasis)
270274
Is = Int[]

src/spinors.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ function directsum(a::DataOperator, b::DataOperator)
4949
end
5050
function directsum(a::SparseOpType, b::SparseOpType)
5151
dType = promote_type(eltype(a),eltype(b))
52-
data = spzeros(dType, size(a,1)+size(b,1), size(a,2)+size(b,2))
53-
data[1:size(a,1),1:size(a,2)] = a.data
54-
data[size(a,1)+1:end, size(a,2)+1:end] = b.data
52+
data = spzeros(dType, size(a,1)::Int+size(b,1)::Int, size(a,2)::Int+size(b,2)::Int)
53+
data[1:size(a,1)::Int,1:size(a,2)::Int] = a.data
54+
data[size(a,1)::Int+1:end, size(a,2)::Int+1:end] = b.data
5555
return Operator(directsum(a.basis_l, b.basis_l), directsum(a.basis_r, b.basis_r), data)
5656
end
5757

src/states_lazyket.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Base.:(==)(x::LazyKet, y::LazyKet) = (x.basis == y.basis) && (x.kets == y.kets)
3232
Ket(ket::LazyKet) = (ket.kets...)
3333

3434
# no lazy bras for now
35-
dagger(x::LazyKet) = throw(MethodError("dagger not implemented for LazyKet: LazyBra is currently not implemented at all!"))
35+
dagger(x::LazyKet) = throw(MethodError(dagger, "dagger not implemented for LazyKet: LazyBra is currently not implemented at all!")) # TODO this should probably be an error hint instead
3636

3737
# tensor with other kets
3838
function tensor(x::LazyKet, y::Ket)
@@ -127,7 +127,7 @@ end
127127
function mul!(y::LazyKet{BL}, op::LazyTensor{BL, BR}, x::LazyKet{BR}, alpha, beta) where {BL, BR}
128128
iszero(beta) || throw("Error: cannot perform muladd operation on LazyKets since addition is not implemented. Convert them to dense kets using Ket(x) in order to perform muladd operations.")
129129

130-
iszero(alpha) && (_zero_op_mul!(y.kets[1].data, beta); return result)
130+
iszero(alpha) && (_zero_op_mul!(y.kets[1].data, beta); return y)
131131

132132
missing_index_allowed = samebases(op)
133133
(length(y.basis.bases) == length(x.basis.bases)) || throw(IncompatibleBases())

test/Project.toml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
[deps]
22
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
33
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
4-
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
4+
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
55
FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"
66
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
77
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
8-
LRUCache = "8ac3fa9e-de4c-5943-b1dc-09c6b5f20637"
98
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
109
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
1110
QuantumInterface = "5717a53b-5d69-4fa3-b976-0bf2f97ca1e5"
1211
QuantumOptics = "6e0679c1-51ea-5a7c-ac74-d61b76210b0c"
1312
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1413
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1514
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
16-
Strided = "5e0ebb24-38b0-5f93-81fe-25c709ecae67"
17-
StridedViews = "4db3bf67-4bd7-4b4e-b153-31dc3fb37143"
1815
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
16+
TestItemRunner = "f8b46487-2199-4994-9208-9a1283c18c0a"
1917
UnsafeArrays = "c4a57d5a-5b31-53a6-b365-19f8c011fbd6"

test/runtests.jl

Lines changed: 19 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,21 @@
1-
names = [
2-
"test_states.jl",
3-
4-
"test_operators.jl",
5-
"test_operators_dense.jl",
6-
"test_sparsematrix.jl",
7-
"test_operators_sparse.jl",
8-
"test_operators_lazytensor.jl",
9-
"test_operators_lazysum.jl",
10-
"test_operators_lazyproduct.jl",
11-
"test_time_dependent_operators.jl",
12-
13-
"test_fock.jl",
14-
"test_charge.jl",
15-
"test_spin.jl",
16-
"test_particle.jl",
17-
"test_manybody.jl",
18-
"test_nlevel.jl",
19-
"test_subspace.jl",
20-
"test_state_definitions.jl",
21-
22-
"test_sciml_broadcast_interfaces.jl",
23-
24-
"test_transformations.jl",
25-
26-
"test_metrics.jl",
27-
"test_embed.jl",
28-
29-
"test_superoperators.jl",
30-
31-
"test_pauli.jl",
32-
"test_spinors.jl",
33-
34-
"test_abstractdata.jl",
35-
36-
"test_printing.jl",
37-
38-
"test_apply.jl",
39-
40-
"test_aqua.jl",
41-
"test_jet.jl"
42-
]
43-
44-
detected_tests = filter(
45-
name->startswith(name, "test_") && endswith(name, ".jl"),
46-
readdir("."))
47-
48-
unused_tests = setdiff(detected_tests, names)
49-
if length(unused_tests) != 0
50-
error("The following tests are not used:\n", join(unused_tests, "\n"))
51-
end
52-
53-
unavailable_tests = setdiff(names, detected_tests)
54-
if length(unavailable_tests) != 0
55-
error("The following tests could not be found:\n", join(unavailable_tests, "\n"))
1+
using TestItemRunner
2+
using QuantumOpticsBase
3+
4+
# filter for the test
5+
testfilter = ti -> begin
6+
exclude = Symbol[]
7+
if get(ENV,"JET_TEST","")=="true"
8+
return :jet in ti.tags
9+
else
10+
push!(exclude, :jet)
11+
end
12+
if !(VERSION >= v"1.10")
13+
push!(exclude, :aqua)
14+
push!(exclude, :doctests)
15+
end
16+
17+
return all(!in(exclude), ti.tags)
5618
end
19+
println("Starting tests with $(Threads.nthreads()) threads out of `Sys.CPU_THREADS = $(Sys.CPU_THREADS)`...")
5720

58-
for name=names
59-
if startswith(name, "test_") && endswith(name, ".jl")
60-
include(name)
61-
end
62-
end
21+
@run_package_tests filter=testfilter

test/test_abstractdata.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@testitem "test_abstractdata" begin
12
using QuantumOpticsBase
23
using Test
34
using LinearAlgebra
@@ -524,3 +525,4 @@ QuantumOpticsBase.mul!(result,state,op,alpha,beta)
524525
@test D(result, alpha*state*op_ + beta*result_, 1e-9)
525526

526527
end # testset
528+
end

test/test_apply.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@testitem "test_apply" begin
12
using QuantumOpticsBase
23
using QuantumInterface
34
using Test
@@ -51,3 +52,4 @@ st2 = coherentstate(bf1, 0.3)
5152
@test_broken apply!(st1st2, [1], sOp1)
5253

5354
end #testset
55+
end

test/test_aqua.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@testitem "test_aqua" tags = [:aqua] begin
12
using Test
23
using QuantumOpticsBase
34
using Aqua
@@ -10,7 +11,8 @@ using StatsBase
1011
StatsBase.TestStat, StatsBase.:(==) , StatsBase.sort!],), # Due to https://github.com/JuliaStats/StatsBase.jl/issues/861
1112
piracies=(broken=true,)
1213
)
13-
# manual piracy check to exclude identityoperator
14-
pirates = [pirate for pirate in Aqua.Piracy.hunt(QuantumOpticsBase) if pirate.name [:identityoperator,:identitysuperoperator]]
14+
# manual piracy check to exclude QuantumInterface functions that construct QuantumOpticsBase operators (as QOB.jl takes priority over other users of QuantumInterface)
15+
pirates = [pirate for pirate in Aqua.Piracy.hunt(QuantumOpticsBase) if pirate.name [:identityoperator,:identitysuperoperator, :position]]
1516
@test isempty(pirates)
1617
end # testset
18+
end

test/test_charge.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@testitem "test_charge" begin
12
using Test
23
using QuantumOpticsBase
34

@@ -44,3 +45,4 @@ using QuantumOpticsBase
4445
end
4546

4647
end # testset
48+
end

0 commit comments

Comments
 (0)