Skip to content

Commit 217ea06

Browse files
committed
fix in swapping rows logic
1 parent 44ad1bc commit 217ea06

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

src/randoms.jl

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ function random_destabilizer(rng::AbstractRNG, n::Int; phases::Bool=true)
154154
# apply qubit permutation S to F2
155155
perm_inds = vcat(perm, perm .+ n)
156156
U = F2[perm_inds,:]
157-
157+
println(U)
158158
# apply layer of hadamards
159159
lhs_inds = vcat(had_idxs, had_idxs .+ n)
160160
rhs_inds = vcat(had_idxs .+ n, had_idxs)
@@ -189,10 +189,6 @@ struct RandDestabMemory{N,T<:Integer}
189189
T = typeof(n)
190190
F1 = zeros(Int8, 2n, 2n)
191191
F2 = zeros(Int8, 2n, 2n)
192-
for i in n+1:2n
193-
@inbounds F1[i, i] = 1
194-
@inbounds F2[i, i] = 1
195-
end
196192
hadamard = falses(n)
197193
perm = zeros(T, n)
198194
had_idxs = zeros(T, n)
@@ -208,10 +204,6 @@ end
208204
function _reset!(memory::RandDestabMemory, n::Integer)
209205
fill!(memory.F1, 0)
210206
fill!(memory.F2, 0)
211-
for i in n+1:2n
212-
@inbounds memory.F1[i, i] = 1
213-
@inbounds memory.F2[i, i] = 1
214-
end
215207
fill!(memory.hadamard, false)
216208
fill!(memory.perm, 0)
217209
fill!(memory.had_idxs, 0)
@@ -334,6 +326,10 @@ function random_destabilizer(rng::AbstractRNG, n::Int, memory::RandDestabMemory;
334326
# now construct the tableau representation for F(I, Gamma, Delta)
335327
mul!(prod, gamma, delta)
336328
mul!(prod_p, gamma_p, delta_p)
329+
for i in n+1:2n
330+
@inbounds F1[i, i] = 1
331+
@inbounds F2[i, i] = 1
332+
end
337333
_inv!(inv_delta, delta')
338334
_inv!(inv_delta_p, delta_p')
339335

@@ -360,14 +356,7 @@ function random_destabilizer(rng::AbstractRNG, n::Int, memory::RandDestabMemory;
360356
for i in 1:n
361357
if had_idxs[i] != 0
362358
for j in 1:2n
363-
U[had_idxs[i], j] = U[had_idxs[i]+n, j]
364-
end
365-
end
366-
end
367-
for i in 1:n
368-
if had_idxs[i] != 0
369-
for j in 1:2n
370-
U[had_idxs[i]+n, j] = U[had_idxs[i], j]
359+
@inbounds (U[had_idxs[i], j], U[had_idxs[i]+n, j]) = (U[had_idxs[i]+n, j], U[had_idxs[i], j])
371360
end
372361
end
373362
end
@@ -376,7 +365,10 @@ function random_destabilizer(rng::AbstractRNG, n::Int, memory::RandDestabMemory;
376365
xzs = memory.xzs
377366
fill!(F2, 0)
378367
_mul!(F2, F1, U, 2n)
379-
_inplace_equals!(xzs, _inplace_mod!(F2, 2), 1)
368+
369+
_inplace_mod!(F2, 2)
370+
_inplace_equals!(xzs, F2, 1)
371+
380372

381373
# random Pauli matrix just amounts to phases on the stabilizer tableau
382374
phasesarray = memory.phasesarray

0 commit comments

Comments
 (0)