Skip to content
This repository has been archived by the owner on Dec 18, 2021. It is now read-only.

Commit

Permalink
Format .jl files (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored and Roger-luo committed Dec 8, 2019
1 parent 9666408 commit 1ba8e83
Show file tree
Hide file tree
Showing 10 changed files with 233 additions and 328 deletions.
228 changes: 56 additions & 172 deletions benchmark/benchmarks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@ using LinearAlgebra, SparseArrays
bench(n, U, loc::Tuple) =
@benchmarkable instruct!(st, $U, $loc) setup = (st = statevec(rand_state($n)))
bench(n, U, loc::Tuple, control_locs::Tuple, control_bits::Tuple) =
@benchmarkable instruct!(st, $U, $loc, $control_locs, $control_bits) setup = (st = statevec(rand_state($n)))
@benchmarkable instruct!(st, $U, $loc, $control_locs, $control_bits) setup =
(st = statevec(rand_state($n)))
bench(n, B::Int, U, loc::Tuple) =
@benchmarkable instruct!(st, $U, $loc) setup = (st = statevec(rand_state($n, nbatch = $B)))
bench(n, B::Int, U, loc::Tuple, control_locs::Tuple, control_bits::Tuple) =
@benchmarkable instruct!(st, $U, $loc, $control_locs, $control_bits) setup = (st = statevec(rand_state(
$n,
nbatch = $B,
)))
@benchmarkable instruct!(st, $U, $loc, $control_locs, $control_bits) setup =
(st = statevec(rand_state($n, nbatch = $B)))


const SUITE = BenchmarkGroup()
Expand All @@ -34,27 +33,17 @@ end

SUITE["specialized"]["single control"] = BenchmarkGroup()
for U in YaoArrayRegister.SPECIALIZATION_LIST, n in 4:4:25
SUITE["specialized"]["single control"][string(U), n, (2,), (1,)] = bench(
n,
Val(U),
(1,),
(2,),
(1,),
)
SUITE["specialized"]["single control"][string(U), n, (2,), (1,)] =
bench(n, Val(U), (1,), (2,), (1,))
end

SUITE["specialized"]["multi control"] = BenchmarkGroup()

for U in YaoArrayRegister.SPECIALIZATION_LIST, n in 4:4:25
control_locs = Tuple(2:n)
control_bits = ntuple(x -> 1, n - 1)
SUITE["specialized"]["multi control"][string(U), n, 2:n, control_locs] = bench(
n,
Val(U),
(1,),
control_locs,
control_bits,
)
SUITE["specialized"]["multi control"][string(U), n, 2:n, control_locs] =
bench(n, Val(U), (1,), control_locs, control_bits)
end

SUITE["specialized"]["multi qubit"] = BenchmarkGroup()
Expand All @@ -77,29 +66,16 @@ for U in YaoArrayRegister.SPECIALIZATION_LIST, n in 4:4:25
control_bits = ntuple(x -> rand(0:1), num_controls)
perms = perms[num_controls+1:num_controls+round(Int, location_sparsity * n)]

SUITE["specialized"]["multi qubit multi control"][string(U), n, num_controls] = bench(
n,
Val(U),
Tuple(perms),
control_locs,
control_bits,
)
SUITE["specialized"]["single qubit multi control"][string(U), n, num_controls] = bench(
n,
Val(U),
(perms[1],),
control_locs,
control_bits,
)
SUITE["specialized"]["multi qubit multi control"][string(U), n, num_controls] =
bench(n, Val(U), Tuple(perms), control_locs, control_bits)
SUITE["specialized"]["single qubit multi control"][string(U), n, num_controls] =
bench(n, Val(U), (perms[1],), control_locs, control_bits)
end

for n in 4:4:25
SUITE["specialized"]["multi qubit"]["SWAP", n] = bench(n, Val(:SWAP), (1, 2))
SUITE["specialized"]["multi qubit"]["SWAP", "random", n] = bench(
n,
Val(:SWAP),
Tuple(randperm(n)[1:2]),
)
SUITE["specialized"]["multi qubit"]["SWAP", "random", n] =
bench(n, Val(:SWAP), Tuple(randperm(n)[1:2]))
end

# General Instructions (matrices based)
Expand Down Expand Up @@ -142,17 +118,11 @@ matrices(N) = matrices(ComplexF64, N)
### contiguous
for n in 1:2:10, T in [ComplexF64], U in matrices(T, 1 << n)
# contiguous ordered address
SUITE["matrices"]["contiguous"]["ordered"][n, string(T), string(typeof(U))] = bench(
n,
U,
Tuple(1:n),
)
SUITE["matrices"]["contiguous"]["ordered"][n, string(T), string(typeof(U))] =
bench(n, U, Tuple(1:n))
# contiguous random address
SUITE["matrices"]["contiguous"]["random"][n, string(T), string(typeof(U))] = bench(
n,
U,
Tuple(randperm(n)),
)
SUITE["matrices"]["contiguous"]["random"][n, string(T), string(typeof(U))] =
bench(n, U, Tuple(randperm(n)))
end

@info "generating benchmark for in-contiguous matrices locs"
Expand All @@ -161,32 +131,20 @@ for m in 1:3, T in [ComplexF64], U in matrices(T, 1 << m)
n = 10
N = 1 << n
# in-contiguous ordered address
SUITE["matrices"]["in-contiguous"]["ordered"][m, string(T), string(typeof(U))] = bench(
n,
U,
Tuple(sort(randperm(n)[1:m])),
)
SUITE["matrices"]["in-contiguous"]["ordered"][m, string(T), string(typeof(U))] =
bench(n, U, Tuple(sort(randperm(n)[1:m])))
# in-contiguous random address
SUITE["matrices"]["in-contiguous"]["random"][m, string(T), string(typeof(U))] = bench(
n,
U,
Tuple(randperm(n)[1:m]),
)
SUITE["matrices"]["in-contiguous"]["random"][m, string(T), string(typeof(U))] =
bench(n, U, Tuple(randperm(n)[1:m]))
end

@info "generating benchmark for single qubit matrices"
### single qubit
for T in [ComplexF64], U in matrices(T, 2), n in 1:4:25
SUITE["matrices"]["single qubit"]["ordered"][string(T), string(typeof(U)), n] = bench(
n,
U,
(rand(1:n),),
)
SUITE["matrices"]["single qubit"]["random"][string(T), string(typeof(U)), n] = bench(
n,
U,
(rand(1:n),),
)
SUITE["matrices"]["single qubit"]["ordered"][string(T), string(typeof(U)), n] =
bench(n, U, (rand(1:n),))
SUITE["matrices"]["single qubit"]["random"][string(T), string(typeof(U)), n] =
bench(n, U, (rand(1:n),))
end

SUITE["matrices"]["controlled"] = BenchmarkGroup()
Expand All @@ -196,22 +154,12 @@ SUITE["matrices"]["controlled"]["random"] = BenchmarkGroup()
test_bench(n, U, loc, control_locs, control_bits) =
instruct!(statevec(rand_state(n)), U, loc, control_locs, control_bits)
for T in [ComplexF64], n in 1:2:10, m in 3:2:6, U in matrices(T, 1 << n)
SUITE["matrices"]["controlled"]["ordered"][n, m, string(T), string(typeof(U))] = bench(
n + m,
U,
Tuple(1:n),
Tuple(n+1:n+m),
ntuple(x -> 1, m),
)
SUITE["matrices"]["controlled"]["ordered"][n, m, string(T), string(typeof(U))] =
bench(n + m, U, Tuple(1:n), Tuple(n+1:n+m), ntuple(x -> 1, m))

perms = randperm(n + m)
SUITE["matrices"]["controlled"]["random"][n, m, string(T), string(typeof(U))] = bench(
n + m,
U,
Tuple(perms[1:n]),
Tuple(perms[n+1:n+m]),
ntuple(x -> 1, m),
)
SUITE["matrices"]["controlled"]["random"][n, m, string(T), string(typeof(U))] =
bench(n + m, U, Tuple(perms[1:n]), Tuple(perms[n+1:n+m]), ntuple(x -> 1, m))
end


Expand All @@ -228,29 +176,17 @@ end

SUITE["batched specialized"]["single control"] = BenchmarkGroup()
for U in YaoArrayRegister.SPECIALIZATION_LIST, n in 5:4:15, B in 10:20:60
SUITE["batched specialized"]["single control"][string(U), n, B, (2,), (1,)] = bench(
n,
B,
Val(U),
(1,),
(2,),
(1,),
)
SUITE["batched specialized"]["single control"][string(U), n, B, (2,), (1,)] =
bench(n, B, Val(U), (1,), (2,), (1,))
end

SUITE["batched specialized"]["multi control"] = BenchmarkGroup()

for U in YaoArrayRegister.SPECIALIZATION_LIST, n in 5:4:15, B in 10:20:60
control_locs = Tuple(2:n)
control_bits = ntuple(x -> 1, n - 1)
SUITE["batched specialized"]["multi control"][string(U), n, B, 2:n, control_locs] = bench(
n,
B,
Val(U),
(1,),
control_locs,
control_bits,
)
SUITE["batched specialized"]["multi control"][string(U), n, B, 2:n, control_locs] =
bench(n, B, Val(U), (1,), control_locs, control_bits)
end

SUITE["batched specialized"]["multi qubit"] = BenchmarkGroup()
Expand All @@ -273,32 +209,16 @@ for U in YaoArrayRegister.SPECIALIZATION_LIST, n in 5:4:15, B in 10:20:60
control_bits = ntuple(x -> rand(0:1), num_controls)
perms = perms[num_controls+1:num_controls+round(Int, location_sparsity * n)]

SUITE["batched specialized"]["multi qubit multi control"][string(U), n, B, num_controls] = bench(
n,
B,
Val(U),
Tuple(perms),
control_locs,
control_bits,
)
SUITE["batched specialized"]["single qubit multi control"][string(U), n, B, num_controls] = bench(
n,
B,
Val(U),
(perms[1],),
control_locs,
control_bits,
)
SUITE["batched specialized"]["multi qubit multi control"][string(U), n, B, num_controls] =
bench(n, B, Val(U), Tuple(perms), control_locs, control_bits)
SUITE["batched specialized"]["single qubit multi control"][string(U), n, B, num_controls] =
bench(n, B, Val(U), (perms[1],), control_locs, control_bits)
end

for n in 5:4:15, B in 10:20:60
SUITE["batched specialized"]["multi qubit"]["SWAP", n, B] = bench(n, B, Val(:SWAP), (1, 2))
SUITE["batched specialized"]["multi qubit"]["SWAP", "random", n, B] = bench(
n,
B,
Val(:SWAP),
Tuple(randperm(n)[1:2]),
)
SUITE["batched specialized"]["multi qubit"]["SWAP", "random", n, B] =
bench(n, B, Val(:SWAP), Tuple(randperm(n)[1:2]))
end

# General Instructions (matrices based)
Expand Down Expand Up @@ -341,19 +261,11 @@ matrices(N) = matrices(ComplexF64, N)
### contiguous
for n in 1:2:5, T in [ComplexF64], U in matrices(T, 1 << n), B in 10:20:60
# contiguous ordered address
SUITE["batched matrices"]["contiguous"]["ordered"][n, B, string(T), string(typeof(U))] = bench(
n,
B,
U,
Tuple(1:n),
)
SUITE["batched matrices"]["contiguous"]["ordered"][n, B, string(T), string(typeof(U))] =
bench(n, B, U, Tuple(1:n))
# contiguous random address
SUITE["batched matrices"]["contiguous"]["random"][n, B, string(T), string(typeof(U))] = bench(
n,
B,
U,
Tuple(randperm(n)),
)
SUITE["batched matrices"]["contiguous"]["random"][n, B, string(T), string(typeof(U))] =
bench(n, B, U, Tuple(randperm(n)))
end

@info "generating benchmark for in-contiguous matrices locs"
Expand All @@ -362,36 +274,20 @@ for m in 1:3, T in [ComplexF64], U in matrices(T, 1 << m), B in 10:20:60
n = 10
N = 1 << n
# in-contiguous ordered address
SUITE["batched matrices"]["in-contiguous"]["ordered"][m, B, string(T), string(typeof(U))] = bench(
n,
B,
U,
Tuple(sort(randperm(n)[1:m])),
)
SUITE["batched matrices"]["in-contiguous"]["ordered"][m, B, string(T), string(typeof(U))] =
bench(n, B, U, Tuple(sort(randperm(n)[1:m])))
# in-contiguous random address
SUITE["batched matrices"]["in-contiguous"]["random"][m, B, string(T), string(typeof(U))] = bench(
n,
B,
U,
Tuple(randperm(n)[1:m]),
)
SUITE["batched matrices"]["in-contiguous"]["random"][m, B, string(T), string(typeof(U))] =
bench(n, B, U, Tuple(randperm(n)[1:m]))
end

@info "generating benchmark for single qubit matrices"
### single qubit
for T in [ComplexF64], U in matrices(T, 2), n in 1:4:25, B in 10:20:60
SUITE["batched matrices"]["single qubit"]["ordered"][string(T), B, string(typeof(U)), n] = bench(
n,
B,
U,
(rand(1:n),),
)
SUITE["batched matrices"]["single qubit"]["random"][string(T), B, string(typeof(U)), n] = bench(
n,
B,
U,
(rand(1:n),),
)
SUITE["batched matrices"]["single qubit"]["ordered"][string(T), B, string(typeof(U)), n] =
bench(n, B, U, (rand(1:n),))
SUITE["batched matrices"]["single qubit"]["random"][string(T), B, string(typeof(U)), n] =
bench(n, B, U, (rand(1:n),))
end

SUITE["batched matrices"]["controlled"] = BenchmarkGroup()
Expand All @@ -401,22 +297,10 @@ SUITE["batched matrices"]["controlled"]["random"] = BenchmarkGroup()
test_bench(n, U, loc, control_locs, control_bits) =
instruct!(statevec(rand_state(n)), U, loc, control_locs, control_bits)
for T in [ComplexF64], n in 1:2:5, m in 3:2:6, U in matrices(T, 1 << n), B in 10:20:60
SUITE["batched matrices"]["controlled"]["ordered"][n, B, m, string(T), string(typeof(U))] = bench(
n + m,
B,
U,
Tuple(1:n),
Tuple(n+1:n+m),
ntuple(x -> 1, m),
)
SUITE["batched matrices"]["controlled"]["ordered"][n, B, m, string(T), string(typeof(U))] =
bench(n + m, B, U, Tuple(1:n), Tuple(n+1:n+m), ntuple(x -> 1, m))

perms = randperm(n + m)
SUITE["batched matrices"]["controlled"]["random"][n, B, m, string(T), string(typeof(U))] = bench(
n + m,
B,
U,
Tuple(perms[1:n]),
Tuple(perms[n+1:n+m]),
ntuple(x -> 1, m),
)
SUITE["batched matrices"]["controlled"]["random"][n, B, m, string(T), string(typeof(U))] =
bench(n + m, B, U, Tuple(perms[1:n]), Tuple(perms[n+1:n+m]), ntuple(x -> 1, m))
end
Loading

0 comments on commit 1ba8e83

Please sign in to comment.