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

Move the test runner to use TestItems.jl #329

Merged
merged 3 commits into from
Aug 3, 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 @@ -22,8 +22,8 @@ QuantumOpticsBase = "4f57444f-1401-5e15-980d-4471b28d5678"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
SIMD = "fdea26ae-647d-5447-a871-4b548cad5224"
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
Static = "aedffcd0-7271-4cad-89d0-dc628f76c6d3"
StridedViews = "4db3bf67-4bd7-4b4e-b153-31dc3fb37143"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
TestItemRunner = "f8b46487-2199-4994-9208-9a1283c18c0a"
88 changes: 20 additions & 68 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,76 +1,28 @@
using SafeTestsets
using QuantumClifford
using TestItemRunner

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

macro doset(descr)
quote
if doset($descr)
@safetestset $descr begin
include("test_"*$descr*".jl")
end
end
end
if get(ENV, "GPU_TESTS", "") != "true"
println("skipping gpu tests (set GPU_TESTS=true to test gpu)")
end

println("Starting tests with $(Threads.nthreads()) threads out of `Sys.CPU_THREADS = $(Sys.CPU_THREADS)`...")
# filter for the test
testfilter = ti -> begin
exclude = Symbol[]
if get(ENV,"JET_TEST","")!="true"
push!(exclude, :jet)
end
if !(VERSION >= v"1.10")
push!(exclude, :doctests)
push!(exclude, :aqua)
end

if get(ENV, "GPU_TESTS", "")!="true"
push!(exclude, :gpu)
end

# in order to run the gpu tests automatically set GPU_TESTS to true in the .env file
if get(ENV, "GPU_TESTS", "") == "true"
@doset "gpu"
else
println("skipping gpu tests (set GPU_TESTS=true to test gpu)")
return all(!in(exclude), ti.tags)
end

@doset "throws"
@doset "paulis"
@doset "stabs"
@doset "stabcanon"
@doset "mul_leftright"
@doset "inner"
@doset "embed"
@doset "gf2"
@doset "projections"
@doset "expect"
@doset "trace"
@doset "cliff"
@doset "symcliff"
@doset "symcontrolled"
@doset "classicalreg"
@doset "random"
@doset "noisycircuits"
@doset "syndromemeas"
@doset "bitpack"
@doset "memorylayout"
@doset "graphs"
@doset "hash"
@doset "entanglement"
@doset "enumerate"
@doset "quantumoptics"
@doset "ecc"
@doset "ecc_codeproperties"
@doset "ecc_decoder_all_setups"
@doset "ecc_encoding"
@doset "ecc_gottesman"
@doset "ecc_reedmuller"
@doset "ecc_bch"
@doset "ecc_syndromes"
@doset "ecc_throws"
@doset "precompile"
@doset "pauliframe"
@doset "sumtypecompactification"
@doset "allocations"
VERSION >= v"1.10" && @doset "doctests"
get(ENV,"JET_TEST","")=="true" && @doset "jet"
VERSION >= v"1.10" && @doset "aqua"
println("Starting tests with $(Threads.nthreads()) threads out of `Sys.CPU_THREADS = $(Sys.CPU_THREADS)`...")

@run_package_tests filter=testfilter
6 changes: 2 additions & 4 deletions test/test_allocations.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using QuantumClifford
using QuantumClifford: mul_left!

@testset "Allocation checks" begin
@testitem "Allocation checks" begin
using QuantumClifford: mul_left!
n = Threads.nthreads()
allocated(f::F) where {F} = @allocated f()
@testset "apply! mul_left! canonicalize!" begin
Expand Down
7 changes: 4 additions & 3 deletions test/test_aqua.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Aqua
using QuantumClifford
Aqua.test_all(QuantumClifford)
@testitem "Aqua" tags=[:aqua] begin
using Aqua
Aqua.test_all(QuantumClifford)
end
81 changes: 41 additions & 40 deletions test/test_bitpack.jl
Original file line number Diff line number Diff line change
@@ -1,49 +1,50 @@
using Random
using QuantumClifford
using QuantumClifford: Tableau
@testitem "Alternative bit packing" begin
using Random
using QuantumClifford: Tableau

@testset "Alternative bit packing" begin
for n in [1,3] # can not go higher than 4 (limitation from SIMD acting on transposed/strided arrays)
N = 64*n-2
s64 = random_stabilizer(N,N);
_phases = phases(s64);
xzs64 = tab(s64).xzs;
xzs64T = collect(xzs64')';
p64 = random_pauli(N;nophase=true);
c64_stab = tab(random_destabilizer(N;phases=false));
@testset "alternative bit packing" begin
for n in [1,3] # can not go higher than 4 (limitation from SIMD acting on transposed/strided arrays)
N = 64*n-2
s64 = random_stabilizer(N,N);
_phases = phases(s64);
xzs64 = tab(s64).xzs;
xzs64T = collect(xzs64')';
p64 = random_pauli(N;nophase=true);
c64_stab = tab(random_destabilizer(N;phases=false));

_after_p = p64*s64
after_p = stab_to_gf2(_after_p);
after_p_phases = phases(_after_p);
after_can = stab_to_gf2(canonicalize!(copy(s64)));
_after_clif = apply!(copy(s64),CliffordOperator(c64_stab));
after_cliff = stab_to_gf2(_after_clif);
after_cliff_phases = phases(_after_clif);
_after_p = p64*s64
after_p = stab_to_gf2(_after_p);
after_p_phases = phases(_after_p);
after_can = stab_to_gf2(canonicalize!(copy(s64)));
_after_clif = apply!(copy(s64),CliffordOperator(c64_stab));
after_cliff = stab_to_gf2(_after_clif);
after_cliff_phases = phases(_after_clif);

for int in [UInt8, UInt16, UInt32, UInt64]
p = PauliOperator(p64.phase, N, collect(reinterpret(int,p64.xz)));
xzs = collect(reinterpret(int, collect(xzs64)));
xzsT = collect(xzs')';
_s = Stabilizer(_phases,N,xzs);
_sT = Stabilizer(_phases,N,xzsT);
for int in [UInt8, UInt16, UInt32, UInt64]
p = PauliOperator(p64.phase, N, collect(reinterpret(int,p64.xz)));
xzs = collect(reinterpret(int, collect(xzs64)));
xzsT = collect(xzs')';
_s = Stabilizer(_phases,N,xzs);
_sT = Stabilizer(_phases,N,xzsT);

for trans in (true, false)
s = trans ? _sT : _s
apply_pauli = p*s
@test after_p_phases == phases(apply_pauli)
canon = canonicalize!(deepcopy(s))
@test after_can == stab_to_gf2(canon)
for trans in (true, false)
s = trans ? _sT : _s
apply_pauli = p*s
@test after_p_phases == phases(apply_pauli)
canon = canonicalize!(deepcopy(s))
@test after_can == stab_to_gf2(canon)

cxzs = collect(reinterpret(int, collect(c64_stab.xzs)));
cxzsT = collect(cxzs')';
_c = CliffordOperator(Tableau(zeros(UInt8,2N),N,cxzs));
_cT = CliffordOperator(Tableau(zeros(UInt8,2N),N,cxzsT));
cxzs = collect(reinterpret(int, collect(c64_stab.xzs)));
cxzsT = collect(cxzs')';
_c = CliffordOperator(Tableau(zeros(UInt8,2N),N,cxzs));
_cT = CliffordOperator(Tableau(zeros(UInt8,2N),N,cxzsT));

for ctrans in (true, false)
c = ctrans ? _c : _cT
after_clifford = apply!(deepcopy(s),c)
@test after_cliff == stab_to_gf2(after_clifford)
@test after_cliff_phases == phases(after_clifford)
for ctrans in (true, false)
c = ctrans ? _c : _cT
after_clifford = apply!(deepcopy(s),c)
@test after_cliff == stab_to_gf2(after_clifford)
@test after_cliff_phases == phases(after_clifford)
end
end
end
end
Expand Down
48 changes: 24 additions & 24 deletions test/test_classicalreg.jl
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
using Random
using QuantumClifford
@testitem "Classical" begin
using Random
using QuantumClifford: stab_looks_good, destab_looks_good, mixed_stab_looks_good, mixed_destab_looks_good

using QuantumClifford: stab_looks_good, destab_looks_good, mixed_stab_looks_good, mixed_destab_looks_good

n=5
stab = random_stabilizer(n)
mdstab = MixedDestabilizer(stab)
_ = Register(stab)
reg = Register(stab, [0,0,0,0])
regmd = Register(mdstab, [0,0,0,0])
@test reg==regmd
@test stabilizerview(reg) == stabilizerview(mdstab)
@test destabilizerview(reg) == destabilizerview(mdstab)
@test logicalxview(reg) == logicalxview(mdstab)
@test logicalzview(reg) == logicalzview(mdstab)
@test bitview(reg) == bitview(regmd)
@test quantumstate(reg) == mdstab
for state in [mdstab,reg,regmd]
for op in [sMX(1,1),sMY(2,2),sMZ(3,3),PauliMeasurement(P"XYZZZ",4),sCNOT(1,2),sCPHASE(2,3),sCNOT(3,4),NoiseOpAll(UnbiasedUncorrelatedNoise(0.1))]
apply!(state,op)
end
for (i,proj) in enumerate([projectXrand!, projectYrand!, projectZrand!])
proj(state, i)
n=5
stab = random_stabilizer(n)
mdstab = MixedDestabilizer(stab)
_ = Register(stab)
reg = Register(stab, [0,0,0,0])
regmd = Register(mdstab, [0,0,0,0])
@test reg==regmd
@test stabilizerview(reg) == stabilizerview(mdstab)
@test destabilizerview(reg) == destabilizerview(mdstab)
@test logicalxview(reg) == logicalxview(mdstab)
@test logicalzview(reg) == logicalzview(mdstab)
@test bitview(reg) == bitview(regmd)
@test quantumstate(reg) == mdstab
for state in [mdstab,reg,regmd]
for op in [sMX(1,1),sMY(2,2),sMZ(3,3),PauliMeasurement(P"XYZZZ",4),sCNOT(1,2),sCPHASE(2,3),sCNOT(3,4),NoiseOpAll(UnbiasedUncorrelatedNoise(0.1))]
apply!(state,op)
end
for (i,proj) in enumerate([projectXrand!, projectYrand!, projectZrand!])
proj(state, i)
end
end
@test tab(canonicalize!(stabilizerview(reg))).xzs == tab(canonicalize!(stabilizerview(mdstab))).xzs
end
@test tab(canonicalize!(stabilizerview(reg))).xzs == tab(canonicalize!(stabilizerview(mdstab))).xzs
Loading
Loading