Skip to content

Commit

Permalink
revamp promote rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Fe-r-oz committed Sep 17, 2024
1 parent cc5b84d commit 11376fd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
12 changes: 8 additions & 4 deletions src/QuantumClifford.jl
Original file line number Diff line number Diff line change
Expand Up @@ -993,10 +993,14 @@ end
# Conversion and promotion
##############################

Base.promote_rule(::Type{<:Stabilizer{T}} , ::Type{<:Destabilizer{T}} ) where {T<:Tableau} = MixedDestabilizer{T}
Base.promote_rule(::Type{<:MixedDestabilizer{T}}, ::Type{<:Stabilizer{T}} ) where {T<:Tableau} = MixedDestabilizer{T}

Base.convert(::Type{<:MixedDestabilizer{T}}, x::Union{Destabilizer{T}, Stabilizer{T}}) where {T <: Tableau} = MixedDestabilizer(x)
# Destabilizer, MixedDestabilizer -> MixedDestabilizer
Base.promote_rule(::Type{<:Destabilizer{T}} , ::Type{<:MixedDestabilizer{T}}) where {T<:Tableau} = MixedDestabilizer{T}
# MixedStabilizer, MixedDestabilizer -> MixedDestabilizer
Base.promote_rule(::Type{<:MixedStabilizer{T}}, ::Type{<:MixedDestabilizer{T}}) where {T<:Tableau} = MixedDestabilizer{T}
# Stabilizer, T<:Union{MixedStabilizer, Destabilizer, MixedDestabilizer} -> T
Base.promote_rule(::Type{<:Stabilizer{T}} , ::Type{<:S} ) where {T<:Tableau, S<:Union{MixedStabilizer{T}, Destabilizer{T}, MixedDestabilizer{T}}} = S

Base.convert(::Type{<:MixedDestabilizer{T}}, x::Union{Destabilizer{T}, MixedStabilizer{T}, Stabilizer{T}}) where {T <: Tableau} = MixedDestabilizer(x)

##############################
# Helpers for binary codes
Expand Down
3 changes: 0 additions & 3 deletions test/test_stabs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@
@test mixed_destab_looks_good(mds)
estab = stabilizerview(md)s
@test canonicalize!(copy(stabilizerview(mds))) == canonicalize!(estab)
d = random_destabilizer(n)
sd = random_stabilizer(n)random_destabilizer(n)
@test mixed_destab_looks_good(sd)
end
end

Expand Down

0 comments on commit 11376fd

Please sign in to comment.