Skip to content

Commit

Permalink
Merge 2121fe3 into 2e97016
Browse files Browse the repository at this point in the history
  • Loading branch information
Todorbsc committed Mar 14, 2024
2 parents 2e97016 + 2121fe3 commit 3e233cb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/Gate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@ targettype(::Type{Op}) where {Op<:Operator} = Op
targettype(::Type{Control{Op}}) where {Op} = Op
targettype(::Type{Control{Op}}) where {Op<:Control} = targettype(Op)
targettype(::Type{<:Gate{Op}}) where {Op} = targettype(Op)
targettype(::Op) where {Op} = targettype(Op)
targettype(::Gate{Op}) where {Op<:Operator} = targettype(Op)

control(g::G) where {G<:Gate{<:Control}} = lanes(g)[1:end-length(targettype(G))]
target(g::G) where {G<:Gate{<:Control}} = lanes(g)[end-length(targettype(G))+1:end]
Expand Down
10 changes: 9 additions & 1 deletion test/Gate_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,17 @@
@test targettype(Gate{Op}) === Op
end

@testset "$Op" for Op in [Control{I}, Control{Control{I}}, Control{Control{Control{I}}}]
@testset "$Op" for Op in [I, Control{I}, Control{Control{I}}, Control{Control{Control{I}}}]
@test targettype(Gate{Op}) === I
end

@testset "$(operator(gate))" for (gate, correct) in [
(Z(1), Z),
(CZ(1, 2), Z),
(Control(1, Control(2, Z(3))), Z),
]
@test targettype(gate) === correct
end
end

@testset "control" begin
Expand Down

0 comments on commit 3e233cb

Please sign in to comment.