This stops using the undocumented and therefore internal method Base.invpermute!! which may be removed from Base in 1.10. It also increases performance by up to 10x for large numbers of qbits at the cost of a decrease in performance up to 3x for few qbits.
benchmarking code
using BenchmarkTools, Random, Plots
old(state, perm) = @inbounds Base.invpermute!!(state, perm)
new(state, perm) = invpermute!(state, perm)
function time(func, n)
s = rand(ComplexF64, n)
p = randperm(n)
p_buf = copy(p)
@belapsed $func($s, copyto!($p_buf, $p)) setup=(randperm!($p); rand!($s))
end
x = 2 .^ (1:25)
y_old = [time(old, n) for n in x]
y_new = [time(new, n) for n in x]
plot(log2.(x), y_old ./ x, label="old")
plot!(log2.(x), y_new ./ x, label="new")
plot!(xlabel="N", yaxis=:log10, legend=:topleft, ylabel="seconds/2^N")
This stops using the undocumented and therefore internal method
Base.invpermute!!
which may be removed from Base in 1.10. It also increases performance by up to 10x for large numbers of qbits at the cost of a decrease in performance up to 3x for few qbits.benchmarking code
Result