Skip to content

Commit

Permalink
noncliff: add copy, == for GeneralizedStabilizer, UnitaryPauliChannel (
Browse files Browse the repository at this point in the history
  • Loading branch information
Fe-r-oz authored Nov 5, 2024
1 parent 78d4430 commit 99f2f0b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/nonclifford.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ function GeneralizedStabilizer(state)
end

GeneralizedStabilizer(s::GeneralizedStabilizer) = s
Base.copy(sm::GeneralizedStabilizer) = GeneralizedStabilizer(copy(sm.stab),copy(sm.destabweights))
Base.:(==)(sm₁::GeneralizedStabilizer, sm₂::GeneralizedStabilizer) = sm₁.stab==sm₂.stab && sm₁.destabweights==sm₂.destabweights

function Base.show(io::IO, s::GeneralizedStabilizer)
println(io, "A mixture ∑ ϕᵢⱼ Pᵢ ρ Pⱼ† where ρ is")
Expand Down Expand Up @@ -145,8 +147,11 @@ with ϕᵢⱼ | Pᵢ | Pⱼ:
0.853553+0.0im | + _ | + _
0.146447+0.0im | + Z | + Z
julia> expect(P"-X", sm)
julia> χ′ = expect(P"-X", sm)
0.7071067811865475 + 0.0im
julia> prob = (real(χ′)+1)/2
0.8535533905932737
```
"""
Expand Down Expand Up @@ -342,6 +347,8 @@ struct UnitaryPauliChannel{T,S,P} <: AbstractPauliChannel
end

PauliChannel(p::UnitaryPauliChannel) = p.paulichannel
Base.copy(p::UnitaryPauliChannel) = UnitaryPauliChannel(map(copy, p.paulis), map(copy, p.weights))
Base.:(==)(p₁::UnitaryPauliChannel, p₂::UnitaryPauliChannel) = p₁.paulis==p₂.paulis && p₁.weights==p₂.weights

function Base.show(io::IO, pc::UnitaryPauliChannel)
println(io, "A unitary Pauli channel P = ∑ ϕᵢ Pᵢ with the following branches:")
Expand Down
13 changes: 13 additions & 0 deletions test/test_nonclifford_quantumoptics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,16 @@ qo_tgate.data[2,2] = exp(im*pi/4)
end
end
end

@testset "copy and ==" begin
for n in 1:10
s = random_stabilizer(n)
sm = GeneralizedStabilizer(s)
i = rand(1:n)
apply!(sm, embed(n, i, pcT))
smcopy = copy(sm)
@test smcopy == sm
nc = embed(n, rand(1:n), pcT)
@test copy(nc) == nc
end
end

0 comments on commit 99f2f0b

Please sign in to comment.