Skip to content

Commit

Permalink
cleanup and remove redundant check
Browse files Browse the repository at this point in the history
  • Loading branch information
Krastanov authored Sep 14, 2024
1 parent 7ae70c9 commit 4757a21
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
5 changes: 3 additions & 2 deletions src/misc_ops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ end
SparseGate(c,t::Tuple) = SparseGate(c,collect(t))

function apply!(state::AbstractStabilizer, g::SparseGate; kwargs...)
if maximum(g.indices) > nqubits(state) || length(g.indices) != nqubits(g.cliff)
throw(ArgumentError("Cannot apply gate: check qubit indices and CliffordOperator qubit count."))
m = maximum(g.indices)
if m > nqubits(state)
throw(ArgumentError(lazy"SparseGate was attempted on invalid qubit index $(m) when the state contains only $(nqubits(state)) qubits."))
end
apply!(state, g.cliff, g.indices; kwargs...)
end
Expand Down
9 changes: 0 additions & 9 deletions test/test_noisycircuits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,6 @@
@assert apply!(apply!(copy(c), g), gi) == c
end

@testset "Sanity checks on SparseGate operations" begin
@test_throws ArgumentError SparseGate(random_clifford(2), [1, 2, 3])
@test_throws ArgumentError apply!(random_stabilizer(2), SparseGate(random_clifford(3), [1, 2, 3]))
for n in filter(x -> x > 1, test_sizes)
@test_throws ArgumentError SparseGate(random_clifford(n-1), collect(1:n))
@test_throws ArgumentError apply!(random_stabilizer(n-1), SparseGate(random_clifford(n), collect(1:n)))
end
end

@testset "Noisy Gates" begin
g1 = SparseGate(tId1, [1])
g2 = SparseGate(tCNOT, [2,3])
Expand Down
3 changes: 3 additions & 0 deletions test/test_throws.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@

@test_throws ArgumentError one(typeof(T"X"), 1, basis=:U)

@test_throws ArgumentError SparseGate(random_clifford(2), [1, 2, 3])
@test_throws ArgumentError apply!(random_stabilizer(2), SparseGate(random_clifford(3), [1, 2, 3]))

for gt in subtypes(QuantumClifford.AbstractSingleQubitOperator)
gt == SingleQubitOperator && continue
@test_throws ArgumentError gt(0)
Expand Down

0 comments on commit 4757a21

Please sign in to comment.