Skip to content

Commit

Permalink
Val(:H) instruct (#37)
Browse files Browse the repository at this point in the history
* more instructs

* add a test
  • Loading branch information
GiggleLiu authored and Roger-luo committed Nov 27, 2019
1 parent 95e7b1b commit 578babc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/instruct.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ end
A list of symbol for specialized gates/operators.
"""
const SPECIALIZATION_LIST = Symbol[:X, :Y, :Z, :S, :T, :Sdag, :Tdag]
const SPECIALIZATION_LIST = Symbol[:X, :Y, :Z, :S, :T, :Sdag, :Tdag, :H, :SWAP, :PSWAP, :CPHASE]

function _prepare_instruct(
state,
Expand Down Expand Up @@ -164,6 +164,11 @@ function YaoBase.instruct!(state::AbstractVecOrMat, ::Val{:X}, locs::NTuple{N,In
return state
end

function YaoBase.instruct!(state::AbstractVecOrMat, ::Val{:H}, locs::NTuple{N, Int}) where {N}
instruct!(state, YaoBase.Const.H, locs)
end


function YaoBase.instruct!(state::AbstractVecOrMat{T}, ::Val{:Y}, locs::NTuple{N,Int}) where {T,N}
mask = bmask(Int, locs)
do_mask = bmask(Int, first(locs))
Expand Down
5 changes: 5 additions & 0 deletions test/instruct.jl
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ end
@test rot_mat(T, Val(:CPHASE), theta) rot_mat(T, Diagonal([1, 1, 1, -1]), theta) *
exp(im * theta / 2)
for ST in [randn(ComplexF64, 1 << 5), randn(ComplexF64, 1 << 5, 10)]
@test instruct!(copy(ST), Val(:H), (4,)) instruct!(
copy(ST),
Const.H,
(4,),
)
for R in [:Rx, :Ry, :Rz]
@test instruct!(copy(ST), Val(R), (4,), θ) instruct!(
copy(ST),
Expand Down

0 comments on commit 578babc

Please sign in to comment.