-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch tests to use TestItemRunner.jl (#75)
Co-authored-by: Stefan Krastanov <[email protected]>
- Loading branch information
Showing
22 changed files
with
495 additions
and
528 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.