Skip to content

Commit db6f804

Browse files
committed
add apply_right! allocation tests
1 parent afacef3 commit db6f804

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

test/test_allocations.jl

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@testitem "Allocation checks" begin
22
using QuantumClifford: mul_left!, RandDestabMemory, Tableau
3-
using Random
3+
using Random, InteractiveUtils
44
n = Threads.nthreads()
55
allocated(f::F) where {F} = @allocations f()
66
@testset "apply! mul_left! canonicalize!" begin
@@ -99,4 +99,50 @@
9999
allocated(f1)
100100
@test allocated(f1) <= 18
101101
end
102+
103+
test_sizes = [2,63,64,65,127,128,129,511,512,513]
104+
@testset "apply_right! symbolic" begin
105+
for q in test_sizes
106+
q1 = rand(1:q)
107+
q2 = rand(setdiff(1:q, [q1]))
108+
for _gate in subtypes(AbstractSingleQubitOperator)
109+
_gate == SingleQubitOperator && continue
110+
111+
l = random_clifford(q)
112+
gate = _gate(q1)
113+
f1() = apply_right!(l, gate)
114+
f1()
115+
allocated(f1)
116+
@test allocated(f1) <= 0
117+
end
118+
for _gate in subtypes(AbstractTwoQubitOperator)
119+
l = random_clifford(q)
120+
gate = _gate(q1, q2)
121+
f2() = apply_right!(l, gate)
122+
f2()
123+
allocated(f2)
124+
@test allocated(f2) <= 0
125+
end
126+
end
127+
end
128+
@testset "apply_right! pauli" begin
129+
for q in test_sizes
130+
l = random_clifford(q)
131+
pauli = random_pauli(q)
132+
f1() = apply_right!(l, pauli)
133+
f1()
134+
allocated(f1)
135+
@test allocated(f1) <= 0
136+
end
137+
end
138+
@testset "apply_right! dense" begin
139+
for q in test_sizes
140+
l = random_clifford(q)
141+
r = random_clifford(q)
142+
f1() = apply_right!(l, r)
143+
f1()
144+
allocated(f1)
145+
@test_broken allocated(f1) <= 0
146+
end
147+
end
102148
end

0 commit comments

Comments
 (0)