Skip to content

Commit

Permalink
embed for single-qubit Clifford Operator
Browse files Browse the repository at this point in the history
  • Loading branch information
Fe-r-oz committed Nov 2, 2024
1 parent c3546cd commit ec1dc07
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
24 changes: 24 additions & 0 deletions src/dense_cliffords.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,30 @@ function apply!(r::CliffordOperator, l::AbstractCliffordOperator; phases=false)
r
end

function embed(n::Int, i::Int, t::CliffordOperator)
t = tab(t)
if nqubits(t) == 1
tout = zero(typeof(t), 2*n, n)
for j in 1:n
tout[j, i] = t[nqubits(t)][1]
tout.phases[j] = t.phases[1]
end
for j in 1:n
tout[n + j, i] = t[nqubits(t)+1][1]
tout.phases[n + j] = t.phases[nqubits(t)+1]
end
return CliffordOperator(tout)
else
throw(ArgumentError("""
You are trying to embed a small CliffordOperator into a larger CliffordOperator.
However, you have not given all the positions at which the CliffordOperator needs to be embedded.
If you are directly calling `embed`, use the form `embed(nqubits, indices::Tuple, t::CliffordOperator)`.
If you are not using `embed` directly, then `embed` must have been incorrectly called
by one of the functions you have called.
"""))
end
end

# TODO create Base.permute! and getindex(..., permutation_array)
function permute(c::CliffordOperator,p) # TODO this is a slow stupid implementation
CliffordOperator(Tableau([tab(c)[i][p] for i in 1:2*nqubits(c)][vcat(p,p.+nqubits(c))]))
Expand Down
25 changes: 24 additions & 1 deletion test/test_embed.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@
@testitem "embed PauliOperator" begin
@testitem "embed PauliOperator, CliffordOperator" begin
@test embed(5,3,P"-Y") == P"-__Y__"
@test embed(5,(3,5),P"-YZ") == P"-__Y_Z"
@test embed(5,[3,5],P"-YZ") == P"-__Y_Z"
@test_throws ArgumentError embed(5,[3,5],P"-YZX")
@test_throws ArgumentError embed(5,3,P"-ZX")

# embed for single-qubit Clifford gates
@test embed(5, 5, tHadamard) == C"____Z
____Z
____Z
____Z
____Z
____X
____X
____X
____X
____X"

@test embed(5, 3, CliffordOperator(sHadamard)) == C"__Z__
__Z__
__Z__
__Z__
__Z__
__X__
__X__
__X__
__X__
__X__"
end

0 comments on commit ec1dc07

Please sign in to comment.