Skip to content

Commit 3bdfaf1

Browse files
committed
fix document
1 parent ac22244 commit 3bdfaf1

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

examples/Shor/Mod.jl

+10-10
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ struct Mod <: PrimitiveBlock{2}
3030
end
3131
Yao.nqudits(m::Mod) = m.n
3232

33-
function _apply!(reg::AbstractArrayReg, m::Mod)
33+
function Yao.unsafe_apply!(reg::AbstractArrayReg, m::Mod)
3434
nstate = zero(reg.state)
3535
for i in basis(reg)
36-
_i = i >= m.L ? i+1 : mod(i*m.a, m.L)+1
37-
for j in 1:B
38-
@inbounds nstate[_i,j] = reg.state[i+1,j]
36+
_i = buffer(i) >= m.L ? buffer(i)+1 : mod(buffer(i)*m.a, m.L)+1
37+
for j in 1:size(nstate, 2)
38+
@inbounds nstate[_i,j] = reg.state[buffer(i)+1,j]
3939
end
4040
end
4141
reg.state = nstate
@@ -82,16 +82,16 @@ function bint2_reader(T, k::Int)
8282
return b -> (b&mask, b>>k)
8383
end
8484

85-
function _apply!(reg::ArrayReg, m::KMod)
85+
function Yao.unsafe_apply!(reg::ArrayReg, m::KMod)
8686
nstate = zero(reg.state)
8787

8888
reader = bint2_reader(Int, m.k)
8989
for b in basis(reg)
90-
k, i = reader(b)
91-
_i = i >= m.L ? i : mod(i*powermod(m.a, m.k, m.L), m.L)
90+
k, i = reader(buffer(b))
91+
_i = i >= m.L ? i : mod(i*powermod(m.a, k, m.L), m.L)
9292
_b = k + _i<<m.k + 1
93-
for j in 1:YaoArrayRegister._asint(nbatch(reg))
94-
@inbounds nstate[_b,j] = reg.state[b+1,j]
93+
for j in 1:size(nstate, 2)
94+
@inbounds nstate[_b,j] = reg.state[buffer(b)+1,j]
9595
end
9696
end
9797
reg.state = nstate
@@ -101,7 +101,7 @@ end
101101
function Yao.mat(::Type{T}, m::KMod) where {T}
102102
perm = Vector{Int}(undef, 1<<m.n)
103103
reader = bint2_reader(Int, m.k)
104-
for b in basis(m.n)
104+
for b in 0:1<<m.n-1
105105
k, i = reader(b)
106106
_i = i >= m.L ? i : mod(i*powermod(m.a, k, m.L), m.L)
107107
_b = k + _i<<m.k + 1

examples/Shor/Project.toml

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
[deps]
2+
BitBasis = "50ba71b6-fa0f-514d-ae9a-0916efc90dcf"
23
Yao = "5872b779-8223-5990-8dd0-5abbb0748c8c"

examples/Shor/number_theory.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Eulerφ(N) = length(Z_star(N))
1818
1919
obtain `s` and `r` from `ϕ` that satisfies `|s/r - ϕ| ≦ 1/2r²`
2020
"""
21-
continued_fraction(ϕ, niter::Int) = niter==0 ? floor(Int, ϕ) : floor(Int, ϕ) + 1//continued_fraction(1/mod(ϕ, 1), niter-1)
21+
continued_fraction(ϕ, niter::Int) = niter==0 || isinteger(ϕ) ? floor(Int, ϕ) : floor(Int, ϕ) + 1//continued_fraction(1/mod(ϕ, 1), niter-1)
2222
continued_fraction::Rational, niter::Int) = niter==0 || ϕ.den==1 ? floor(Int, ϕ) : floor(Int, ϕ) + 1//continued_fraction(1/mod(ϕ, 1), niter-1)
2323

2424
"""
@@ -72,7 +72,7 @@ Estimate the order of `x` to `L`, `r`, from a floating point number `ϕ ∼ s/r`
7272
function order_from_float(ϕ, x, L)
7373
k = 1
7474
rnum = continued_fraction(ϕ, k)
75-
while rnum.den < L
75+
while rnum.den < L && k < 100
7676
r = rnum.den
7777
if is_order(r, x, L)
7878
return r

0 commit comments

Comments
 (0)