Skip to content
This repository has been archived by the owner on Dec 18, 2021. It is now read-only.

Commit

Permalink
add test, fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Roger-luo committed May 23, 2019
1 parent 96c63cb commit 164395c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/instruct.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ const SPECIALIZATION_LIST = Symbol[:X, :Y, :Z, :S, :T, :Sdag, :Tdag]
const Locations{T} = NTuple{N, T} where N
const BitConfigs{T} = NTuple{N, T} where N

function YaoBase.instruct!(
state::AbstractVecOrMat{T1},
operator::AbstractMatrix{T2},
locs::Tuple{},
control_locs::NTuple{C, Int}=(),
control_bits::NTuple{C, Int}=()) where {T1, T2, M, C}
return state
end

function YaoBase.instruct!(
state::AbstractVecOrMat{T1},
operator::AbstractMatrix{T2},
Expand All @@ -44,6 +53,15 @@ function YaoBase.instruct!(state::AbstractVecOrMat{T1}, U1::SDDiagonal{T2}, loc:
return instruct!(state, copyto!(similar(U1, T1), U1), loc)
end

function YaoBase.instruct!(
state::AbstractVecOrMat{T},
operator::AbstractMatrix{T},
locs::Tuple{},
control_locs::NTuple{C, Int} = (),
control_bits::NTuple{C, Int} = ()) where {T, M, C}
return state
end

function YaoBase.instruct!(
state::AbstractVecOrMat{T},
operator::AbstractMatrix{T},
Expand Down Expand Up @@ -193,7 +211,7 @@ for (G, FACTOR) in zip([:Z, :S, :T, :Sdag, :Tdag], [:(-1), :(im), :($(exp(im*π/
instruct!(state, g, locs...)

# no effect (to fix ambiguity)
@eval YaoBase.instruct!(::AbstractVecOrMat, ::Val{$(QuoteNode(G))}, ::Tuple{}) = nothing
@eval YaoBase.instruct!(st::AbstractVecOrMat, ::Val{$(QuoteNode(G))}, ::Tuple{}) = st

@eval function YaoBase.instruct!(state::AbstractVecOrMat{T}, ::Val{$(QuoteNode(G))}, locs::Int) where T
mask = bmask(locs)
Expand Down
10 changes: 10 additions & 0 deletions test/instruct.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,13 @@ end
st = rand(1<<4)
@test instruct!(st, IMatrix{2, Float64}(), 1) == st
end

@testset "test empty locs" begin
st = rand(ComplexF64, 1<<4)
pm = pmrand(ComplexF64, 2)
@test instruct!(copy(st), pm, ()) == st

for G in [:Z, :S, :T, :Sdag, :Tdag]
@test instruct!(copy(st), Val(G), ()) == st
end
end

0 comments on commit 164395c

Please sign in to comment.