diff --git a/src/nonclifford.jl b/src/nonclifford.jl index 70f99e42f..74f623d78 100644 --- a/src/nonclifford.jl +++ b/src/nonclifford.jl @@ -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") @@ -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 ``` """ @@ -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:") diff --git a/test/test_nonclifford_quantumoptics.jl b/test/test_nonclifford_quantumoptics.jl index a520578d7..a25b522fc 100644 --- a/test/test_nonclifford_quantumoptics.jl +++ b/test/test_nonclifford_quantumoptics.jl @@ -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