Skip to content

Commit

Permalink
improve error handling in apply!(sm, pcT)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fe-r-oz committed Sep 30, 2024
1 parent 624eedd commit 4601ecb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/nonclifford.jl
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ end
function _proj₊(sm::GeneralizedStabilizer, p::PauliOperator)
end

nqubits(sm::GeneralizedStabilizer) = nqubits(sm.stab)

abstract type AbstractPauliChannel <: AbstractOperation end

"""A Pauli channel datastructure, mainly for use with [`GeneralizedStabilizer`](@ref)
Expand Down Expand Up @@ -228,6 +230,7 @@ nqubits(pc::PauliChannel) = nqubits(pc.paulis[1][1])
See also: [`GeneralizedStabilizer`](@ref), [`PauliChannel`](@ref), [`UnitaryPauliChannel`](@ref)
"""
function apply!(state::GeneralizedStabilizer, gate::AbstractPauliChannel; prune_threshold=1e-10)
nqubits(state) == nqubits(gate) || throw(DimensionMismatch("GeneralizedStabilizer has $(nqubits(state)) qubits, but PauliChannel has $(nqubits(gate)). Use `embed` to create an appropriately padded PauliChannel."))
dict = state.destabweights
stab = state.stab
dtype = valtype(dict)
Expand Down
1 change: 1 addition & 0 deletions test/test_throws.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ using InteractiveUtils: subtypes
@test_throws DimensionMismatch mul_right!(P"X", P"XX")

@test_throws ArgumentError GeneralizedStabilizer(S"XX")
@test_throws DimensionMismatch apply!(GeneralizedStabilizer(random_stabilizer(2)), pcT)

@test_throws ArgumentError UnitaryPauliChannel([P"X"], [1,2])
@test_throws ArgumentError UnitaryPauliChannel([P"X",P"XX"], [1,2])
Expand Down

0 comments on commit 4601ecb

Please sign in to comment.