Skip to content

Commit 9a8a1dd

Browse files
committed
quickfix of QFT
1 parent 753de5d commit 9a8a1dd

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

src/QFT.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ QFTCircuit(n::Int) = chain(n, CRot(n, i) for i = 1:n)
1111
struct QFTBlock{N} <: PrimitiveBlock{N,ComplexF64} end
1212
mat(q::QFTBlock{N}) where N = applymatrix(q)
1313

14-
apply!(reg::DefaultRegister{B}, ::QFTBlock) where B = (reg.state = ifft!(invorder_firstdim(reg |> state), 1)*sqrt(1<<nqubits(reg)); reg)
15-
apply!(reg::DefaultRegister{B}, ::Daggered{N, T, <:QFTBlock}) where {B,N,T} = (reg.state = invorder_firstdim(fft!(reg|>state, 1)/sqrt(1<<nqubits(reg))); reg)
14+
apply!(reg::DefaultRegister{B}, ::QFTBlock) where B = (reg.state = ifft!(invorder_firstdim(reg |> state), 1)*sqrt(1<<nactive(reg)); reg)
15+
apply!(reg::DefaultRegister{B}, ::Daggered{N, T, <:QFTBlock}) where {B,N,T} = (reg.state = invorder_firstdim(fft!(reg|>state, 1)/sqrt(1<<nactive(reg))); reg)
1616

1717
# traits
1818
ishermitian(q::QFTBlock{N}) where N = N==1

src/QuAlgorithmZoo.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ using Yao
55
using Yao.Intrinsics
66
using Yao.Registers
77
using Yao.Blocks
8-
import Yao.Blocks: mat, dispatch!, nparameters, parameters, cache_key, print_block, _make_rot_mat, apply!
8+
import Yao.Blocks: mat, dispatch!, nparameters, parameters, cache_key, print_block, _make_rot_mat, apply!, PrimitiveBlock
99
import Base: ==, copy, hash
1010
import Yao.Intrinsics: ishermitian, isreflexive, isunitary
1111

test/QFT.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,7 @@ end
4444

4545
# test fft
4646
@test apply!(copy(reg), qft) apply!(copy(reg), qftblock)
47+
48+
# regression test for nactive
49+
@test apply!(focus!(copy(reg), 1:3), QFTBlock{3}()) |> isnormalized
4750
end

0 commit comments

Comments
 (0)