Skip to content

Commit 78d4430

Browse files
Fe-r-ozKrastanov
andauthored
noncliff: improve error handling in apply!(sm, pcT) (#374)
--------- Co-authored-by: Stefan Krastanov <[email protected]>
1 parent 6863bd0 commit 78d4430

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

src/nonclifford.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ end
183183
function _proj₊(sm::GeneralizedStabilizer, p::PauliOperator)
184184
end
185185

186+
nqubits(sm::GeneralizedStabilizer) = nqubits(sm.stab)
187+
186188
abstract type AbstractPauliChannel <: AbstractOperation end
187189

188190
"""A Pauli channel datastructure, mainly for use with [`GeneralizedStabilizer`](@ref)
@@ -232,6 +234,7 @@ nqubits(pc::PauliChannel) = nqubits(pc.paulis[1][1])
232234
See also: [`GeneralizedStabilizer`](@ref), [`PauliChannel`](@ref), [`UnitaryPauliChannel`](@ref)
233235
"""
234236
function apply!(state::GeneralizedStabilizer, gate::AbstractPauliChannel; prune_threshold=1e-10)
237+
nqubits(state) == nqubits(gate) || throw(DimensionMismatch(lazy"GeneralizedStabilizer has $(nqubits(state)) qubits, but PauliChannel has $(nqubits(gate)). Use `embed` to create an appropriately padded PauliChannel."))
235238
dict = state.destabweights
236239
stab = state.stab
237240
dtype = valtype(dict)

test/test_throws.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ using InteractiveUtils: subtypes
2020
@test_throws DimensionMismatch mul_right!(P"X", P"XX")
2121

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

2425
@test_throws ArgumentError UnitaryPauliChannel([P"X"], [1,2])
2526
@test_throws ArgumentError UnitaryPauliChannel([P"X",P"XX"], [1,2])

0 commit comments

Comments
 (0)