Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch tests to use TestItemRunner.jl #75

Merged
merged 3 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ QuantumOpticsBase = "4f57444f-1401-5e15-980d-4471b28d5678"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
SymbolicUtils = "d1185830-fcd6-423d-90d6-eec64667417b"
Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7"
TermInterface = "8ea1fca8-c5ef-4a55-8b96-4e9afe9c9a3c"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
TestItemRunner = "f8b46487-2199-4994-9208-9a1283c18c0a"
51 changes: 13 additions & 38 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,46 +1,21 @@
using SafeTestsets
using TestItemRunner
using QuantumSymbolics

function doset(descr)
if length(ARGS) == 0
return true
end
for a in ARGS
if occursin(lowercase(a), lowercase(descr))
return true
end
end
return false
end
# filter for the test
testfilter = ti -> begin
exclude = Symbol[:jet]
if !(VERSION >= v"1.10")
push!(exclude, :doctests)
push!(exclude, :aqua)
end

macro doset(descr)
quote
if doset($descr)
@safetestset $descr begin include("test_"*$descr*".jl") end
end
end
return all(!in(exclude), ti.tags)
end

println("Starting tests with $(Threads.nthreads()) threads out of `Sys.CPU_THREADS = $(Sys.CPU_THREADS)`...")

@doset "sym_expressions"
@doset "express_opt"
@doset "express_cliff"
@doset "qo"
@doset "qo_qc_interop"
@doset "basis_consistency"
@doset "superop"
@doset "conditional_cliffords"
@doset "commutator"
@doset "anticommutator"
@doset "dagger"
@doset "zero_obj"
@doset "trace"
@doset "expand"
@doset "misc_linalg"
@doset "throws"
@doset "pauli"
@run_package_tests filter=testfilter

VERSION >= v"1.9" && @doset "doctests"
get(ENV,"JET_TEST","")=="true" && @doset "jet"
VERSION >= v"1.9" && @doset "aqua"
if get(ENV,"JET_TEST","")=="true"
@run_package_tests filter=(ti -> :jet in ti.tags)
end
32 changes: 16 additions & 16 deletions test/test_anticommutator.jl
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
using QuantumSymbolics
using Test
@testitem "Anticommutator" begin

@op A; @op B;
@op A; @op B;

@testset "symbolic anticommutator tests" begin
@test isequal(anticommutator(2*A, B), anticommutator(A, 2*B)) && isequal(2*anticommutator(A, B), anticommutator(2*A, B)) && isequal(2*anticommutator(A, B), anticommutator(2*A, B))
end
@testset "symbolic anticommutator tests" begin
@test isequal(anticommutator(2*A, B), anticommutator(A, 2*B)) && isequal(2*anticommutator(A, B), anticommutator(2*A, B)) && isequal(2*anticommutator(A, B), anticommutator(2*A, B))
end

@testset "anticommutator Pauli tests" begin
@test isequal(qsimplify(anticommutator(X, X), rewriter=qsimplify_anticommutator), 2*I)
@test isequal(qsimplify(anticommutator(Y, Y), rewriter=qsimplify_anticommutator), 2*I)
@test isequal(qsimplify(anticommutator(Z, Z), rewriter=qsimplify_anticommutator), 2*I)
@test isequal(qsimplify(anticommutator(X, Y), rewriter=qsimplify_anticommutator), 0)
@test isequal(qsimplify(anticommutator(Y, X), rewriter=qsimplify_anticommutator), 0)
@test isequal(qsimplify(anticommutator(Y, Z), rewriter=qsimplify_anticommutator), 0)
@test isequal(qsimplify(anticommutator(Z, Y), rewriter=qsimplify_anticommutator), 0)
@test isequal(qsimplify(anticommutator(Z, X), rewriter=qsimplify_anticommutator), 0)
@test isequal(qsimplify(anticommutator(X, Z), rewriter=qsimplify_anticommutator), 0)
@testset "anticommutator Pauli tests" begin
@test isequal(qsimplify(anticommutator(X, X), rewriter=qsimplify_anticommutator), 2*I)
@test isequal(qsimplify(anticommutator(Y, Y), rewriter=qsimplify_anticommutator), 2*I)
@test isequal(qsimplify(anticommutator(Z, Z), rewriter=qsimplify_anticommutator), 2*I)
@test isequal(qsimplify(anticommutator(X, Y), rewriter=qsimplify_anticommutator), 0)
@test isequal(qsimplify(anticommutator(Y, X), rewriter=qsimplify_anticommutator), 0)
@test isequal(qsimplify(anticommutator(Y, Z), rewriter=qsimplify_anticommutator), 0)
@test isequal(qsimplify(anticommutator(Z, Y), rewriter=qsimplify_anticommutator), 0)
@test isequal(qsimplify(anticommutator(Z, X), rewriter=qsimplify_anticommutator), 0)
@test isequal(qsimplify(anticommutator(X, Z), rewriter=qsimplify_anticommutator), 0)
end
end
13 changes: 7 additions & 6 deletions test/test_aqua.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Aqua, QuantumSymbolics, Test

Aqua.test_all(QuantumSymbolics,
ambiguities=(;broken=true),
piracies=(;broken=true),
)
@testitem "Aqua" tags=[:aqua] begin
using Aqua
Aqua.test_all(QuantumSymbolics,
ambiguities=(;broken=true),
piracies=(;broken=true),
)
end
32 changes: 16 additions & 16 deletions test/test_basis_consistency.jl
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
using Test
using QuantumSymbolics
using QuantumOptics
@testitem "Basis consistency" begin
using QuantumOptics

@test express(Z*Z1) == express(Z1)
@test express(Z*Z2) == -express(Z2)
@test express(X*X1) == express(X1)
@test express(X*X2) == -express(X2)
@test express(Y*Y1) == express(Y1)
@test express(Y*Y2) == -express(Y2)
@test express(Pm*Z1) == express(Z2)
@test express(Pp*Z2) == express(Z1)
@test express(Pm*L0) == express(L1)
@test express(Pp*L1) == express(L0)
@test express(Z*Z1) == express(Z1)
@test express(Z*Z2) == -express(Z2)
@test express(X*X1) == express(X1)
@test express(X*X2) == -express(X2)
@test express(Y*Y1) == express(Y1)
@test express(Y*Y2) == -express(Y2)
@test express(Pm*Z1) == express(Z2)
@test express(Pp*Z2) == express(Z1)
@test express(Pm*L0) == express(L1)
@test express(Pp*L1) == express(L0)

@op A; @op B; @op C; @op O; @ket k;
@superop S; K = kraus(A, B, C);
@op A; @op B; @op C; @op O; @ket k;
@superop S; K = kraus(A, B, C);

@test basis(K) == basis(A)
@test basis(K) == basis(A)
end
29 changes: 14 additions & 15 deletions test/test_commutator.jl
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
using QuantumSymbolics
using Test
@testitem "Commutator" begin
@op A; @op B;

@op A; @op B;
@testset "symbolic commutator tests" begin
@test isequal(commutator(2*A, B), commutator(A, 2*B)) && isequal(2*commutator(A, B), commutator(2*A, B)) && isequal(commutator(A, 2*B), 2*commutator(A, B))
@test commutator(A, A) == SZeroOperator()
end

@testset "symbolic commutator tests" begin
@test isequal(commutator(2*A, B), commutator(A, 2*B)) && isequal(2*commutator(A, B), commutator(2*A, B)) && isequal(commutator(A, 2*B), 2*commutator(A, B))
@test commutator(A, A) == SZeroOperator()
@testset "commutator Pauli tests" begin
@test isequal(qsimplify(commutator(X, Y), rewriter=qsimplify_commutator), 2*im*Z)
@test isequal(qsimplify(commutator(Y, X), rewriter=qsimplify_commutator), -2*im*Z)
@test isequal(qsimplify(commutator(Y, Z), rewriter=qsimplify_commutator), 2*im*X)
@test isequal(qsimplify(commutator(Z, Y), rewriter=qsimplify_commutator), -2*im*X)
@test isequal(qsimplify(commutator(Z, X), rewriter=qsimplify_commutator), 2*im*Y)
@test isequal(qsimplify(commutator(X, Z), rewriter=qsimplify_commutator), -2*im*Y)
end
end

@testset "commutator Pauli tests" begin
@test isequal(qsimplify(commutator(X, Y), rewriter=qsimplify_commutator), 2*im*Z)
@test isequal(qsimplify(commutator(Y, X), rewriter=qsimplify_commutator), -2*im*Z)
@test isequal(qsimplify(commutator(Y, Z), rewriter=qsimplify_commutator), 2*im*X)
@test isequal(qsimplify(commutator(Z, Y), rewriter=qsimplify_commutator), -2*im*X)
@test isequal(qsimplify(commutator(Z, X), rewriter=qsimplify_commutator), 2*im*Y)
@test isequal(qsimplify(commutator(X, Z), rewriter=qsimplify_commutator), -2*im*Y)
end
24 changes: 12 additions & 12 deletions test/test_conditional_cliffords.jl
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using Test
using QuantumSymbolics
using QuantumClifford
using QuantumOpticsBase
using LinearAlgebra
@testitem "Conditional Cliffords" begin
using QuantumClifford
using QuantumOpticsBase
using LinearAlgebra

for control in (:X, :Y, :Z)
for target in (:X, :Y, :Z)
structname = Symbol(control,"C",target,"Gate")
gate = eval(structname)()
gate_qo = express(gate, QuantumOpticsRepr())
gate_qc = Operator(CliffordOperator(express(gate, CliffordRepr(), UseAsOperation())(1,2),2))
@test gate_qo ≈ gate_qc
for control in (:X, :Y, :Z)
for target in (:X, :Y, :Z)
structname = Symbol(control,"C",target,"Gate")
gate = eval(structname)()
gate_qo = express(gate, QuantumOpticsRepr())
gate_qc = Operator(CliffordOperator(express(gate, CliffordRepr(), UseAsOperation())(1,2),2))
@test gate_qo ≈ gate_qc
end
end
end
54 changes: 27 additions & 27 deletions test/test_dagger.jl
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
using QuantumSymbolics
using QuantumInterface: AbstractOperator
using Test
@testitem "Dagger" begin
using QuantumInterface: AbstractOperator

@bra b₁; @bra b₂;
@ket k₁; @ket k₂;
@bra b₁; @bra b₂;
@ket k₁; @ket k₂;

@op A; @op B; @op C;
U = SUnitaryOperator(:U); ℋ = SHermitianOperator(:ℋ);
@op A; @op B; @op C;
U = SUnitaryOperator(:U); ℋ = SHermitianOperator(:ℋ);

@testset "symbolic dagger tests" begin
@test isequal(dagger(im*k₁), -im*dagger(k₁))
@test isequal(dagger(k₁+k₂), dagger(k₁)+dagger(k₂))
@test isequal(dagger(im*b₁), -im*dagger(b₁))
@test isequal(dagger(b₁+b₂), dagger(b₁)+dagger(b₂))
@test isequal(dagger(A+B), dagger(A) + dagger(B))
@test isequal(dagger(ℋ), ℋ)
@test isequal(dagger(U), inv(U))
@test isequal(dagger(b₁⊗b₂), dagger(b₁)⊗dagger(b₂))
@test isequal(dagger(k₁⊗k₂), dagger(k₁)⊗dagger(k₂))
@test isequal(dagger(A⊗B), dagger(A)⊗dagger(B))
@test isequal(dagger(im*A), -im*dagger(A))
@test isequal(dagger(A*k₁), dagger(k₁)*dagger(A))
@test isequal(dagger(b₁*A), dagger(A)*dagger(b₁))
@test isequal(dagger(A*B*C), dagger(C)*dagger(B)*dagger(A))
@test isequal(dagger(b₁*k₁), dagger(k₁)*dagger(b₁))
@test isequal(dagger(k₁*b₁), dagger(b₁)* dagger(k₁))
@test isequal(dagger(dagger(A)), A)
@test isequal(dagger(dagger(A)), A)
end
@testset "symbolic dagger tests" begin
@test isequal(dagger(im*k₁), -im*dagger(k₁))
@test isequal(dagger(k₁+k₂), dagger(k₁)+dagger(k₂))
@test isequal(dagger(im*b₁), -im*dagger(b₁))
@test isequal(dagger(b₁+b₂), dagger(b₁)+dagger(b₂))
@test isequal(dagger(A+B), dagger(A) + dagger(B))
@test isequal(dagger(ℋ), ℋ)
@test isequal(dagger(U), inv(U))
@test isequal(dagger(b₁⊗b₂), dagger(b₁)⊗dagger(b₂))
@test isequal(dagger(k₁⊗k₂), dagger(k₁)⊗dagger(k₂))
@test isequal(dagger(A⊗B), dagger(A)⊗dagger(B))
@test isequal(dagger(im*A), -im*dagger(A))
@test isequal(dagger(A*k₁), dagger(k₁)*dagger(A))
@test isequal(dagger(b₁*A), dagger(A)*dagger(b₁))
@test isequal(dagger(A*B*C), dagger(C)*dagger(B)*dagger(A))
@test isequal(dagger(b₁*k₁), dagger(k₁)*dagger(b₁))
@test isequal(dagger(k₁*b₁), dagger(b₁)* dagger(k₁))
@test isequal(dagger(dagger(A)), A)
@test isequal(dagger(dagger(A)), A)
end
end
20 changes: 7 additions & 13 deletions test/test_doctests.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
using Documenter
using QuantumSymbolics
using QuantumOptics
using QuantumClifford
using Test
@testitem "Doctests" tags=[:doctests] begin
using Documenter
using QuantumOptics
using QuantumClifford

function doctests()
@testset "Doctests" begin
DocMeta.setdocmeta!(QuantumSymbolics, :DocTestSetup, :(using QuantumSymbolics, QuantumOptics, QuantumClifford); recursive=true)
doctest(QuantumSymbolics)
end
end

doctests()
DocMeta.setdocmeta!(QuantumSymbolics, :DocTestSetup, :(using QuantumSymbolics, QuantumOptics, QuantumClifford); recursive=true)
doctest(QuantumSymbolics)
end
53 changes: 26 additions & 27 deletions test/test_expand.jl
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
using QuantumSymbolics
using Test
@testitem "Expand" begin
@bra b₁; @bra b₂; @bra b₃;
@ket k₁; @ket k₂; @ket k₃;

@bra b₁; @bra b₂; @bra b₃;
@ket k₁; @ket k₂; @ket k₃;
@op A; @op B; @op C; @op D;

@op A; @op B; @op C; @op D;
@testset "expand errors" begin
@test_throws ErrorException qexpand(X)
end

@testset "expand errors" begin
@test_throws ErrorException qexpand(X)
end

@testset "expand rules" begin
@test isequal(qexpand(commutator(A, B)), A*B - B*A)
@test isequal(qexpand(anticommutator(A, B)), A*B + B*A)
@testset "expand rules" begin
@test isequal(qexpand(commutator(A, B)), A*B - B*A)
@test isequal(qexpand(anticommutator(A, B)), A*B + B*A)

@test isequal(qexpand(A⊗(B+C+D)), A⊗B + A⊗C + A⊗D)
@test isequal(qexpand(C ⊗ commutator(A, B)), C⊗(A*B) - C⊗(B*A))
@test isequal(qexpand(k₁⊗(k₂+k₃)), k₁⊗k₂ + k₁⊗k₃)
@test isequal(qexpand(b₁⊗(b₂+b₃)), b₁⊗b₂ + b₁⊗b₃)
@test isequal(qexpand(A⊗(B+C+D)), A⊗B + A⊗C + A⊗D)
@test isequal(qexpand(C ⊗ commutator(A, B)), C⊗(A*B) - C⊗(B*A))
@test isequal(qexpand(k₁⊗(k₂+k₃)), k₁⊗k₂ + k₁⊗k₃)
@test isequal(qexpand(b₁⊗(b₂+b₃)), b₁⊗b₂ + b₁⊗b₃)

@test isequal(qexpand((B+C+D)⊗A), B⊗A + C⊗A + D⊗A)
@test isequal(qexpand(commutator(A, B) ⊗ C), (A*B)⊗C - (B*A)⊗C)
@test isequal(qexpand((k₂+k₃)⊗k₁), k₂⊗k₁ + k₃⊗k₁)
@test isequal(qexpand((b₂+b₃)⊗b₁), b₂⊗b₁ + b₃⊗b₁)
@test isequal(qexpand((B+C+D)⊗A), B⊗A + C⊗A + D⊗A)
@test isequal(qexpand(commutator(A, B) ⊗ C), (A*B)⊗C - (B*A)⊗C)
@test isequal(qexpand((k₂+k₃)⊗k₁), k₂⊗k₁ + k₃⊗k₁)
@test isequal(qexpand((b₂+b₃)⊗b₁), b₂⊗b₁ + b₃⊗b₁)

@test isequal(qexpand(A*(B+C+D)), A*B + A*C + A*D)
@test isequal(qexpand(C * commutator(A, B)), C*A*B - C*B*A)
@test isequal(qexpand(A*(B+C+D)), A*B + A*C + A*D)
@test isequal(qexpand(C * commutator(A, B)), C*A*B - C*B*A)

@test isequal(qexpand((B+C+D)*A), B*A + C*A + D*A)
@test isequal(qexpand(commutator(A, B) * C), A*B*C - B*A*C)
@test isequal(qexpand((B+C+D)*A), B*A + C*A + D*A)
@test isequal(qexpand(commutator(A, B) * C), A*B*C - B*A*C)

@test isequal(qexpand((A⊗B)*(C⊗D)), (A*C)⊗(B*D))
@test isequal(qexpand((b₁⊗b₂)*(k₁⊗k₂)), (b₁*k₁)*(b₂*k₂))
end
@test isequal(qexpand((A⊗B)*(C⊗D)), (A*C)⊗(B*D))
@test isequal(qexpand((b₁⊗b₂)*(k₁⊗k₂)), (b₁*k₁)*(b₂*k₂))
end
end
Loading
Loading